Skip to content

Commit 62cb0bc

Browse files
Fix LOC poweroften lookup. It protects the poweroften lookup when large input (#251)
causes the maximum exponent value.
1 parent fd22206 commit 62cb0bc

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/generic/loc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ static really_inline int32_t scan_precision(
235235
return -1; // syntax error
236236

237237
uint8_t exponent = 0;
238-
while (centimeters >= poweroften[exponent+1] && exponent < 9)
238+
while (exponent < 9 && centimeters >= poweroften[exponent+1])
239239
exponent++;
240240

241241
uint8_t mantissa = (uint8_t)(centimeters / poweroften[exponent]);

tests/types.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,17 @@ static const rdata_t loc_rdata =
307307
0x70, 0xbe, 0x15, 0xf0, // longitude
308308
0x00, 0x98, 0x8d, 0x20); // altitude
309309

310+
static const char loc_text_2[] =
311+
PAD("addie.example.com. IN LOC 90 S 180 E 42849672.91m 90000000m 90000000m 89999999m");
312+
static const rdata_t loc_rdata_2 =
313+
RDATA(0x00, // version (always 0)
314+
0x99, // size (default 1m)
315+
0x99, // horizontal precision (default 10000m)
316+
0x89, // vertical precision (default 10m)
317+
0x6c, 0xb0, 0x27, 0x00, // latitude
318+
0xa6, 0x9f, 0xb2, 0x00, // longitude
319+
0xff, 0xff, 0xff, 0xfb); // altitude
320+
310321
static const char nxt_text[] =
311322
PAD("big.foo.tld. NXT medium.foo.tld. A MX SIG NXT");
312323
static const rdata_t nxt_rdata =
@@ -1106,6 +1117,7 @@ static const test_t tests[] = {
11061117
{ ZONE_TYPE_PX, px_text, &px_rdata },
11071118
{ ZONE_TYPE_PX, px_generic_text, &px_rdata },
11081119
{ ZONE_TYPE_LOC, loc_text, &loc_rdata },
1120+
{ ZONE_TYPE_LOC, loc_text_2, &loc_rdata_2 },
11091121
{ ZONE_TYPE_NXT, nxt_text, &nxt_rdata },
11101122
{ ZONE_TYPE_EID, eid_text, &eid_rdata },
11111123
{ ZONE_TYPE_NIMLOC, nimloc_text, &nimloc_rdata },

0 commit comments

Comments
 (0)