facebook / infer

A static analyzer for Java, C, C++, and Objective-C
http://fbinfer.com/
MIT License
14.83k stars 2k forks source link

Cannot detect call to function pointer inside a struct #1712

Open JukMR opened 1 year ago

JukMR commented 1 year ago

Please make sure your issue is not addressed in the FAQ.

Please include the following information:

Topl cannot detect the call to a function pointer located in a struct. Here is a simple example:

struct {
    void (*func_to_void)(int arg1);
} *my_struct;

int main()
{
    (my_struct->func_to_void) (1);

    return 0;
}

I am particularly trying to detect the line (my_struct->func_to_void) (1); but without any success.

The property i'm using:

property anyName
    start -> start: *
    start -> error: ".*" (Arg1, VoidRet) when 1 == 1

property pointer
    start -> start: *
    start -> error: "\(->*\)" (Arg1, VoidRet) when 1 == 1

property fullname
    start -> start: *
    start -> error: "(my_struct->func_to_void)" (Arg1, VoidRet) when 1 == 1

property withoutParentesis
    start -> start: *
    start -> error: "my_struct->func_to_void" (Arg1, VoidRet) when 1 == 1

property somethingWithArrows
    start -> start: *
    start -> error: ".*->.*" (Arg1, VoidRet) when 1 == 1

property arrowExpansion
    start -> start: *
    start -> error: "\(\*my_struct\)\.func_to_void" (Arg1, VoidRet) when 1 == 1

I am running topl with:

infer --topl-only --topl-properties simple_prop.topl --function-pointer-specialization -- clang -c -O0 simple_file.c

Output of the command:

infer --topl-only --topl-properties simple_prop.topl --function-pointer-specialization -- clang -c -O0 simple_file.c 
Capturing in make/cc mode...
Found 1 source file to analyze in /home/username/issue/infer-out
1/1 [################################################################################] 100% 46.852ms

  No issues found  

CC: @dgutson

dgutson commented 1 year ago

Ping

rgrig commented 1 year ago

I was alerted about this issue by @hajduakos. I'll look into it this week.

dgutson commented 1 year ago

@rgrig thanks, it's basically when the functions are actually pointers inside a C structures. We couldn't find a way to specify a rule/pattern how to catch them.