Skip to content

[Bug][C] Dataflow issue for struct member assignments #5668

@van-dalf

Description

@van-dalf

Describe the bug
Dataflow is not detected correctly when a struct member assignment is performed on a struct pointer and the access is performed on the struct directly

To Reproduce

#include <stdio.h>

struct numbers {
    int number_1;
    int number_2;
};

int main(int argc, char **argv) {
    struct numbers nums = {};    
    int one = 1;
    nums.number_1 = one;
    printf("%d", nums.number_1);

    int two = 2;
    struct numbers *nums_p = &nums;
    nums_p->number_2 = two;
    printf("%d", nums.number_2);
}

Import above code and run the queries

cpg.call("printf").reachableByFlows(cpg.identifier("one")).p //finds flow
cpg.call("printf").reachableByFlows(cpg.identifier("two")).p //empty

Only the flow to the first printf-call is detected

Expected behavior
Flows to both printf calls are detected

Desktop (please complete the following information):

  • Joern Version 4.0.302

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