0

After calling the JavaParser, I want to visit/select all the BufferedReader objects that reads from Sockets or ServerSocket. The problem is that the object of BufferedReader is not defined directly from it, instead the declaration of InputStreamReader is there. Notice that I do not want to visit BufferedReader objects that reads from a file or anything else, I am interested only in those which read from a Socket.

For example:

In the two blocks of code code below I want the visitor to select bf1 but not bf2.

Any idea how to do it?

    ServerSocket serverSocket = new ServerSocket(1024);
    Socket socket = serverSocket.accept();
    InputStreamReader inputReader = new InputStreamReader(socket.getInputStream());
    BufferedReader bf1 = new BufferedReader(inputReader);
    String x = bf1.readLine();

and

InputStreamReader Stream = new InputStreamReader(System.in);
BufferedReader bf2 = new BufferedReader(Stream);
int y = bf2.readLine();

Much appreciated!

S. Nabil
  • 319
  • 1
  • 10
  • That's a semantic not a syntactic relationship so probably not something you can reliably do with parsing. – pvg May 07 '17 at 12:39
  • @Henry that's like saying parsing code for syntax highlighting is a code smell. – pvg May 07 '17 at 12:40
  • I am trying to do some static analysis on the code to identify points of connection to the server. – S. Nabil May 07 '17 at 12:41
  • Sounds like some sort of data flow analysis problem. I am wondering what the underlying problem is that you intend to solve here. – GhostCat May 07 '17 at 12:43
  • `bf2 = new BufferedReader(pickStream())`. Imagine `pickStream` constructs a different kind stream based on user input or phase of moon. Via classloading and reflection, if you want to make it more entertaining. Can you tell what kind of stream you got back from looking at the AST? No. – pvg May 07 '17 at 12:47
  • I want to identify input network data to the server and taint them with a low label. I was counting on JavaParser to help me identify those lines where the input is happening, but I got stuck there. – S. Nabil May 07 '17 at 12:48
  • @pvg guess you are right. – S. Nabil May 07 '17 at 12:50
  • @pvg on a second though, i think my problem is defined and have a smaller scope. This is because I am interested in streams that reads from `Socket` and nothing else. If there is `pickStream` that streams for anything other than a `Socket` I shouldn't care about it. – S. Nabil May 07 '17 at 13:05
  • @Inquirer but how if `pickStream` makes a stream out of a socket or not? Like, say it takes an integer as input and returns a stream made out of a socket if the integer is even and a stream made out of cheese if the integer is odd. You can't tell which one you're getting back from the AST. If you could, we wouldn't need to have runtimes at all. – pvg May 07 '17 at 16:53
  • I am unsure if I understand your question but if you want to look into the semantics of Java code you should look into JavaSymbolSolver which is built to work on top of JavaParser and figure out things like the classes extended or implemented by a given type – Federico Tomassetti May 09 '17 at 18:16

0 Answers0