Skip to content

Commit 479abee

Browse files
authored
stringToTTL: error when overflowing uint32 (#1698)
* stringToTTL: error when overflowing uint32 Signed-off-by: Miek Gieben <miek@miek.nl> * update template Signed-off-by: Miek Gieben <miek@miek.nl> --------- Signed-off-by: Miek Gieben <miek@miek.nl>
1 parent 9516b49 commit 479abee

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

.github/pull_request_template.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Thanks for you pull request, do note the following:
22

3-
* If your PR introduces backward incompatible changes it will very likely not be merged.
3+
- If your PR introduces backward incompatible changes it will very likely not be merged.
44

5-
* We support the last two major Go versions, if your PR uses features from a too new Go version, it
6-
will not be merged.
5+
- We support the last two major Go versions, if your PR uses features from a too new Go version, it
6+
will not be merged.
7+
8+
- If this text is not replaced (deleted, or preferably replaced with something sensible), your PR will be closed.

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)