From 9c1e7a93761fbc6eecfe82adf7f03375d472d9e1 Mon Sep 17 00:00:00 2001 From: xx <0x7fancyxx@gmail.com> Date: Mon, 22 Jan 2024 16:30:32 +0800 Subject: [PATCH 1/2] fix: revert '+' syntax optimize --- grammars/f1_g4_translate.py | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/grammars/f1_g4_translate.py b/grammars/f1_g4_translate.py index b69e461..0b54790 100644 --- a/grammars/f1_g4_translate.py +++ b/grammars/f1_g4_translate.py @@ -75,30 +75,11 @@ def esc_token(self, t): t = t.replace('\t', '\\t') return t - def rule_to_s(self, key, rule, grammar): - # feat: add 'directly head/tail recursion' optimized syntax '+' - if len(rule) == 0: - return '' - - # head recursion - recursion = False - if rule[0] == key: - rule = rule[1:] - recursion = True - # tail recursion - if rule[-1] == key: - rule = rule[:-1] - recursion = True - - # append rules - data = ' '.join(["'%s'" % self.esc_token(t) + def rule_to_s(self, rule, grammar): + return ' '.join(["'%s'" % self.esc_token(t) if t not in grammar else self.to_key(t) for t in rule]) - if recursion: - data = "(%s)+" % data - return data - def translate(self): lines = ['grammar Grammar;'] entries = '\n | '.join([self.to_key(entry_k) + ' EOF' for entry_k in self.entry_keys]) @@ -108,7 +89,7 @@ def translate(self): ;''' % entries) for k in self.grammar_keys: rules = self.grammar[k] - v = '\n | '.join([self.rule_to_s(k, rule, self.grammar) + v = '\n | '.join([self.rule_to_s(rule, self.grammar) for rule in rules]) lines.append('''\ %s From 032a98438d61dabcbc1169f98c339dde8a67acff Mon Sep 17 00:00:00 2001 From: xx <0x7fancyxx@gmail.com> Date: Tue, 23 Jan 2024 18:49:54 +0800 Subject: [PATCH 2/2] fix: add growth check limit for 'random_recursive_mutation' --- src/grammar_mutator.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/grammar_mutator.c b/src/grammar_mutator.c index bab4116..9644881 100644 --- a/src/grammar_mutator.c +++ b/src/grammar_mutator.c @@ -556,7 +556,11 @@ size_t afl_custom_fuzz(my_mutator_t *data, __attribute__((unused)) uint8_t *buf, const unsigned RRM_GROWTH = 10; // Allow 2**RRM_GROWTH of bytes of expansion tree_t *rrm_tree = NULL; tree_to_buf(tree); + int failed_count = 8; do { + if (failed_count-- <= 0) { + break; + } if (rrm_tree) tree_free(rrm_tree); rrm_tree =