diff --git a/pkg/base/base.go b/pkg/base/base.go index d89864cf9..1f30d6328 100644 --- a/pkg/base/base.go +++ b/pkg/base/base.go @@ -279,3 +279,13 @@ func BoundInt(ival int, minVal int, maxVal int) int { } return ival } + +func BoundInt64(ival int64, minVal int64, maxVal int64) int64 { + if ival < minVal { + return minVal + } + if ival > maxVal { + return maxVal + } + return ival +} diff --git a/pkg/shexec/shexec.go b/pkg/shexec/shexec.go index a7879ebda..5a841a88b 100644 --- a/pkg/shexec/shexec.go +++ b/pkg/shexec/shexec.go @@ -40,6 +40,8 @@ const MaxFdNum = 1023 const FirstExtraFilesFdNum = 3 const DefaultTermType = "xterm-256color" const DefaultMaxPtySize = 1024 * 1024 +const MinMaxPtySize = 16 * 1024 +const MaxMaxPtySize = 100 * 1024 * 1024 const GetStateTimeout = 5 * time.Second @@ -1038,10 +1040,9 @@ func RunCommandDetached(pk *packet.RunPacketType, sender *packet.PacketSender) ( cmd.FileNames = fileNames cmd.CmdPty = cmdPty 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) if err != nil {