Skip to content

cpp_peglib

Suresoft-GLaDOS edited this page May 26, 2023 · 9 revisions

#1

Link : https://github.com/yhirose/cpp-peglib/commit/0061f393de54cf0326621c079dc2988336d1ebb3
Description: NULL Pointer Dereference
CVE Info: CVE-2020-23914

At peglib.h

@@ -3445,7 +3445,6 @@ private:
           log(line.first, line.second,
               "Ignore operator cannot be applied to '" + rule.name + "'.");
         }
+        ret = false;
       }
     }

Tags
#Omission #Memory-error #Address-sanitizer #Single-line #Added #CVE

#2

Link : https://github.com/yhirose/cpp-peglib/commit/072cdb6d235c09d858e91c976c006cefa9ef10ea
Description: Macro that passes args to another macro causes crash

At peglib.h

@@ -2477,12 +2477,7 @@ inline size_t Holder::parse_core(const char *s, size_t n, SemanticValues &sv,
   // Macro reference
   // TODO: need packrat support
+  if (outer_->is_macro) {
+    c.rule_stack.push_back(outer_);
+    auto len = ope_->parse(s, n, sv, c, dt);
+    c.rule_stack.pop_back();
+    return len;
+  }
-  if (outer_->is_macro) { return ope_->parse(s, n, sv, c, dt); }
   size_t len;
   any val;

Tags
#Omission #Memory-error #Address-sanitizer #Multi-line #Modified

#3

Link : https://github.com/yhirose/cpp-peglib/commit/8e890ced7fdf762e7a73380d887daccec1b75ec2
Description: Fix support to custom AST node types

At peglib.h

@@ -3937,7 +3937,7 @@ public:
   template <typename T = Ast> parser &enable_ast() {
     for (auto &x : *grammar_) {
       auto &rule = x.second;
+      if (!rule.action) { add_ast_action<T>(rule); }
-      if (!rule.action) { add_ast_action(rule); }
     }
     return *this;
   }

Tags
#Logical-error #Memory-error #Single-line #Modified

#4

Link : https://github.com/yhirose/cpp-peglib/commit/be470f93320b6ec98668a65452a5ac4a6b9e8468
Description: Macro parameters are hidden by rule identifiers

At peglib.h

@@ -2498,7 +2498,7 @@ inline void LinkReferences::visit(Reference& ope) {
     }
     // Check if the reference is a definition rule
+    if (!found_param && grammar_.count(ope.name_)) {
-    if (grammar_.count(ope.name_)) {
         auto& rule = grammar_.at(ope.name_);
         ope.rule_ = &rule;
     }

Tags
#Invalid-condition #Single-line #Modified

#5

Link : https://github.com/yhirose/cpp-peglib/commit/2d276c8cd9a64800587172b40b8cb74e273a4f88
Description: Fix left recursion not detected

At peglib.h

@@ -2374,9 +2374,6 @@ inline void DetectLeftRecursion::visit(Reference& ope) {
         refs_.insert(ope.name_);
         if (ope.rule_) {
             ope.rule_->accept(*this);
+            if (done_ == false) {
+                return;
+            }
         }
     }
     done_ = true;

Tags
#Omission #Multi-line #Added

#6

Link : https://github.com/yhirose/cpp-peglib/commit/5445b5c2bb8310c3a65a9b61a84a0463660047a4
Description: Packrat parsing problem with macro

At peglib.h

@@ -2029,9 +2029,6 @@ inline void AssignIDToDefinition::visit(Holder& ope) {
 inline void AssignIDToDefinition::visit(Reference& ope) {
     if (ope.rule_) {
+        for (auto arg: ope.args_) {
+            arg->accept(*this);
+        }
         ope.rule_->accept(*this);
     }
 }

Tags
#Omission #Memory-error #Address-sanitizer #Multi-line #Added

#7

Link : https://github.com/yhirose/cpp-peglib/commit/e72b63045585aececc0c3e81885b9b35d1dd99d3
Description: Added line_info method on SemanticValues

At peglib.h

@@ -245,7 +245,6 @@ struct SemanticValues : protected std::vector<any>
     // Line number and column at which the matched string is
     std::pair<size_t, size_t> line_info() const {
+        return peg::line_info(ss, s_);
     }
     // Choice number (0 based index)

Tags
#Omission #Single-line #Added

#8

Link : https://github.com/yhirose/cpp-peglib/commit/a3cfd1b8ada850722176f58cb52cb0e23e81568a
Description: Handled UTF-8 codes from 0x80 as valid identifier codes

At peglib.h

@@ -1588,7 +1588,7 @@ private:
         g["Identifier"] <= seq(g["IdentCont"], g["Spacing"]);
         g["IdentCont"]  <= seq(g["IdentStart"], zom(g["IdentRest"]));
+        g["IdentStart"] <= cls("a-zA-Z_\x80-\xff");
-        g["IdentStart"] <= cls("a-zA-Z_");
         g["IdentRest"]  <= cho(g["IdentStart"], cls("0-9"));
         g["Literal"]    <= cho(seq(cls("'"), anc(zom(seq(npd(cls("'")), g["Char"]))), cls("'"), g["Spacing"]),

Tags
#Invalid-format-string #Single-line #Modified

#9

Link : https://github.com/yhirose/cpp-peglib/commit/5b9daaf0906f2ac45cb0639f11e71805034dc4fb
Description: Restored before/after handlers.

At peglib.h

@@ -1227,10 +1227,6 @@ inline size_t Holder::parse(const char* s, size_t n, SemanticValues& sv, Context
     c.packrat(s, outer_->id, len, val, [&](any& val) {
         auto& chldsv = c.push();
+        if (outer_->before) {
+            outer_->before(dt);
+        }
+
         const auto& rule = *ope_;
         len = rule.parse(s, n, chldsv, c, dt);
@@ -1257,10 +1253,6 @@ inline size_t Holder::parse(const char* s, size_t n, SemanticValues& sv, Context
             }
         }
+        if (outer_->after) {
+            outer_->after(dt);
+        }
+
         c.pop();
     });

Tags
#Omission #Multi-line #Added

#10

Link : https://github.com/yhirose/cpp-peglib/commit/b92da07beddd286cc16ef3620793e297a5f17a6c
Description: Interaction between %whitespace and token boundary operators

At peglib.h

@@ -827,7 +827,7 @@ public:
   std::vector<Definition *> rule_stack;
   std::vector<std::vector<std::shared_ptr<Ope>>> args_stack;
+  size_t in_token_boundary_count = 0;
-  bool in_token = false;
   std::shared_ptr<Ope> whitespaceOpe;
   bool in_whitespace = false;
@@ -2392,7 +2392,7 @@ inline size_t parse_literal(const char *s, size_t n, SemanticValues &sv,
   }
   // Skip whiltespace
+  if (!c.in_token_boundary_count) {
-  if (!c.in_token) {
     if (c.whitespaceOpe) {
       auto len = c.whitespaceOpe->parse(s + i, n - i, sv, c, dt);
       if (fail(len)) { return static_cast<size_t>(-1); }
@@ -2457,22 +2457,17 @@ inline size_t LiteralString::parse_core(const char *s, size_t n,
 inline size_t TokenBoundary::parse_core(const char *s, size_t n,
                                         SemanticValues &sv, Context &c,
                                         any &dt) const {
+  size_t len;
+  {
+    c.in_token_boundary_count++;
+    auto se = make_scope_exit([&]() { c.in_token_boundary_count--; });
+    len = ope_->parse(s, n, sv, c, dt);
+  }
-  c.in_token = true;
-  auto se = make_scope_exit([&]() { c.in_token = false; });
-  auto len = ope_->parse(s, n, sv, c, dt);
   if (success(len)) {
     sv.tokens.emplace_back(std::make_pair(s, len));
+    if (!c.in_token_boundary_count) {
+      if (c.whitespaceOpe) {
+        auto l = c.whitespaceOpe->parse(s + len, n - len, sv, c, dt);
+        if (fail(l)) { return static_cast<size_t>(-1); }
+        len += l;
+      }
-    if (c.whitespaceOpe) {
-      auto l = c.whitespaceOpe->parse(s + len, n - len, sv, c, dt);
-      if (fail(l)) { return static_cast<size_t>(-1); }
-      len += l;
     }
   }
   return len;

Tags
#Omission #Multi-line #Modified

Clone this wiki locally