Skip to content

[clang][analyzer] Improve modeling of 'execv' and 'execvp' in StdLibraryFunctionsChecker #78930

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

Merged
merged 2 commits into from
Jan 25, 2024
Merged

Conversation

benshi001
Copy link
Member

These functions always return -1 and set 'errno'.

…ryFunctionsChecker

These functions always return -1 and set 'errno'.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:static analyzer labels Jan 22, 2024
@llvmbot
Copy link
Member

llvmbot commented Jan 22, 2024

@llvm/pr-subscribers-clang-static-analyzer-1

@llvm/pr-subscribers-clang

Author: Ben Shi (benshi001)

Changes

These functions always return -1 and set 'errno'.


Full diff: https://github.com/llvm/llvm-project/pull/78930.diff

1 Files Affected:

  • (modified) clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp (+2-2)
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index fcd907a9bb0da0..61bf3c8528be2b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -3002,7 +3002,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
         "execv",
         Signature(ArgTypes{ConstCharPtrTy, CharPtrConstPtr}, RetType{IntTy}),
         Summary(NoEvalCall)
-            .Case(ReturnsMinusOne, ErrnoIrrelevant)
+            .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant)
             .ArgConstraint(NotNull(ArgNo(0))));
 
     // int execvp(const char *file, char *const argv[]);
@@ -3010,7 +3010,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
         "execvp",
         Signature(ArgTypes{ConstCharPtrTy, CharPtrConstPtr}, RetType{IntTy}),
         Summary(NoEvalCall)
-            .Case(ReturnsMinusOne, ErrnoIrrelevant)
+            .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant)
             .ArgConstraint(NotNull(ArgNo(0))));
 
     // int getopt(int argc, char * const argv[], const char *optstring);

@steakhal steakhal changed the title [clang[analyzer] Improve modeling of 'execv' and 'execvp' in StdLibraryFunctionsChecker [clang][analyzer] Improve modeling of 'execv' and 'execvp' in StdLibraryFunctionsChecker Jan 22, 2024
@balazske
Copy link
Collaborator

Test for these functions can be added to file std-c-library-functions-POSIX.c (with check of return value and errno).

@benshi001
Copy link
Member Author

Test for these functions can be added to file std-c-library-functions-POSIX.c (with check of return value and errno).

I will put them into errno-stdlibraryfunctions.c, which seems better.

…ryFunctionsChecker

These functions always return -1 and set 'errno'.
Copy link
Contributor

@steakhal steakhal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@benshi001 benshi001 merged commit b7f986d into llvm:main Jan 25, 2024
@benshi001 benshi001 deleted the csa-exec branch January 25, 2024 01:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:static analyzer clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants