Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Javasrc2cpg]When a line of code uses string concatenation, the taint analysis results of this line of code lose some details. #4424

Open
wooyune1 opened this issue Apr 5, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@wooyune1
Copy link

wooyune1 commented Apr 5, 2024

Describe the bug

s =  s.substring(0) + "a";

The above is a line of Java code, which evidently contains two method calls: string concatenation and the substring method.
However, in the paths obtained through taint analysis, there is only a single call recorded.
image
After debugging, it was discovered that the call for string concatenation was retained, while the call to the substring method was not included in the traced path.
I originally thought that Joern wouldn't handle cases where there are multiple function calls in a single line of code, but in reality, Joern is able to handle the following code correctly.

s =  s.substring(0).substring(0); // handled correctly

image
Then I tested the following code and found that Joern still loses some information, so I suspect this might be due to the string concatenation operation.

s =  s + "a" + "b"; // handled incorrectly

To Reproduce
A.java

public class A {
    public static void main(String[] args) {
        String s = source();
        s =  s.substring(0) + "a"; // this line
        sink(s);
    }
    public static String source() {
        return "abc";
    }
    public static String sink(String s) {
        String temp = s;
        return s;
    }
}

TaintAnalysis.scala

    val source = cpg.call.name("source")
    val sink = cpg.call.name("sink")
    val paths = sink.reachableByFlows(source)

Expected behavior
The line of code where the expected comments are added can find two method calls in the taint analysis.

Desktop (please complete the following information):

  • Joern Version : v2.0.311
  • Java version : 17
@wooyune1 wooyune1 added the bug Something isn't working label Apr 5, 2024
@wooyune1 wooyune1 changed the title [Bug]When a line of code uses string concatenation, the taint analysis results of this line of code lose some details. [Javasrc2cpg]When a line of code uses string concatenation, the taint analysis results of this line of code lose some details. Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant