You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a string is parsed into an int using strconv.Atoi, and subsequently that int is converted into another integer type of a smaller size, the result can produce unexpected values. This also applies to the results of strconv.ParseInt and strconv.ParseUint when the specified size is larger than the size of the type that number is converted to.
POC
In the first assume that an input string is passed to parseAllocateBad1 function, parsed by strconv.Atoi, and then converted into an int32 type:
The bounds are not checked, so this means that if the provided number is greater than the maximum value of type int32, the resulting value from the conversion will be different from the actual provided value.
To avoid unexpected values, you should either use the other functions provided by the strconv package to parse the specific types and bit sizes as shown in the parseAllocateGood2 function; or check bounds as in the parseAllocateGood1 function.
In the second vulnerable, assume that an input string is passed to parseAllocateBad2 function, parsed by strconv.ParseInt with a bit size set to 64, and then converted into an int32 type:
If the provided number is greater than the maximum value of type int32, the resulting value from the conversion will be different from the actual provided value.
To avoid unexpected values, you should specify the correct bit size as in parseAllocateGood3; or check bounds before making the conversion as in parseAllocateGood4.
nordvpn-linux/cmd/norduser/main.go
Line 291 in dbac8d8
If a string is parsed into an int using
strconv.Atoi
, and subsequently that int is converted into another integer type of a smaller size, the result can produce unexpected values. This also applies to the results ofstrconv.ParseInt
andstrconv.ParseUint
when the specified size is larger than the size of the type that number is converted to.POC
In the first assume that an input string is passed to
parseAllocateBad1
function, parsed bystrconv.Atoi
, and then converted into anint32
type:The bounds are not checked, so this means that if the provided number is greater than the maximum value of type
int32
, the resulting value from the conversion will be different from the actual provided value.To avoid unexpected values, you should either use the other functions provided by the
strconv
package to parse the specific types and bit sizes as shown in theparseAllocateGood2
function; or check bounds as in theparseAllocateGood1
function.In the second vulnerable, assume that an input string is passed to
parseAllocateBad2
function, parsed bystrconv.ParseInt
with a bit size set to 64, and then converted into anint32
type:If the provided number is greater than the maximum value of type
int32
, the resulting value from the conversion will be different from the actual provided value.To avoid unexpected values, you should specify the correct bit size as in
parseAllocateGood3
; or check bounds before making the conversion as inparseAllocateGood4
.References
Wikipedia Integer overflow
Go language specification Integer overflow
Documentation for strconv.Atoi
Documentation for strconv.ParseInt
Documentation for strconv.ParseUint
Common Weakness Enumeration: CWE-190
Common Weakness Enumeration: CWE-681
The text was updated successfully, but these errors were encountered: