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

[Bug][Java] Inconsistent results for arguments resolving of similar calls #4836

Open
michwqy opened this issue Aug 11, 2024 · 0 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@michwqy
Copy link

michwqy commented Aug 11, 2024

Describe the bug
When I used Joern to detect a Java project that used MyBatis-Plus, I found that Joern gave the inconsistent results for arguments resolving of similar calls queryWrapper.apply and updateWrapper.set

To Reproduce
The Java code like

    public Users getUserByName(String name) {
        QueryWrapper<Users> queryWrapper = new QueryWrapper<>();
        queryWrapper.apply("username={0}",name);
        Users user = userService.getOne(queryWrapper);
        return user;
    }

    public Users getUser2(Long id, String username, String password) {
        UpdateWrapper<Users> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set("password", password).apply("username="+username);
        Users user = userService.updateUsers(id, updateWrapper, "users");
        return user;
    }

First, I used cpg.call.methodFullName(".*UpdateWrapper.set.*").argument.l, and Joern returns ( ignore the argument 0 )

  Literal(
    argumentIndex = 1,
    argumentName = None,
    code = "\"password\"",
    columnNumber = None,
    dynamicTypeHintFullName = IndexedSeq(),
    lineNumber = None,
    order = 2,
    possibleTypes = IndexedSeq(),
    typeFullName = "java.lang.String"
  ),
  Identifier(
    argumentIndex = 2,
    argumentName = None,
    code = "password",
    columnNumber = None,
    dynamicTypeHintFullName = IndexedSeq(),
    lineNumber = Some(value = 77),
    name = "password",
    order = 3,
    possibleTypes = IndexedSeq(),
    typeFullName = "java.lang.String"
  )

It shows that joern can correctly resovle one argument as a Literal and the other as an Identifier of String, and the corresponding code is also correct.

But when I used cpg.call.methodFullName(".*QueryWrapper.apply.*").argument.l, I found joern returned the wrong typeFullName and code of the second argument of queryWrapper.apply("username={0}",name)

  Literal(
    argumentIndex = 1,
    argumentName = None,
    code = "\"username={0}\"",
    columnNumber = None,
    dynamicTypeHintFullName = IndexedSeq(),
    lineNumber = None,
    order = 2,
    possibleTypes = IndexedSeq(),
    typeFullName = "java.lang.String"
  ),
  Identifier(
    argumentIndex = 2,
    argumentName = None,
    code = "$stack5",
    columnNumber = None,
    dynamicTypeHintFullName = IndexedSeq(),
    lineNumber = Some(value = 59),
    name = "$stack5",
    order = 3,
    possibleTypes = IndexedSeq(),
    typeFullName = "java.lang.Object[]"
  )

Why joern gave the inconsistent results for arguments resolving of similar calls? How can I get the right typeFullName and code of secong argument of queryWrapper.apply("username={0}",name)

Following is the information of method queryWrapper.apply and updateWrapper.set, I don't know if it helps.

cpg.method.fullName(".*UpdateWrapper.set.*").l

val res10: List[io.shiftleft.codepropertygraph.generated.nodes.Method] = List(
  Method(
    astParentFullName = "<global>",
    astParentType = "NAMESPACE_BLOCK",
    code = "<empty>",
    columnNumber = None,
    columnNumberEnd = None,
    filename = "<empty>",
    fullName = "com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper.set:java.lang.Object(java.lang.Object,java.lang.Object)",
    hash = None,
    isExternal = true,
    lineNumber = None,
    lineNumberEnd = None,
    name = "set",
    offset = None,
    offsetEnd = None,
    order = 0,
    signature = "java.lang.Object(java.lang.Object,java.lang.Object)"
  )
)

cpg.method.fullName(".*QueryWrapper.apply.*").l

val res11: List[io.shiftleft.codepropertygraph.generated.nodes.Method] = List(
  Method(
    astParentFullName = "<global>",
    astParentType = "NAMESPACE_BLOCK",
    code = "<empty>",
    columnNumber = None,
    columnNumberEnd = None,
    filename = "<empty>",
    fullName = "com.baomidou.mybatisplus.core.conditions.query.QueryWrapper.apply:java.lang.Object(java.lang.String,java.lang.Object[])",
    hash = None,
    isExternal = true,
    lineNumber = None,
    lineNumberEnd = None,
    name = "apply",
    offset = None,
    offsetEnd = None,
    order = 0,
    signature = "java.lang.Object(java.lang.String,java.lang.Object[])"
  )
)

Desktop

  • OS: macOS 13
  • Joern Version: 4.0.33
  • Java version: 17.0.11
@michwqy michwqy added the bug Something isn't working label Aug 11, 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

2 participants