Code Monkey home page Code Monkey logo

Comments (7)

X-C3LL avatar X-C3LL commented on August 18, 2024 1

Hi!

I tested it on two machines with a more recent version of my distro (Debian 10) and it works like a charm (just needed to do the .py edit again):

psyconauta@insulaanglia ᐓ  ~/Grammar-Mutator |stable⚡ ᐓ   cat seeds/6
<?php
try {
 try {
class Class02 {
	test02;
}

} catch (Exception $e){}} catch(Error $e){}
try {
 try {
class Class04 {
	test03;
}

} catch (Exception $e){}} catch(Error $e){}
?>%                                          

So it's highly probable the problem is in my side. Let me upgrade the VM (currently is running Debian 9) and test it to confirm it.

from grammar-mutator.

h1994st avatar h1994st commented on August 18, 2024

Hi @X-C3LL ,

Your grammar looks fine. the generated test cases are good as well, except for your last example. The generator does produce different results every time due to randomness. You may want to set a fixed random seed, as shown in the last argument of the command below, for the grammar generator.

May I know your expected outputs? I tried your grammar on my side, using the latest dev branch and the following command. The generator works as I expected.

./grammar_generator-phpexcept 100 1000 ./seeds ./trees 1641180035

from grammar-mutator.

X-C3LL avatar X-C3LL commented on August 18, 2024

Hi!

Setting your default value:

 psyconauta@insulaalchimia ᐓ  ~/Grammar-Mutator |stable⚡ ᐓ   ./grammar_generator-phpexcept 100 1000 ./seeds ./trees 1641180035
Using seed 100
 psyconauta@insulaalchimia ᐓ  ~/Grammar-Mutator |stable⚡ ᐓ   cat seeds/*                                                      
Class05Class03Class04Class04Class05Class03Class05Class03Class05Class02Class04Class05Class03Class05Class04Class02Class03Class01Class01Class05Class02Class05Class03Class01Class03Class01Class04Class03Class01Class01Class05Class05Class04Class05Class03Class04Class02Class03Class01Class03Class01Class02Class02Class05Class02Class05Class01Class04Class05Class04Class01Class05Class02Class03Class01Class04Class02Class02Class02Class01Class04Class03Class04Class03Class02Class05Class04Class01Class05Class04Class05Class03Class01Class02Class05Class01Class02Class02Class05Class04Class05Class05Class05Class04Class05Class05Class01Class05Class04Class05Class05Class04Class05Class03Class03Class03Class01Class02Class03Class02

If I change the fixed value, the result it's the same:

 psyconauta@insulaalchimia ᐓ  ~/Grammar-Mutator |stable⚡ ᐓ   sudo rm seeds/* && sudo rm trees/*                               
 psyconauta@insulaalchimia ᐓ  ~/Grammar-Mutator |stable⚡ ᐓ   ./grammar_generator-phpexcept 100 1000 ./seeds ./trees 1337180035
Using seed 100
 psyconauta@insulaalchimia ᐓ  ~/Grammar-Mutator |stable⚡ ᐓ   cat seeds/*                                                  
 psyconauta@insulaalchimia ᐓ  ~/Grammar-Mutator |stable⚡ ᐓ   ./grammar_generator-phpexcept 100 1000 ./seeds ./trees 1337181337
Using seed 100
 psyconauta@insulaalchimia ᐓ  ~/Grammar-Mutator |stable⚡ ᐓ   cat seeds/*
Class05Class03Class04Class04Class05Class03Class05Class03Class05Class02Class04Class05Class03Class05Class04Class02Class03Class01Class01Class05Class02Class05Class03Class01Class03Class01Class04Class03Class01Class01Class05Class05Class04Class05Class03Class04Class02Class03Class01Class03Class01Class02Class02Class05Class02Class05Class01Class04Class05Class04Class01Class05Class02Class03Class01Class04Class02Class02Class02Class01Class04Class03Class04Class03Class02Class05Class04Class01Class05Class04Class05Class03Class01Class02Class05Class01Class02Class02Class05Class04Class05Class05Class05Class04Class05Class05Class01Class05Class04Class05Class05Class04Class05Class03Class03Class03Class01Class02Class03Class02%

Looks like it is taking the number of seeds (first arg) as parameter instead of the last arg (Just saw your last commit). But even changing the fixed value, all the seeds generated contains only the rule <CLASSNAME>. If I recompile and try the same seed value, it picks another rule or a small chain of rules, but rarely applies all of them.

What I was expecting is generating a batch of variants of the next example (or the same with recursion at <FUZZ> level) where all the rules were applied:

<?php
try {
 try {
class Class04 {
	test03;

}

} catch (Exception $e){}} catch(Error $e){}
?>

The PHP logic does not matter, I was using a bigger file with all the rules, just created this small grammar to illustrate the issue


OTOH I had to edit `grammars/f1_c_gen.py`:
 import sys
 import itertools
 import random
 import os
 import string
 import json
 
 from f1_common import LimitFuzzer
 
 
 class TreeNode:
     #node_type: int = 0
     #rule_id: int = 0
     #val: str = ''
     #parent: 'TreeNode' = None
     #subnodes: list = None

I had to comment it to avoid this error:

  File "grammars/f1_c_gen.py", line 39
    node_type: int = 0
             ^
SyntaxError: invalid syntax
  File "grammars/f1_c_gen.py", line 39
    node_type: int = 0
             ^
SyntaxError: invalid syntax

from grammar-mutator.

h1994st avatar h1994st commented on August 18, 2024

Looks like it is taking the number of seeds (first arg) as parameter instead of the last arg (Just saw your last commit). But even changing the fixed value, all the seeds generated contains only the rule <CLASSNAME>. If I recompile and try the same seed value, it picks another rule or a small chain of rules, but rarely applies all of them.

What I was expecting is generating a batch of variants of the next example (or the same with recursion at <FUZZ> level) where all the rules were applied

That is weird. I did generate test cases with recursive <FUZZ> rule, like:

<?php
try {
 try {
class Class04 {
        test01;
}

} catch (Exception $e){}} catch(Error $e){}
try {
 try {

} catch (Exception $e){}} catch(Error $e){}
try {
 try {
class Class05 {
        test02;
}

} catch (Exception $e){}} catch(Error $e){}
try {
 try {

} catch (Exception $e){}} catch(Error $e){}
?>
  File "grammars/f1_c_gen.py", line 39
    node_type: int = 0
             ^
SyntaxError: invalid syntax
  File "grammars/f1_c_gen.py", line 39
    node_type: int = 0
             ^
SyntaxError: invalid syntax

This error did not show up as well. May I know your python3 version?

from grammar-mutator.

X-C3LL avatar X-C3LL commented on August 18, 2024

Hi

My version:

Python 3.7.3

from grammar-mutator.

h1994st avatar h1994st commented on August 18, 2024

Thanks. The python version looks fine.

One possible reason for your issue (no recursive <FUZZ> rule) might be that <CLASSNAME> is wrongly identified as the entry rule for the grammar. Can you share with me the generated f1_c_fuzz.h in include directory?

from grammar-mutator.

X-C3LL avatar X-C3LL commented on August 18, 2024

Yep, the problem was on my side. Upgrading to Debian 10 solved the issue: every time the whole chain of rules is used.

 psyconauta@insulaalchimia ᐓ  ~/Grammar-Mutator |stable⚡ ᐓ   lsb_release -d                                         
Description:	Debian GNU/Linux 10 (buster)
 psyconauta@insulaalchimia ᐓ  ~/Grammar-Mutator |stable⚡ ᐓ   ./grammar_generator-phpexcept 100 1000 ./seeds ./trees 
Using seed 1641239392
 psyconauta@insulaalchimia ᐓ  ~/Grammar-Mutator |stable⚡ ᐓ   cat seeds/1
<?php
try {
 try {
class Class01 {
	test03;
}

} catch (Exception $e){}} catch(Error $e){}
try {
 try {
class Class05 {
	test02;
}

} catch (Exception $e){}} catch(Error $e){}
try {
 try {

} catch (Exception $e){}} catch(Error $e){}
try {
 try {

} catch (Exception $e){}} catch(Error $e){}
?>%                                               

from grammar-mutator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.