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

Question about modeling of system api like getpwuid #1610

Open
for-just-we opened this issue Dec 18, 2024 · 3 comments
Open

Question about modeling of system api like getpwuid #1610

for-just-we opened this issue Dec 18, 2024 · 3 comments

Comments

@for-just-we
Copy link

for-just-we commented Dec 18, 2024

I notice in svf-llvm/lib/extapi.c, the api like getpwuid return STATIC_OBJECT. However, the STATIC_OBJECT is defined as malloc(10), which causes many false positive bug report in real-world projects like nginx.

Would it make more sense to define it as alloca(10) or NULL, since alloca and NULL do not need to be freed. Which may not be reasonable but could reduce false reports of heap object. Or consider modeling it to point to a global object.

Here is an example:

#include <pwd.h>
#include <stdio.h>
#include <errno.h>

int main() {
    struct passwd *pw1 = getpwnam("root");
    struct passwd *pw2 = getpwnam("nobody"); // 会覆盖前一次调用的结果

    errno = 1;
    return 0;
}

The bug report is as follows, which seems to be false positives.

	 NeverFree : memory allocation at : ({ "ln": 9, "cl": 5, "fl": "test.c" })
	 NeverFree : memory allocation at : ({ "ln": 6, "cl": 26, "fl": "test.c" })
	 NeverFree : memory allocation at : ({ "ln": 7, "cl": 26, "fl": "test.c" })
@for-just-we for-just-we changed the title Question about system api like getpwuid Question about modeling of system api like getpwuid Dec 18, 2024
@for-just-we
Copy link
Author

Currently, I made a modification that makes STATIC_OBJECT aliased with a global object. I'm not sure whether this is a reasonable modification

char* globalData = "dummy global\n";
#define STATIC_OBJECT globalData

@shuangxiangkan
Copy link
Contributor

We added a new "ALLOC_STACK_RET" annotation in extapi.c (#1616), which allows SVF to allocate a stack object for APIs like getpwuid() based on this annotation.

@yuleisui
Copy link
Collaborator

We added a new "ALLOC_STACK_RET" annotation in extapi.c (#1616), which allows SVF to allocate a stack object for APIs like getpwuid() based on this annotation.

@for-just-we could you try our patch and let us know if it works before we merge it to upstream?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants