]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
[v4_1_esv] Corrected right brace detection in parsing
authorThomas Markwalder <tmark@isc.org>
Mon, 8 Sep 2014 17:41:26 +0000 (13:41 -0400)
committerThomas Markwalder <tmark@isc.org>
Mon, 8 Sep 2014 17:41:26 +0000 (13:41 -0400)
    Merges in rt36021

RELNOTES
common/parse.c

index 0aabebc0398af2406e7cb33eed0e6d37d1b3ec93..e4ab10570a699aefe1659a66efd83b3188106d45 100644 (file)
--- a/RELNOTES
+++ b/RELNOTES
@@ -59,6 +59,9 @@ by Eric Young (eay@cryptsoft.com).
 
                        Changes since 4.1.-ESV
 
+- Corrected parser's right brace matching when a statement contains an error.
+  [ISC-Bugs #36021]
+
 - Added check for invalid failover message type.
   [ISC-Bugs #36653]
 
index e0a49525f97b89177fc6f0a1a6fe7c4465427aae..7d27ce6e4875a3f6559dc2154770d6b9c64f44bd 100644 (file)
@@ -72,11 +72,18 @@ struct enumeration_value *find_enumeration_value (const char *name,
 }
 
 /* Skip to the semicolon ending the current statement.   If we encounter
-   braces, the matching closing brace terminates the statement.   If we
-   encounter a right brace but haven't encountered a left brace, return
-   leaving the brace in the token buffer for the caller.   If we see a
-   semicolon and haven't seen a left brace, return.   This lets us skip
-   over:
+   braces, the matching closing brace terminates the statement.
+*/
+void skip_to_semi (cfile)
+       struct parse *cfile;
+{
+       skip_to_rbrace(cfile, 0);
+}
+
+/* Skips everything from the current point upto (and including) the given
+ number of right braces.  If we encounter a semicolon but haven't seen a
+ left brace, consume it and return.
+ This lets us skip over:
 
        statement;
        statement foo bar { }
@@ -84,13 +91,6 @@ struct enumeration_value *find_enumeration_value (const char *name,
        statement}
  
        ...et cetera. */
-
-void skip_to_semi (cfile)
-       struct parse *cfile;
-{
-       skip_to_rbrace (cfile, 0);
-}
-
 void skip_to_rbrace (cfile, brace_count)
        struct parse *cfile;
        int brace_count;
@@ -99,30 +99,36 @@ void skip_to_rbrace (cfile, brace_count)
        const char *val;
 
 #if defined (DEBUG_TOKEN)
-       log_error ("skip_to_rbrace: %d\n", brace_count);
+       log_error("skip_to_rbrace: %d\n", brace_count);
 #endif
        do {
-               token = peek_token (&val, (unsigned *)0, cfile);
+               token = peek_token(&val, NULL, cfile);
                if (token == RBRACE) {
-                       skip_token(&val, (unsigned *)0, cfile);
-                       if (brace_count) {
-                               if (!--brace_count)
-                                       return;
-                       } else
+                       if (brace_count > 0) {
+                               --brace_count;
+                       }
+
+                       if (brace_count == 0) {
+                               /* Eat the brace and return. */
+                               skip_token(&val, NULL, cfile);
                                return;
+                       }
                } else if (token == LBRACE) {
                        brace_count++;
-               } else if (token == SEMI && !brace_count) {
-                       skip_token(&val, (unsigned *)0, cfile);
+               } else if (token == SEMI && (brace_count == 0)) {
+                       /* Eat the semicolon and return. */
+                       skip_token(&val, NULL, cfile);
                        return;
                } else if (token == EOL) {
                        /* EOL only happens when parsing /etc/resolv.conf,
                           and we treat it like a semicolon because the
                           resolv.conf file is line-oriented. */
-                       skip_token(&val, (unsigned *)0, cfile);
+                       skip_token(&val, NULL, cfile);
                        return;
                }
-               token = next_token (&val, (unsigned *)0, cfile);
+
+               /* Eat the current token */
+               token = next_token(&val, NULL, cfile);
        } while (token != END_OF_FILE);
 }