Skip to content

Commit 186a8ea

Browse files
committed
Allow leading zeroes in integers
The socket10kxfr uses serials with leading zeroes. A quick test showed BIND and Knot both allow for leading zeroes too.
1 parent dee9a5e commit 186a8ea

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

FORMAT.md

+2
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,5 @@ anything other than domain names and text strings, MUST not be quoted.
235235
* Some implementations (Knot, possibly PowerDNS) will silently split-up
236236
strings longer than 255 characters. Others (BIND, simdzone) will throw a
237237
syntax error.
238+
239+
* Leading zeroes in integers appear to be allowed judging by the zone file generated for the [socket10kxfr](https://github.com/NLnetLabs/nsd/blob/86a6961f2ca64f169d7beece0ed8a5e1dd1cd302/tpkg/long/socket10kxfr.tdir/socket10kxfr.pre#L64) test in NSD. BIND and Knot (and the old parser in NSD) all parsed it without problems.

src/generic/number.h

+6-12
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ static really_inline int32_t scan_int8(
1515
{
1616
uint32_t sum = (uint8_t)data[0] - '0';
1717

18-
if (sum > 9 || length > 3)
18+
if (sum > 9 || !length || length > 3)
1919
return 0;
2020

21-
uint32_t non_zero = (sum != 0) | (length == 1);
22-
2321
for (size_t count=1; count < length; count++) {
2422
const uint8_t digit = (uint8_t)data[count] - '0';
2523
sum = sum * 10 + digit;
@@ -28,7 +26,7 @@ static really_inline int32_t scan_int8(
2826
}
2927

3028
*number = (uint8_t)sum;
31-
return sum <= 255u && non_zero;
29+
return sum <= 255u;
3230
}
3331

3432
nonnull((1,3))
@@ -37,11 +35,9 @@ static really_inline int32_t scan_int16(
3735
{
3836
uint32_t sum = (uint8_t)data[0] - '0';
3937

40-
if (sum > 9 || length > 5)
38+
if (sum > 9 || !length || length > 5)
4139
return 0;
4240

43-
uint32_t non_zero = (sum != 0) | (length == 1);
44-
4541
for (size_t count=1; count < length; count++) {
4642
const uint8_t digit = (uint8_t)data[count] - '0';
4743
sum = sum * 10 + digit;
@@ -50,7 +46,7 @@ static really_inline int32_t scan_int16(
5046
}
5147

5248
*number = (uint16_t)sum;
53-
return sum <= 65535u && non_zero;
49+
return sum <= 65535u;
5450
}
5551

5652
nonnull((1,3))
@@ -59,11 +55,9 @@ static really_inline int32_t scan_int32(
5955
{
6056
uint64_t sum = (uint8_t)data[0] - '0';
6157

62-
if (sum > 9 || length > 10)
58+
if (sum > 9 || !length || length > 10)
6359
return 0;
6460

65-
uint32_t non_zero = (sum != 0) | (length == 1);
66-
6761
for (size_t count=1; count < length; count++) {
6862
const uint8_t digit = (uint8_t)data[count] - '0';
6963
sum = sum * 10 + digit;
@@ -72,7 +66,7 @@ static really_inline int32_t scan_int32(
7266
}
7367

7468
*number = (uint32_t)sum;
75-
return sum <= 4294967295u && non_zero;
69+
return sum <= 4294967295u;
7670
}
7771

7872
nonnull_all

tests/time.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void time_stamp_syntax(void **state)
5151
// one second over maximum value
5252
{ "4294967296", 0, ZONE_SYNTAX_ERROR },
5353
// starts with zero
54-
{ "01", 0, ZONE_SYNTAX_ERROR },
54+
{ "01", 1, ZONE_SUCCESS },
5555
// Time specified as YYYYMMDDHHmmSS
5656
// bad number of digits
5757
{ "202301010101", 0, ZONE_SYNTAX_ERROR },

0 commit comments

Comments
 (0)