-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[analyzer] Fix crash when modelling 'getline' function in checkers #145229
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ba9f1ed
[clang][analyzer] fix crash when modelling 'getline' function in chec…
vbvictor f871058
fix pr comments
vbvictor 4bda059
add 'const' where appropriate
vbvictor b55d517
fix pr comments from steakhal
vbvictor f6c8601
improve release notes
vbvictor ac2da96
change name 'getdelim' to 'GetDelimOrGetLine'
vbvictor 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
127 changes: 127 additions & 0 deletions
127
clang/test/Analysis/getline-unixapi-invalid-signatures.c
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 |
---|---|---|
@@ -0,0 +1,127 @@ | ||
// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix -verify %s -DTEST_CORRECT | ||
// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix -verify %s -DTEST_GETLINE_1 | ||
// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix -verify %s -DTEST_GETLINE_2 | ||
// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix -verify %s -DTEST_GETLINE_3 | ||
// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix -verify %s -DTEST_GETLINE_4 | ||
// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix -verify %s -DTEST_GETLINE_5 | ||
// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix -verify %s -DTEST_GETLINE_GH144884 | ||
necto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// emulator of "system-header-simulator.h" because of redefinition of 'getline' function | ||
typedef struct _FILE FILE; | ||
typedef __typeof(sizeof(int)) size_t; | ||
typedef long ssize_t; | ||
#define NULL 0 | ||
|
||
int fclose(FILE *fp); | ||
FILE *tmpfile(void); | ||
|
||
#ifdef TEST_CORRECT | ||
ssize_t getline(char **lineptr, size_t *n, FILE *stream); | ||
ssize_t getdelim(char **lineptr, size_t *n, int delimiter, FILE *stream); | ||
|
||
void test_correct() { | ||
FILE *F1 = tmpfile(); | ||
if (!F1) | ||
return; | ||
char *buffer = NULL; | ||
getline(&buffer, NULL, F1); // expected-warning {{Size pointer might be NULL}} | ||
fclose(F1); | ||
} | ||
|
||
void test_delim_correct() { | ||
FILE *F1 = tmpfile(); | ||
if (!F1) | ||
return; | ||
char *buffer = NULL; | ||
getdelim(&buffer, NULL, ',', F1); // expected-warning {{Size pointer might be NULL}} | ||
fclose(F1); | ||
} | ||
#endif | ||
|
||
#ifdef TEST_GETLINE_1 | ||
// expected-no-diagnostics | ||
ssize_t getline(int lineptr); | ||
|
||
void test() { | ||
FILE *F1 = tmpfile(); | ||
if (!F1) | ||
return; | ||
int buffer = 0; | ||
getline(buffer); | ||
fclose(F1); | ||
} | ||
#endif | ||
|
||
#ifdef TEST_GETLINE_2 | ||
ssize_t getline(char **lineptr, size_t *n); | ||
|
||
void test() { | ||
FILE *F1 = tmpfile(); | ||
if (!F1) | ||
return; | ||
char *buffer = NULL; | ||
getline(&buffer, NULL); // expected-warning {{Size pointer might be NULL}} | ||
fclose(F1); | ||
} | ||
#endif | ||
|
||
#ifdef TEST_GETLINE_3 | ||
// expected-no-diagnostics | ||
ssize_t getline(char **lineptr, size_t n, FILE *stream); | ||
|
||
void test() { | ||
FILE *F1 = tmpfile(); | ||
if (!F1) | ||
return; | ||
char *buffer = NULL; | ||
getline(&buffer, 0, F1); | ||
fclose(F1); | ||
} | ||
#endif | ||
|
||
#ifdef TEST_GETLINE_4 | ||
ssize_t getline(char **lineptr, size_t *n, int stream); | ||
ssize_t getdelim(char **lineptr, size_t *n, int delimiter, int stream); | ||
|
||
void test() { | ||
FILE *F1 = tmpfile(); | ||
if (!F1) | ||
return; | ||
char *buffer = NULL; | ||
getline(&buffer, NULL, 1); // expected-warning {{Size pointer might be NULL}} | ||
fclose(F1); | ||
} | ||
|
||
void test_delim() { | ||
FILE *F1 = tmpfile(); | ||
if (!F1) | ||
return; | ||
char *buffer = NULL; | ||
getdelim(&buffer, NULL, ',', 1); // expected-warning {{Size pointer might be NULL}} | ||
fclose(F1); | ||
} | ||
#endif | ||
|
||
#ifdef TEST_GETLINE_5 | ||
ssize_t getdelim(char **lineptr, size_t *n, const char* delimiter, FILE *stream); | ||
|
||
void test_delim() { | ||
FILE *F1 = tmpfile(); | ||
if (!F1) | ||
return; | ||
char *buffer = NULL; | ||
getdelim(&buffer, NULL, ",", F1); // expected-warning {{Size pointer might be NULL}} | ||
fclose(F1); | ||
} | ||
#endif | ||
|
||
#ifdef TEST_GETLINE_GH144884 | ||
// expected-no-diagnostics | ||
struct AW_string {}; | ||
void getline(int *, struct AW_string); | ||
void top() { | ||
struct AW_string line; | ||
int getline_file_info; | ||
getline(&getline_file_info, line); | ||
} | ||
#endif |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.