Skip to content

[Bug] [C] cpg.ifBlock.condition.reachableBy fails to find any nodes when the condition is an identifier #5777

@Miden0

Description

@Miden0

Describe the bug
When trying to find nodes by which an ifBlock condition is reachable, joern will fail to do so if the condition is formed by a single identifier node, in this case I'm trying to find that the condition of the ifBlock, formed only by the variable one_copy, is reachable by the call to givemeone()

To Reproduce

int givemeone(){
    return 1;
}

int main(){
    int one = givemeone();
    int one_copy = one;
    if (one_copy) {
        return 1;
    }
    return 0;
}
// in joern, after importCode():
cpg.ifBlock.condition.reachableBy(cpg.call).l

output:

val res3: List[io.shiftleft.codepropertygraph.generated.nodes.Call] = List()

Expected behavior
I'd expect to see that one_copy is reachable by the givemeone() call.

Desktop (please complete the following information):

  • OS: Arch Linux
  • Joern Version: 4.0.460

Additional context
I've found that reachableBy works correctly when you add almost anything to the condition, the bug only seems to affect the case where an identifier is found alone as the condition.

int givemeone(){
    return 1;
}

int main(){
    int one = givemeone();
    int one_copy = one;
    if (one_copy + 0) {            // <--------- Notice how I've only added '+ 0'
        return 1;
    }
    return 0;
}
// in joern, after importCode():
cpg.ifBlock.condition.reachableBy(cpg.call).l

output:

val res6: List[io.joern.dataflowengineoss.language.Path] = List(
  Path(
    elements = List(
      Call(
        argumentIndex = -1,
        argumentName = None,
        code = "one_copy + 0",
        columnNumber = Some(value = 9),
        dispatchType = "STATIC_DISPATCH",
        dynamicTypeHintFullName = IndexedSeq(),
        lineNumber = Some(value = 8),
        methodFullName = "<operator>.addition",
        name = "<operator>.addition",
        offset = None,
        offsetEnd = None,
        order = 1,
        possibleTypes = IndexedSeq(),
        signature = "",
        staticReceiver = None,
        typeFullName = "ANY"
      )
    )
  ),
  Path(
    elements = List(
      Call(
        argumentIndex = 2,
        argumentName = None,
        code = "givemeone()",
        columnNumber = Some(value = 15),
        dispatchType = "STATIC_DISPATCH",
        dynamicTypeHintFullName = IndexedSeq(),
        lineNumber = Some(value = 6),
        methodFullName = "givemeone",
        name = "givemeone",
        offset = None,
        offsetEnd = None,
        order = 2,
        possibleTypes = IndexedSeq(),
        signature = "",
        staticReceiver = None,
        typeFullName = "int"
      ),
      Identifier(
        argumentIndex = 1,
        argumentName = None,
        code = "one",
        columnNumber = Some(value = 9),
        dynamicTypeHintFullName = IndexedSeq(),
        lineNumber = Some(value = 6),
        name = "one",
        offset = None,
        offsetEnd = None,
        order = 1,
        possibleTypes = IndexedSeq(),
        typeFullName = "int"
      ),
      Identifier(
        argumentIndex = 2,
        argumentName = None,
        code = "one",
        columnNumber = Some(value = 20),
        dynamicTypeHintFullName = IndexedSeq(),
        lineNumber = Some(value = 7),
        name = "one",
        offset = None,
        offsetEnd = None,
        order = 2,
        possibleTypes = IndexedSeq(),
        typeFullName = "int"
      ),
      Identifier(
        argumentIndex = 1,
        argumentName = None,
        code = "one_copy",
        columnNumber = Some(value = 9),
        dynamicTypeHintFullName = IndexedSeq(),
        lineNumber = Some(value = 7),
        name = "one_copy",
        offset = None,
        offsetEnd = None,
        order = 1,
        possibleTypes = IndexedSeq(),
        typeFullName = "int"
      ),
      Call(
        argumentIndex = -1,
        argumentName = None,
        code = "one_copy + 0",
        columnNumber = Some(value = 9),
        dispatchType = "STATIC_DISPATCH",
        dynamicTypeHintFullName = IndexedSeq(),
        lineNumber = Some(value = 8),
        methodFullName = "<operator>.addition",
        name = "<operator>.addition",
        offset = None,
        offsetEnd = None,
        order = 1,
        possibleTypes = IndexedSeq(),
        signature = "",
        staticReceiver = None,
        typeFullName = "ANY"
      )
    )
  )
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions