Commit 17a99e32 authored by Daniel Salzman's avatar Daniel Salzman

zscanner: fix final block parsing in parse_record

parent 8d04e201
......@@ -140,7 +140,7 @@ int zs_init(
s->default_ttl = ttl;
s->line_counter = 1;
s->state = ZS_STATE_EOF;
s->state = ZS_STATE_NONE;
s->process.automatic = false;
return 0;
......@@ -245,10 +245,6 @@ int zs_set_input_file(
// Try to set the mapped memory advise to sequential.
(void)madvise(start, file_stat.st_size, MADV_SEQUENTIAL);
s->input.eof = false;
} else {
s->input.eof = true;
}
// Get absolute path of the zone file.
......@@ -276,6 +272,7 @@ int zs_set_input_file(
s->input.start = start;
s->input.current = start;
s->input.end = start + file_stat.st_size;
s->input.eof = false;
return 0;
file_error:
......@@ -75456,21 +75453,31 @@ int zs_parse_record(
// Check for the end of the input.
if (s->input.current != s->input.end) {
s->state = ZS_STATE_NONE;
// Parse the next item.
parse(s);
return 0;
} else if (s->state != ZS_STATE_EOF) {
}
switch (s->state) {
case ZS_STATE_NONE:
// Indicate end of the input.
s->state = ZS_STATE_EOF;
return 0;
} else {
case ZS_STATE_EOF:
// Parse the final block.
if (zs_set_input_string(s, "\n", 1) != 0) {
return -1;
}
s->input.eof = true;
parse(s);
if (s->state == ZS_STATE_EOF) {
return -1;
}
return 0;
default:
return -1;;
}
}
......@@ -5016,7 +5016,7 @@ int zs_init(
s->default_ttl = ttl;
s->line_counter = 1;
s->state = ZS_STATE_EOF;
s->state = ZS_STATE_NONE;
s->process.automatic = false;
return 0;
......@@ -5121,10 +5121,6 @@ int zs_set_input_file(
// Try to set the mapped memory advise to sequential.
(void)madvise(start, file_stat.st_size, MADV_SEQUENTIAL);
s->input.eof = false;
} else {
s->input.eof = true;
}
// Get absolute path of the zone file.
......@@ -5152,6 +5148,7 @@ int zs_set_input_file(
s->input.start = start;
s->input.current = start;
s->input.end = start + file_stat.st_size;
s->input.eof = false;
return 0;
file_error:
......@@ -7767,21 +7764,31 @@ int zs_parse_record(
// Check for the end of the input.
if (s->input.current != s->input.end) {
s->state = ZS_STATE_NONE;
// Parse the next item.
parse(s);
return 0;
} else if (s->state != ZS_STATE_EOF) {
}
switch (s->state) {
case ZS_STATE_NONE:
// Indicate end of the input.
s->state = ZS_STATE_EOF;
return 0;
} else {
case ZS_STATE_EOF:
// Parse the final block.
if (zs_set_input_string(s, "\n", 1) != 0) {
return -1;
}
s->input.eof = true;
parse(s);
if (s->state == ZS_STATE_EOF) {
return -1;
}
return 0;
default:
return -1;;
}
}
......
......@@ -86,6 +86,7 @@ typedef struct {
/*! \brief Scanner states describing the result. */
typedef enum {
ZS_STATE_NONE, /*!< Initial state. */
ZS_STATE_DATA, /*!< A record parsed. */
ZS_STATE_ERROR, /*!< An error occured. */
ZS_STATE_INCLUDE, /*!< An include directive parsed. */
......
......@@ -141,7 +141,7 @@ int zs_init(
s->default_ttl = ttl;
s->line_counter = 1;
s->state = ZS_STATE_EOF;
s->state = ZS_STATE_NONE;
s->process.automatic = false;
return 0;
......@@ -246,10 +246,6 @@ int zs_set_input_file(
// Try to set the mapped memory advise to sequential.
(void)madvise(start, file_stat.st_size, MADV_SEQUENTIAL);
s->input.eof = false;
} else {
s->input.eof = true;
}
// Get absolute path of the zone file.
......@@ -277,6 +273,7 @@ int zs_set_input_file(
s->input.start = start;
s->input.current = start;
s->input.end = start + file_stat.st_size;
s->input.eof = false;
return 0;
file_error:
......@@ -411,21 +408,31 @@ int zs_parse_record(
// Check for the end of the input.
if (s->input.current != s->input.end) {
s->state = ZS_STATE_NONE;
// Parse the next item.
parse(s);
return 0;
} else if (s->state != ZS_STATE_EOF) {
}
switch (s->state) {
case ZS_STATE_NONE:
// Indicate end of the input.
s->state = ZS_STATE_EOF;
return 0;
} else {
case ZS_STATE_EOF:
// Parse the final block.
if (zs_set_input_string(s, "\n", 1) != 0) {
return -1;
}
s->input.eof = true;
parse(s);
if (s->state == ZS_STATE_EOF) {
return -1;
}
return 0;
default:
return -1;;
}
}
......
......@@ -2029,15 +2029,7 @@
# Blank spaces with comments.
blank = rest . newline;
action _main_init {
if (escape) {
escape = false;
fbreak;
}
}
# Main processing loop.
# main := (record %_main_init | directive %_main_init | blank %_main_init)*;
main := (record | directive | blank)*;
# END
}%%
......@@ -98,7 +98,8 @@ int state_parsing(
if (zs_init(ss, (char *)s->buffer, s->default_class, s->default_ttl) != 0 ||
zs_set_input_file(ss, (char *)(s->include_filename)) != 0 ||
zs_set_processing(ss, s->process.record, s->process.error, s->process.data) != 0 ||
state_parsing(ss) != 0) {
state_parsing(ss) != 0 ||
ss->error.counter > 0) {
if (ss->error.counter > 0) {
s->error.code = ZS_UNPROCESSED_INCLUDE;
} else {
......@@ -118,6 +119,8 @@ int state_parsing(
zs_deinit(ss);
free(ss);
break;
case ZS_STATE_NONE:
break;
case ZS_STATE_EOF:
// Set the next input string block.
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment