Superion icon indicating copy to clipboard operation
Superion copied to clipboard

New parser is incompatible with current source code

Open zhangysh1995 opened this issue 5 years ago • 8 comments

Hi,

Follow my previous issue #8 , I added a parser SQLite.g4. And I changed the Makefile to compile it as:


afl-fuzz: afl-fuzz.c $(COMM_HDR) | test_x86
        $(CC) $(CFLAGS) [email protected] -o $@ $(LDFLAGS) ./tree_mutation/sql_parser/libTreeMutation.so

And I make:


zhangys@xxx:~/utility/superion$ make
[*] Checking for the ability to compile x86 code...
[+] Everything seems to be working, ready to compile.
cc -O3 -funroll-loops -Wall -D_FORTIFY_SOURCE=2 -g -Wno-pointer-sign -DAFL_PATH=\"/usr/local/lib/afl\" -DDOC_PATH=\"/usr/local/share/doc/afl\" -DBIN_PATH=\"/usr/local/bin\" afl-gcc.c -o afl-gcc -ldl
set -e; for i in afl-g++ afl-clang afl-clang++; do ln -sf afl-gcc $i; done
cc -O3 -funroll-loops -Wall -D_FORTIFY_SOURCE=2 -g -Wno-pointer-sign -DAFL_PATH=\"/usr/local/lib/afl\" -DDOC_PATH=\"/usr/local/share/doc/afl\" -DBIN_PATH=\"/usr/local/bin\" afl-fuzz.c -o afl-fuzz -ldl ./tree_mutation/sql_parser/libTreeMutation.so
/tmp/cc96fGic.o: In function `fuzz_one':
/home/zhangys/utility/superion/afl-fuzz.c:6124: undefined reference to `parse'
/home/zhangys/utility/superion/afl-fuzz.c:6132: undefined reference to `fuzz'
collect2: error: ld returned 1 exit status
Makefile:73: recipe for target 'afl-fuzz' failed
make: *** [afl-fuzz] Error 1

It gives an error. if we look at the parse and fuzz functions, they are implemented in tree_mutation/xxx_parser/TreeMutation.cpp.

Let's see .../js_parser/TreeMutation.cpp

#include <iostream>
#include <cstring>
#include "antlr4-runtime.h"
#include "ECMAScriptLexer.h"
#include "ECMAScriptParser.h"
#include "ECMAScriptBaseVisitor.h"
#include "ECMAScriptSecondVisitor.h"
....

If look at the TreeMutation.cpp under the folder of different parsers, we could see almost the same code.

How doI write the new TreeMutation.cpp for the new grammar?

zhangysh1995 avatar Dec 30 '19 13:12 zhangysh1995

I try to modify the TreeMuataion.cpp but it is incompatible:

TreeMutation.cpp:39:34: error: ‘class SQLiteParser’ has no member named ‘program’
   tree::ParseTree* tree = parser.program();
                                  ^~~~~~~
TreeMutation.cpp:47:33: error: ‘class SQLiteBaseVisitor’ has no member named ‘intervals’
    int interval_size = visitor->intervals.size();
                                 ^~~~~~~~~
TreeMutation.cpp:49:56: error: ‘class SQLiteBaseVisitor’ has no member named ‘intervals’
     if(find(intervals.begin(),intervals.end(),visitor->intervals[i])!=intervals.end()){
                                                        ^~~~~~~~~
TreeMutation.cpp:50:23: error: ‘class SQLiteBaseVisitor’ has no member named ‘intervals’
     }else if(visitor->intervals[i].a<=visitor->intervals[i].b){
                       ^~~~~~~~~
TreeMutation.cpp:50:48: error: ‘class SQLiteBaseVisitor’ has no member named ‘intervals’
     }else if(visitor->intervals[i].a<=visitor->intervals[i].b){
                                                ^~~~~~~~~
TreeMutation.cpp:51:35: error: ‘class SQLiteBaseVisitor’ has no member named ‘intervals’
      intervals.push_back(visitor->intervals[i]);
                                   ^~~~~~~~~
TreeMutation.cpp:54:30: error: ‘class SQLiteBaseVisitor’ has no member named ‘texts’
    int texts_size = visitor->texts.size();
                              ^~~~~
TreeMutation.cpp:56:48: error: ‘class SQLiteBaseVisitor’ has no member named ‘texts’
     if(find(texts.begin(),texts.end(),visitor->texts[i])!=texts.end()){
                                                ^~~~~
TreeMutation.cpp:57:23: error: ‘class SQLiteBaseVisitor’ has no member named ‘texts’
     }else if(visitor->texts[i].length()>MAXTEXT){
                       ^~~~~
TreeMutation.cpp:59:31: error: ‘class SQLiteBaseVisitor’ has no member named ‘texts’
      texts.push_back(visitor->texts[i]);
                               ^~~~~
TreeMutation.cpp:74:38: error: ‘class SQLiteParser’ has no member named ‘program’
     tree::ParseTree* treeS = parserS.program();
                                      ^~~~~~~
TreeMutation.cpp:79:6: error: ‘SQLiteSecondVisitor’ was not declared in this scope
      SQLiteSecondVisitor *visitorS=new SQLiteSecondVisitor();
      ^~~~~~~~~~~~~~~~~~~
TreeMutation.cpp:79:6: note: suggested alternative: ‘SQLiteBaseVisitor’
      SQLiteSecondVisitor *visitorS=new SQLiteSecondVisitor();
      ^~~~~~~~~~~~~~~~~~~
      SQLiteBaseVisitor
TreeMutation.cpp:79:27: error: ‘visitorS’ was not declared in this scope
      SQLiteSecondVisitor *visitorS=new SQLiteSecondVisitor();
                           ^~~~~~~~
TreeMutation.cpp:79:27: note: suggested alternative: ‘visitor’
      SQLiteSecondVisitor *visitorS=new SQLiteSecondVisitor();
                           ^~~~~~~~
                           visitor
TreeMutation.cpp:79:40: error: expected type-specifier before ‘SQLiteSecondVisitor’
      SQLiteSecondVisitor *visitorS=new SQLiteSecondVisitor();
                                        ^~~~~~~~~~~~~~~~~~~
TreeMutation.cpp:89:30: error: type ‘<type error>’ argument given to ‘delete’, expected pointer
                       delete visitorS;
                             ^~~~~~~~

Could I know the exact version of ANTLR used in this project?

zhangysh1995 avatar Dec 31 '19 07:12 zhangysh1995

please make sure you understand the approach and what you are doing.

Yushan ZHANG [email protected] 于2019年12月31日周二 下午3:30写道:

I try to modify the TreeMuataion.cpp but it is incompatible:

TreeMutation.cpp:39:34: error: ‘class SQLiteParser’ has no member named ‘program’

tree::ParseTree* tree = parser.program();

                              ^~~~~~~

TreeMutation.cpp:47:33: error: ‘class SQLiteBaseVisitor’ has no member named ‘intervals’

int interval_size = visitor->intervals.size();

                             ^~~~~~~~~

TreeMutation.cpp:49:56: error: ‘class SQLiteBaseVisitor’ has no member named ‘intervals’

 if(find(intervals.begin(),intervals.end(),visitor->intervals[i])!=intervals.end()){

                                                    ^~~~~~~~~

TreeMutation.cpp:50:23: error: ‘class SQLiteBaseVisitor’ has no member named ‘intervals’

 }else if(visitor->intervals[i].a<=visitor->intervals[i].b){

                   ^~~~~~~~~

TreeMutation.cpp:50:48: error: ‘class SQLiteBaseVisitor’ has no member named ‘intervals’

 }else if(visitor->intervals[i].a<=visitor->intervals[i].b){

                                            ^~~~~~~~~

TreeMutation.cpp:51:35: error: ‘class SQLiteBaseVisitor’ has no member named ‘intervals’

  intervals.push_back(visitor->intervals[i]);

                               ^~~~~~~~~

TreeMutation.cpp:54:30: error: ‘class SQLiteBaseVisitor’ has no member named ‘texts’

int texts_size = visitor->texts.size();

                          ^~~~~

TreeMutation.cpp:56:48: error: ‘class SQLiteBaseVisitor’ has no member named ‘texts’

 if(find(texts.begin(),texts.end(),visitor->texts[i])!=texts.end()){

                                            ^~~~~

TreeMutation.cpp:57:23: error: ‘class SQLiteBaseVisitor’ has no member named ‘texts’

 }else if(visitor->texts[i].length()>MAXTEXT){

                   ^~~~~

TreeMutation.cpp:59:31: error: ‘class SQLiteBaseVisitor’ has no member named ‘texts’

  texts.push_back(visitor->texts[i]);

                           ^~~~~

TreeMutation.cpp:74:38: error: ‘class SQLiteParser’ has no member named ‘program’

 tree::ParseTree* treeS = parserS.program();

                                  ^~~~~~~

TreeMutation.cpp:79:6: error: ‘SQLiteSecondVisitor’ was not declared in this scope

  SQLiteSecondVisitor *visitorS=new SQLiteSecondVisitor();

  ^~~~~~~~~~~~~~~~~~~

TreeMutation.cpp:79:6: note: suggested alternative: ‘SQLiteBaseVisitor’

  SQLiteSecondVisitor *visitorS=new SQLiteSecondVisitor();

  ^~~~~~~~~~~~~~~~~~~

  SQLiteBaseVisitor

TreeMutation.cpp:79:27: error: ‘visitorS’ was not declared in this scope

  SQLiteSecondVisitor *visitorS=new SQLiteSecondVisitor();

                       ^~~~~~~~

TreeMutation.cpp:79:27: note: suggested alternative: ‘visitor’

  SQLiteSecondVisitor *visitorS=new SQLiteSecondVisitor();

                       ^~~~~~~~

                       visitor

TreeMutation.cpp:79:40: error: expected type-specifier before ‘SQLiteSecondVisitor’

  SQLiteSecondVisitor *visitorS=new SQLiteSecondVisitor();

                                    ^~~~~~~~~~~~~~~~~~~

TreeMutation.cpp:89:30: error: type ‘’ argument given to ‘delete’, expected pointer

                   delete visitorS;

                         ^~~~~~~~

Could I know the exact version of ANTLR used in this project?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/zhunki/Superion/issues/9?email_source=notifications&email_token=ACXW5VE4DCPHYLPGWCXZMRLQ3LYKNA5CNFSM4KBMU7BKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEH33D7I#issuecomment-569881085, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACXW5VB2V6A5ZOQKYMYE7D3Q3LYKNANCNFSM4KBMU7BA .

zhunki avatar Dec 31 '19 07:12 zhunki

So how could I change the file?

zhangysh1995 avatar Dec 31 '19 07:12 zhangysh1995

I exaplained all my steps in this issue and try to fix the problem. I believe I understand what I am doing.

zhangysh1995 avatar Dec 31 '19 07:12 zhangysh1995

My guess is TreeMutator your own mutator.... you need to implement how to to mutate by yourself. And antlr only make a base parser for you, also a parser need to be provided.

StarGazerM avatar Jun 29 '20 18:06 StarGazerM

ANTLR only generates empty BaseVisitor. The authors modified the BaseVisitor to intercept certain intermediate values. Besides, the authors also generate their own SecondVisitor, which is slightly different from BaseVisitor. The TreeMutation.cpp also requires some minor adaption for different grammars.

Unfortunately, the authors did not disclose any such details. I think I have figured it out and wrote some instructions for this. Please check my fork for details if you are still interested: https://github.com/peng-hui/Superion

peng-hui avatar Mar 25 '21 16:03 peng-hui

there is a python script under the corresponding folder, which can do the job for you.

peng-hui @.***> 于2021年3月26日周五 上午12:20写道:

ANTLR only generates empty BaseVisitor. The authors modified the BaseVisitor to intercept certain intermediate values. Besides, the authors also generate their own SecondVisitor, which is slightly different from BaseVisitor. The TreeMutation.cpp also requires some minor adaption for different grammars.

Unfortunately, the authors did not disclose any such details. I think I have figured it out and wrote some instructions for this. Please check my fork for details if you are still interested: https://github.com/peng-hui/Superion

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/zhunki/Superion/issues/9#issuecomment-807035396, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACXW5VEIBQPXQII2MPAJC7LTFNPDXANCNFSM4KBMU7BA .

zhunki avatar Mar 28 '21 12:03 zhunki

there is a python script under the corresponding folder, which can do the job for you.

Hmmm, do you mean my fork or your own repository? Actually, I don't find such a python script in your code. I would appreciate it if you can add more detailed instructions in your README file to guide other users on how to generate the SecondVisitor and TreeMutation step by step.

peng-hui avatar Mar 28 '21 13:03 peng-hui