Skip to content

Commit ae7c05a

Browse files
wcawijngaardsk0ekk0ek
authored andcommitted
Fix that fallback scanner contiguous resets is_escaped.
1 parent 98130b3 commit ae7c05a

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

src/fallback/scanner.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ static really_inline const char *scan_contiguous(
7171
while (start < end) {
7272
if (likely(classify[ (uint8_t)*start ] == CONTIGUOUS)) {
7373
if (unlikely(*start == '\\')) {
74-
if ((parser->file->state.is_escaped = (++start == end)))
75-
break;
74+
start++;
7675
escaped:
76+
if ((parser->file->state.is_escaped = (start == end)))
77+
break;
7778
assert(start < end);
7879
parser->file->newlines.tail[0] += (*start == '\n');
7980
}

tests/syntax.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,3 +1168,54 @@ void quoted_escaped_start(void** state)
11681168
NULL);
11691169
assert_int_equal(result, ZONE_SUCCESS);
11701170
}
1171+
1172+
/*!cmocka */
1173+
void contiguous_escaped_reset(void** state)
1174+
{
1175+
/* Check that the fallback parser resets the is_escaped value, so that
1176+
* a newline is not wrongly classified in the next block. */
1177+
char* zone = PAD(
1178+
"$ORIGIN example.\n"
1179+
"$TTL 3600\n"
1180+
"@ IN SOA ns zonemaster.mail 2147483647 3600 900 1814400 900\n"
1181+
" IN NS ns\n"
1182+
"ns IN A 203.0.113.53\n"
1183+
"ns IN AAAA 2001:db8:feed:beef::53\n"
1184+
"\n"
1185+
"0000000 IN A 192.0.2.0\n"
1186+
"0000000 IN TYPE994 \\# 6 303132333435\n"
1187+
"0000001 IN A 192.0.2.1\n"
1188+
"0000001 IN TYPE994 \\# 7 30313233343536\n"
1189+
"0000002 IN A 192.0.2.2\n"
1190+
"0000002 IN TYPE994 \\# 8 3031323334353637\n"
1191+
"0000003 IN A 192.0.2.3\n"
1192+
"0000003 IN TYPE994 \\# 9 303132333435363738\n"
1193+
"0000004 IN A 192.0.2.4\n"
1194+
"0000004 IN TYPE994 \\# 10 30313233343536373839\n"
1195+
"0000005 IN A 192.0.2.5\n"
1196+
"0000005 IN TYPE994 \\# 11 3031323334353637383961\n"
1197+
"0000006 IN A 192.0.2.6\n"
1198+
"0000006 IN TYPE994 \\# 12 303132333435363738396162\n"
1199+
"0000007 IN A 192.0.2.7\n"
1200+
"0000007 IN TYPE994 \\# 13 30313233343536373839616263\n"
1201+
);
1202+
static uint8_t origin[] = { 0 };
1203+
zone_parser_t parser;
1204+
zone_name_buffer_t name;
1205+
zone_rdata_buffer_t rdata;
1206+
zone_buffers_t buffers = { 1, &name, &rdata };
1207+
zone_options_t options;
1208+
int32_t result;
1209+
(void) state;
1210+
1211+
memset(&options, 0, sizeof(options));
1212+
options.accept.callback = contiguous_escaped_start_cb;
1213+
options.origin.octets = origin;
1214+
options.origin.length = sizeof(origin);
1215+
options.default_ttl = 3600;
1216+
options.default_class = ZONE_CLASS_IN;
1217+
1218+
result = zone_parse_string(&parser, &options, &buffers, zone, strlen(zone),
1219+
NULL);
1220+
assert_int_equal(result, ZONE_SUCCESS);
1221+
}

0 commit comments

Comments
 (0)