diff --git a/command/agent/http.go b/command/agent/http.go index d33be8e85..de6a314e3 100644 --- a/command/agent/http.go +++ b/command/agent/http.go @@ -766,7 +766,7 @@ func parsePagination(req *http.Request, b *structs.QueryOptions) { query := req.URL.Query() rawPerPage := query.Get("per_page") if rawPerPage != "" { - perPage, err := strconv.Atoi(rawPerPage) + perPage, err := strconv.ParseInt(rawPerPage, 10, 32) if err == nil { b.PerPage = int32(perPage) } diff --git a/drivers/shared/executor/executor_universal_linux.go b/drivers/shared/executor/executor_universal_linux.go index 87184d843..d5076a8d3 100644 --- a/drivers/shared/executor/executor_universal_linux.go +++ b/drivers/shared/executor/executor_universal_linux.go @@ -33,9 +33,9 @@ func setCmdUser(cmd *exec.Cmd, userid string) error { gids := make([]uint32, len(gidStrings)) for _, gidString := range gidStrings { - u, err := strconv.Atoi(gidString) + u, err := strconv.ParseUint(gidString, 10, 32) if err != nil { - return fmt.Errorf("Unable to convert user's group to int %s: %v", gidString, err) + return fmt.Errorf("Unable to convert user's group to uint32 %s: %v", gidString, err) } gids = append(gids, uint32(u)) diff --git a/helper/flags/autopilot_flags.go b/helper/flags/autopilot_flags.go index 67740a8f5..d0a984a72 100644 --- a/helper/flags/autopilot_flags.go +++ b/helper/flags/autopilot_flags.go @@ -5,6 +5,7 @@ package flags import ( "fmt" + "math/bits" "strconv" "time" ) @@ -88,7 +89,8 @@ func (u *UintValue) Set(v string) error { if u.v == nil { u.v = new(uint) } - parsed, err := strconv.ParseUint(v, 0, 64) + + parsed, err := strconv.ParseUint(v, 0, bits.UintSize) *(u.v) = (uint)(parsed) return err } diff --git a/lib/cpuset/cpuset.go b/lib/cpuset/cpuset.go index e794d354c..0caa96671 100644 --- a/lib/cpuset/cpuset.go +++ b/lib/cpuset/cpuset.go @@ -2,6 +2,7 @@ package cpuset import ( "fmt" + "math" "reflect" "sort" "strconv" @@ -153,6 +154,9 @@ func Parse(s string) (CPUSet, error) { return New(), err } + if v > math.MaxUint16 { + return New(), fmt.Errorf("failed to parse element %s, more than max allowed cores", set) + } cpuset.cpus[uint16(v)] = struct{}{} continue } @@ -168,7 +172,11 @@ func Parse(s string) (CPUSet, error) { if err != nil { return New(), err } + for v := lower; v <= upper; v++ { + if v > math.MaxUint16 { + return New(), fmt.Errorf("failed to parse element %s, more than max allowed cores", set) + } cpuset.cpus[uint16(v)] = struct{}{} } } diff --git a/plugins/drivers/server.go b/plugins/drivers/server.go index 15896801e..0117e0c1c 100644 --- a/plugins/drivers/server.go +++ b/plugins/drivers/server.go @@ -3,6 +3,7 @@ package drivers import ( "fmt" "io" + "math" "github.com/golang/protobuf/ptypes" plugin "github.com/hashicorp/go-plugin" @@ -125,6 +126,9 @@ func (b *driverPluginServer) StartTask(ctx context.Context, req *proto.StartTask AutoAdvertise: net.AutoAdvertise, } for k, v := range net.PortMap { + if v > math.MaxInt32 { + return nil, fmt.Errorf("port map out of bounds") + } pbNet.PortMap[k] = int32(v) } }