Skip to content

Commit 9aa57dc

Browse files
Fix contiguous scan of escaped content (#203)
* Fix contiguous scan that starts is_escaped, this fixes the parsing of unknown RR types. * Fix for escaped newlines.
1 parent 7847af8 commit 9aa57dc

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-2
lines changed

src/fallback/scanner.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ nonnull_all
6464
static really_inline const char *scan_contiguous(
6565
parser_t *parser, const char *start, const char *end)
6666
{
67-
if (parser->file->state.is_escaped)
67+
if (parser->file->state.is_escaped && start < end)
6868
goto escaped;
6969

7070
while (start < end) {
7171
if (likely(classify[ (uint8_t)*start ] == CONTIGUOUS)) {
7272
if (unlikely(*start == '\\')) {
73-
escaped:
7473
if ((parser->file->state.is_escaped = (++start == end)))
7574
break;
75+
escaped:
7676
assert(start < end);
7777
parser->file->newlines.tail[0] += (*start == '\n');
7878
}

tests/syntax.c

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,3 +1049,73 @@ void origin_is_reinstated(void **state)
10491049
assert_int_equal(code, ZONE_SUCCESS);
10501050
assert_true(count == 3);
10511051
}
1052+
1053+
static int32_t contiguous_escaped_start_cb(
1054+
zone_parser_t *parser,
1055+
const zone_name_t *owner,
1056+
uint16_t type,
1057+
uint16_t class,
1058+
uint32_t ttl,
1059+
uint16_t rdlength,
1060+
const uint8_t *rdata,
1061+
void *user_data)
1062+
{
1063+
(void)parser;
1064+
(void)owner;
1065+
(void)type;
1066+
(void)class;
1067+
(void)ttl;
1068+
(void)rdlength;
1069+
(void)rdata;
1070+
(void)user_data;
1071+
return ZONE_SUCCESS;
1072+
}
1073+
1074+
/*!cmocka */
1075+
void contiguous_escaped_start(void** state)
1076+
{
1077+
/* Check that the fallback parser handles a scan of a contiguous segment
1078+
* that starts with is_escaped. */
1079+
char* zone =
1080+
"$ORIGIN example.\n"
1081+
"$TTL 3600\n"
1082+
"@ IN SOA ns postmaster.mail 2147483647 3600 900 1814400 900\n"
1083+
" IN NS ns\n"
1084+
"ns IN A 203.0.113.53\n"
1085+
"ns IN AAAA 2001:db8:feed:beef::53\n"
1086+
"\n"
1087+
"0000000 IN A 192.0.2.0\n"
1088+
"0000000 IN TYPE994 \\# 10 30313233343536373839\n"
1089+
"0000001 IN A 192.0.2.1\n"
1090+
"0000001 IN TYPE994 \\# 11 3031323334353637383961\n"
1091+
"0000002 IN A 192.0.2.2\n"
1092+
"0000002 IN TYPE994 \\# 12 303132333435363738396162\n"
1093+
"0000003 IN A 192.0.2.3\n"
1094+
"0000003 IN TYPE994 \\# 13 30313233343536373839616263\n"
1095+
"0000004 IN A 192.0.2.4\n"
1096+
"0000004 IN TYPE994 \\# 14 3031323334353637383961626364\n"
1097+
"0000005 IN A 192.0.2.5\n"
1098+
"0000005 IN TYPE994 \\# 15 303132333435363738396162636465\n"
1099+
"0000006 IN A 192.0.2.6\n"
1100+
"0000006 IN TYPE994 \\# 16 30313233343536373839616263646566\n"
1101+
;
1102+
static uint8_t origin[] = { 0 };
1103+
zone_parser_t parser;
1104+
zone_name_buffer_t name;
1105+
zone_rdata_buffer_t rdata;
1106+
zone_buffers_t buffers = { 1, &name, &rdata };
1107+
zone_options_t options;
1108+
int32_t result;
1109+
(void) state;
1110+
1111+
memset(&options, 0, sizeof(options));
1112+
options.accept.callback = contiguous_escaped_start_cb;
1113+
options.origin.octets = origin;
1114+
options.origin.length = sizeof(origin);
1115+
options.default_ttl = 3600;
1116+
options.default_class = ZONE_CLASS_IN;
1117+
1118+
result = zone_parse_string(&parser, &options, &buffers, zone, strlen(zone),
1119+
NULL);
1120+
assert_int_equal(result, ZONE_SUCCESS);
1121+
}

0 commit comments

Comments
 (0)