-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][analyzer] StreamChecker: Model getc, vfscanf, putc, vfprintf #82476
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
steakhal
merged 11 commits into
llvm:main
from
alejandro-alvarez-sonarsource:aa/streamchecker
Feb 28, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
414fb84
[clang][analyzer] StreamChecker: add more APIs, invalidate fscanf args
alejandro-alvarez-sonarsource 9d8f44d
Reintroduce static, rename escapeArgsAfterIndex
alejandro-alvarez-sonarsource aa34150
Reorder functions
alejandro-alvarez-sonarsource 71a9fe0
Remove redundant invalidation in scanf
alejandro-alvarez-sonarsource 62c315d
vfscanf does not model escaping of parameters
alejandro-alvarez-sonarsource 9b1e3c9
Fix typo in test
alejandro-alvarez-sonarsource 8ccd54e
Remove redundant tests
alejandro-alvarez-sonarsource 6893893
Move invalidation tests to stream-invalidate.c
alejandro-alvarez-sonarsource 14af3ab
Remove test code that does not test for invalidation
alejandro-alvarez-sonarsource c8c9bd3
More precise explanation for test_vfscanf
alejandro-alvarez-sonarsource 2f6c479
Add NULL fd test for vfscanf and vfprintf
alejandro-alvarez-sonarsource File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.Stream,debug.ExprInspection -verify %s | ||
|
||
#include "Inputs/system-header-simulator.h" | ||
#include "Inputs/system-header-simulator-for-valist.h" | ||
|
||
void clang_analyzer_eval(int); | ||
|
||
|
@@ -65,12 +66,24 @@ void check_fseek(void) { | |
fclose(fp); | ||
} | ||
|
||
void check_fseeko(void) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we have these null pointer tests for all functions, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
FILE *fp = tmpfile(); | ||
fseeko(fp, 0, 0); // expected-warning {{Stream pointer might be NULL}} | ||
fclose(fp); | ||
} | ||
|
||
void check_ftell(void) { | ||
FILE *fp = tmpfile(); | ||
ftell(fp); // expected-warning {{Stream pointer might be NULL}} | ||
fclose(fp); | ||
} | ||
|
||
void check_ftello(void) { | ||
FILE *fp = tmpfile(); | ||
ftello(fp); // expected-warning {{Stream pointer might be NULL}} | ||
fclose(fp); | ||
} | ||
|
||
void check_rewind(void) { | ||
FILE *fp = tmpfile(); | ||
rewind(fp); // expected-warning {{Stream pointer might be NULL}} | ||
|
@@ -129,6 +142,18 @@ void f_dopen(int fd) { | |
fclose(F); | ||
} | ||
|
||
void f_vfprintf(int fd, va_list args) { | ||
FILE *F = fdopen(fd, "r"); | ||
vfprintf(F, "%d", args); // expected-warning {{Stream pointer might be NULL}} | ||
fclose(F); | ||
} | ||
|
||
void f_vfscanf(int fd, va_list args) { | ||
FILE *F = fdopen(fd, "r"); | ||
vfscanf(F, "%u", args); // expected-warning {{Stream pointer might be NULL}} | ||
fclose(F); | ||
} | ||
|
||
void f_seek(void) { | ||
FILE *p = fopen("foo", "r"); | ||
if (!p) | ||
|
@@ -138,6 +163,15 @@ void f_seek(void) { | |
fclose(p); | ||
} | ||
|
||
void f_seeko(void) { | ||
FILE *p = fopen("foo", "r"); | ||
if (!p) | ||
return; | ||
fseeko(p, 1, SEEK_SET); // no-warning | ||
fseeko(p, 1, 3); // expected-warning {{The whence argument to fseek() should be SEEK_SET, SEEK_END, or SEEK_CUR}} | ||
fclose(p); | ||
} | ||
|
||
void f_double_close(void) { | ||
FILE *p = fopen("foo", "r"); | ||
if (!p) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change looks not needed.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to modify this line after adding
vfscanf
(and nowvfprintf
) tosystem-header-simulator-for-valist.h
The reason is that they need the
FILE*
typedef and they have to be consistent with the typedef ofsystem-header-simulator.h
since they are used together.But
system-header-simulator-for-valist.h
was already used together withsystem-header-simulator-for-simple-stream.h
insecurity-syntax-checks.m
.So I had to change something to keep them consistent, and
typedef struct _FILE FILE;
seems to be used more commonly over the tests, and less likely to cause conflicts in the future.