limit maxptysize

This commit is contained in:
sawka 2022-09-03 23:38:35 -07:00
parent 39dacb988a
commit 57b54198e5
2 changed files with 15 additions and 4 deletions

View File

@ -279,3 +279,13 @@ func BoundInt(ival int, minVal int, maxVal int) int {
} }
return ival return ival
} }
func BoundInt64(ival int64, minVal int64, maxVal int64) int64 {
if ival < minVal {
return minVal
}
if ival > maxVal {
return maxVal
}
return ival
}

View File

@ -40,6 +40,8 @@ const MaxFdNum = 1023
const FirstExtraFilesFdNum = 3 const FirstExtraFilesFdNum = 3
const DefaultTermType = "xterm-256color" const DefaultTermType = "xterm-256color"
const DefaultMaxPtySize = 1024 * 1024 const DefaultMaxPtySize = 1024 * 1024
const MinMaxPtySize = 16 * 1024
const MaxMaxPtySize = 100 * 1024 * 1024
const GetStateTimeout = 5 * time.Second const GetStateTimeout = 5 * time.Second
@ -1038,10 +1040,9 @@ func RunCommandDetached(pk *packet.RunPacketType, sender *packet.PacketSender) (
cmd.FileNames = fileNames cmd.FileNames = fileNames
cmd.CmdPty = cmdPty cmd.CmdPty = cmdPty
cmd.Detached = true cmd.Detached = true
if pk.TermOpts != nil && pk.TermOpts.MaxPtySize != 0 {
cmd.MaxPtySize = pk.TermOpts.MaxPtySize
} else {
cmd.MaxPtySize = DefaultMaxPtySize cmd.MaxPtySize = DefaultMaxPtySize
if pk.TermOpts != nil && pk.TermOpts.MaxPtySize > 0 {
cmd.MaxPtySize = base.BoundInt64(pk.TermOpts.MaxPtySize, MinMaxPtySize, MaxMaxPtySize)
} }
cmd.RunnerOutFd, err = os.OpenFile(fileNames.RunnerOutFile, os.O_TRUNC|os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600) cmd.RunnerOutFd, err = os.OpenFile(fileNames.RunnerOutFile, os.O_TRUNC|os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600)
if err != nil { if err != nil {