diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2012-11-27 18:52:40 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2012-11-27 18:52:40 +0000 |
commit | ba1f6d2eaac7d4d8e8f08f78ed9f5f947e14c499 (patch) | |
tree | 3b19780336785cd07e287d5b9e7741c9f5e34e9a /sbin | |
parent | 730481217dc73fdcd0a27476785cf79301397be7 (diff) |
Clean up parsing of option lists. Part 7 (and final).
Allow 'request ;', 'require ;' and 'ignore ;' as requests to create
empty lists of options. Thus enabling the removal of built-in lists
or the removal of global lists inside an 'interface' declaration.
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/dhclient/clparse.c | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c index c22072c6696..6e44f3d2399 100644 --- a/sbin/dhclient/clparse.c +++ b/sbin/dhclient/clparse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clparse.c,v 1.48 2012/11/27 15:51:48 krw Exp $ */ +/* $OpenBSD: clparse.c,v 1.49 2012/11/27 18:52:39 krw Exp $ */ /* Parser for dhclient config and lease files... */ @@ -188,7 +188,7 @@ parse_client_statement(FILE *cfile) return; case TOK_REQUEST: count = parse_option_list(cfile, optlist, sizeof(optlist)); - if (count > 0) { + if (count != -1) { config->requested_option_count = count; memcpy(config->requested_options, optlist, sizeof(config->requested_options)); @@ -196,7 +196,7 @@ parse_client_statement(FILE *cfile) return; case TOK_REQUIRE: count = parse_option_list(cfile, optlist, sizeof(optlist)); - if (count > 0) { + if (count != -1) { config->required_option_count = count; memcpy(config->required_options, optlist, sizeof(config->required_options)); @@ -204,7 +204,7 @@ parse_client_statement(FILE *cfile) return; case TOK_IGNORE: count = parse_option_list(cfile, optlist, sizeof(optlist)); - if (count > 0) { + if (count != -1) { config->ignored_option_count = count; memcpy(config->ignored_options, optlist, sizeof(config->ignored_options)); @@ -315,10 +315,13 @@ parse_option_list(FILE *cfile, u_int8_t *list, size_t sz) ix = 0; do { token = next_token(&val, cfile); + if (token == ';' && ix == 0) { + /* Empty list. */ + return (0); + } if (!is_identifier(token)) { parse_warn("expected option name."); - skip_to_semi(cfile); - return (0); + goto syntaxerror; } /* * 0 (DHO_PAD) and 255 (DHO_END) are not valid in option @@ -331,21 +334,18 @@ parse_option_list(FILE *cfile, u_int8_t *list, size_t sz) if (i == DHO_END) { parse_warn("%s: unexpected option name.", val); - skip_to_semi(cfile); - return (0); + goto syntaxerror; } if (ix == sz) { parse_warn("%s: too many options.", val); - skip_to_semi(cfile); - return (0); + goto syntaxerror; } /* Avoid storing duplicate options in the list. */ for (j = 0; j < ix; j++) { if (list[j] == i) { parse_warn("%s: option in list more than once.", val); - skip_to_semi(cfile); - return (0); + goto syntaxerror; } } list[ix++] = i; @@ -353,10 +353,13 @@ parse_option_list(FILE *cfile, u_int8_t *list, size_t sz) } while (token == ','); if (token != ';') { parse_warn("expecting semicolon."); - skip_to_semi(cfile); - return (0); + goto syntaxerror; } return (ix); + +syntaxerror: + skip_to_semi(cfile); + return (-1); } /* |