]> granicus.if.org Git - re2c/commitdiff
Fixed segfault cause by out of bounds access.
authorUlya Trofimovich <skvadrik@gmail.com>
Thu, 15 Nov 2018 07:33:25 +0000 (07:33 +0000)
committerUlya Trofimovich <skvadrik@gmail.com>
Thu, 15 Nov 2018 07:33:25 +0000 (07:33 +0000)
This fixes bug #227.
Found by american fuzzy lop (thanks to Henri Salo).

re2c/src/ast/validate.cc
re2c/test/american_fuzzy_lop/008.c [new file with mode: 0644]
re2c/test/american_fuzzy_lop/008.re [new file with mode: 0644]

index 66ec19b0b859ff08481ee74eac299e5b1dd961e7..1f735d8ce09e71901fcc315179c06f286c0f0f79 100644 (file)
@@ -31,6 +31,7 @@ void validate_mode(Scanner::ParseMode mode, bool rflag, bool rules, Scanner &inp
 
 void validate_ast(const specs_t &specs, bool cflag)
 {
+    static const uint32_t NONE = ~0u;
     specs_t::const_iterator i,
         b = specs.begin(),
         e = specs.end();
@@ -46,16 +47,26 @@ void validate_ast(const specs_t &specs, bool cflag)
     if (!cflag) {
         for (i = b; i != e; ++i) {
             if (i->name != "") {
-                fatal_l(i->rules[0].code->fline,
-                    "conditions are only allowed with '-c', '--conditions' option");
+                const uint32_t l = !i->rules.empty()
+                    ? i->rules[0].code->fline : !i->defs.empty()
+                        ? i->defs[0]->fline : NONE;
+                if (l != NONE) {
+                    fatal_l(l, "conditions are only allowed with '-c', "
+                        "'--conditions' option");
+                }
+
             }
         }
     } else {
         for (i = b; i != e; ++i) {
             if (i->name == "") {
-                fatal_l(i->rules[0].code->fline,
-                    "non-conditional rules are not allowed"
-                    " with '-c', '--conditions' option");
+                const uint32_t l = !i->rules.empty()
+                    ? i->rules[0].code->fline : !i->defs.empty()
+                        ? i->defs[0]->fline : NONE;
+                if (l != NONE) {
+                    fatal_l(l, "non-conditional rules are not allowed with "
+                        "'-c', '--conditions' option");
+                }
             }
         }
 
diff --git a/re2c/test/american_fuzzy_lop/008.c b/re2c/test/american_fuzzy_lop/008.c
new file mode 100644 (file)
index 0000000..6d1d059
--- /dev/null
@@ -0,0 +1 @@
+re2c: error: line 2: conditions are only allowed with '-c', '--conditions' option
diff --git a/re2c/test/american_fuzzy_lop/008.re b/re2c/test/american_fuzzy_lop/008.re
new file mode 100644 (file)
index 0000000..5cff2c0
--- /dev/null
@@ -0,0 +1,3 @@
+/*!re2c
+    <c> * {}
+*/