Skip to content

Commit 4037765

Browse files
committed
builtin: fix OOB bugs in s.is_bin, s.is_oct, s.is_hex, discovered through ./v -force-bounds-checking test vlib/builtin/
1 parent bf03add commit 4037765

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

‎vlib/builtin/string.v‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,7 +2060,7 @@ pub fn (str string) is_oct() bool {
20602060
} else if str[i] == `-` || str[i] == `+` {
20612061
i++
20622062

2063-
if str[i] == `0` {
2063+
if i < str.len && str[i] == `0` {
20642064
i++
20652065
} else {
20662066
return false
@@ -2069,7 +2069,7 @@ pub fn (str string) is_oct() bool {
20692069
return false
20702070
}
20712071

2072-
if str[i] == `o` {
2072+
if i < str.len && str[i] == `o` {
20732073
i++
20742074
} else {
20752075
return false
@@ -2103,7 +2103,7 @@ pub fn (str string) is_bin() bool {
21032103
} else if str[i] == `-` || str[i] == `+` {
21042104
i++
21052105

2106-
if str[i] == `0` {
2106+
if i < str.len && str[i] == `0` {
21072107
i++
21082108
} else {
21092109
return false
@@ -2112,7 +2112,7 @@ pub fn (str string) is_bin() bool {
21122112
return false
21132113
}
21142114

2115-
if str[i] == `b` {
2115+
if i < str.len && str[i] == `b` {
21162116
i++
21172117
} else {
21182118
return false
@@ -2146,7 +2146,7 @@ pub fn (str string) is_hex() bool {
21462146
} else if str[i] == `-` || str[i] == `+` {
21472147
i++
21482148

2149-
if str[i] == `0` {
2149+
if i < str.len && str[i] == `0` {
21502150
i++
21512151
} else {
21522152
return false
@@ -2155,7 +2155,7 @@ pub fn (str string) is_hex() bool {
21552155
return false
21562156
}
21572157

2158-
if str[i] == `x` {
2158+
if i < str.len && str[i] == `x` {
21592159
i++
21602160
} else {
21612161
return false

0 commit comments

Comments
 (0)