Commit 099f28c2 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Clean up configuration parser, fix edge case.

parent 0e326332
...@@ -80,13 +80,13 @@ getword(int c, char **token_r, gnc_t gnc, void *closure) ...@@ -80,13 +80,13 @@ getword(int c, char **token_r, gnc_t gnc, void *closure)
int i = 0; int i = 0;
c = skip_whitespace(c, gnc, closure); c = skip_whitespace(c, gnc, closure);
if(c < 0 || c == '"' || c == '\n') if(c < 0 || c == '"' || c == '\n' || c == '#' || c < 0)
return -2; return -2;
do { do {
if(i >= 255) return -2; if(i >= 255) return -2;
buf[i++] = c; buf[i++] = c;
c = gnc(closure); c = gnc(closure);
} while(c != ' ' && c != '\t' && c != '\n' && c >= 0); } while(c != ' ' && c != '\t' && c != '\n' && c != '#' && c >= 0);
buf[i] = '\0'; buf[i] = '\0';
*token_r = strdup(buf); *token_r = strdup(buf);
return c; return c;
...@@ -99,9 +99,7 @@ getstring(int c, char **token_r, gnc_t gnc, void *closure) ...@@ -99,9 +99,7 @@ getstring(int c, char **token_r, gnc_t gnc, void *closure)
int i = 0; int i = 0;
c = skip_whitespace(c, gnc, closure); c = skip_whitespace(c, gnc, closure);
if(c < 0) if(c < 0 || c == '\n' || c == '#')
return c;
if(c == '\n')
return -2; return -2;
/* Unquoted strings have the same syntax as words. */ /* Unquoted strings have the same syntax as words. */
...@@ -286,9 +284,9 @@ parse_filter(int c, gnc_t gnc, void *closure) ...@@ -286,9 +284,9 @@ parse_filter(int c, gnc_t gnc, void *closure)
goto error; goto error;
filter->plen_le = 128; filter->plen_le = 128;
while(c >= 0 && c != '\n') { while(1) {
c = skip_whitespace(c, gnc, closure); c = skip_whitespace(c, gnc, closure);
if(c == '\n' || c == '#') { if(c < 0 || c == '\n' || c == '#') {
c = skip_to_eol(c, gnc, closure); c = skip_to_eol(c, gnc, closure);
break; break;
} }
...@@ -390,9 +388,9 @@ parse_anonymous_ifconf(int c, gnc_t gnc, void *closure, ...@@ -390,9 +388,9 @@ parse_anonymous_ifconf(int c, gnc_t gnc, void *closure,
goto error; goto error;
} }
while(c >= 0 && c != '\n') { while(1) {
c = skip_whitespace(c, gnc, closure); c = skip_whitespace(c, gnc, closure);
if(c == '\n' || c == '#') { if(c < 0 || c == '\n' || c == '#') {
c = skip_to_eol(c, gnc, closure); c = skip_to_eol(c, gnc, closure);
break; break;
} }
...@@ -573,9 +571,9 @@ parse_option(int c, gnc_t gnc, void *closure) ...@@ -573,9 +571,9 @@ parse_option(int c, gnc_t gnc, void *closure)
{ {
char *token; char *token;
while(c >= 0 && c != '\n') { while(1) {
c = skip_whitespace(c, gnc, closure); c = skip_whitespace(c, gnc, closure);
if(c == '\n' || c == '#') { if(c < 0 || c == '\n' || c == '#') {
c = skip_to_eol(c, gnc, closure); c = skip_to_eol(c, gnc, closure);
break; break;
} }
...@@ -702,7 +700,7 @@ parse_config(gnc_t gnc, void *closure) ...@@ -702,7 +700,7 @@ parse_config(gnc_t gnc, void *closure)
if(c < -1) if(c < -1)
return -1; return -1;
while(c >= 0) { while(1) {
c = skip_whitespace(c, gnc, closure); c = skip_whitespace(c, gnc, closure);
if(c == '\n' || c == '#') { if(c == '\n' || c == '#') {
c = skip_to_eol(c, gnc, closure); c = skip_to_eol(c, gnc, closure);
......
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