Skip to content

Commit 4e99247

Browse files
committed
stringToTTL: error when overflowing uint32
Signed-off-by: Miek Gieben <miek@miek.nl>
1 parent 49a9cee commit 4e99247

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

scan.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"io"
77
"io/fs"
8+
"math"
89
"os"
910
"path"
1011
"path/filepath"
@@ -1231,7 +1232,7 @@ func typeToInt(token string) (uint16, bool) {
12311232

12321233
// stringToTTL parses things like 2w, 2m, etc, and returns the time in seconds.
12331234
func stringToTTL(token string) (uint32, bool) {
1234-
var s, i uint32
1235+
var s, i uint
12351236
for _, c := range token {
12361237
switch c {
12371238
case 's', 'S':
@@ -1251,12 +1252,15 @@ func stringToTTL(token string) (uint32, bool) {
12511252
i = 0
12521253
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
12531254
i *= 10
1254-
i += uint32(c) - '0'
1255+
i += uint(c) - '0'
12551256
default:
12561257
return 0, false
12571258
}
12581259
}
1259-
return s + i, true
1260+
if s+i > math.MaxUint32 {
1261+
return 0, false
1262+
}
1263+
return uint32(s + i), true
12601264
}
12611265

12621266
// Parse LOC records' <digits>[.<digits>][mM] into a

0 commit comments

Comments
 (0)