Fix integer overflows with new parseutil (#15437)

* Use new parseutil helper: Safe variants

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Update parseutil to v0.1.5

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Fix additional integer overflow in command/server

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
This commit is contained in:
Alexander Scheel
2022-05-16 13:57:19 -04:00
committed by GitHub
parent 0e111805a6
commit 91e710f495
6 changed files with 17 additions and 19 deletions

View File

@@ -11,6 +11,7 @@ import (
"strings"
"time"
"github.com/hashicorp/go-secure-stdlib/parseutil"
"github.com/posener/complete"
)
@@ -208,8 +209,8 @@ type IntVar struct {
func (f *FlagSet) IntVar(i *IntVar) {
initial := i.Default
if v, exist := os.LookupEnv(i.EnvVar); exist {
if i, err := strconv.ParseInt(v, 0, 64); err == nil {
initial = int(i)
if i, err := parseutil.SafeParseInt(v); err == nil {
initial = i
}
}
@@ -243,7 +244,7 @@ func newIntValue(def int, target *int, hidden bool) *intValue {
}
func (i *intValue) Set(s string) error {
v, err := strconv.ParseInt(s, 0, 64)
v, err := parseutil.SafeParseInt(s)
if err != nil {
return err
}