-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[clang][analyzer] Add checker 'security.SetgidSetuidOrder' #91445
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d839faf
[clang][analyzer] Add checker 'Security.SetgidSetuidOrder'.
balazske 996c22c
Update checker file header comment
balazske 50d996a
improved CallDescription usage, updated message
balazske 49b3fe9
added missing 'CDM::CLibrary'
balazske be329ce
more review related fixes
balazske ae31b7b
updates according to new review
balazske 5f97049
adding NoteTag support
balazske 1493978
added test file, removed getBT
balazske 96b340a
improved repeated test comments
balazske 704cba8
Update checkers.rst
balazske 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 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 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,75 @@ | ||
// RUN: %clang_analyze_cc1 -analyzer-checker=core,security.SetgidSetuidOrder -analyzer-output=text -verify %s | ||
|
||
typedef int uid_t; | ||
typedef int gid_t; | ||
|
||
int setuid(uid_t); | ||
int setgid(gid_t); | ||
|
||
uid_t getuid(); | ||
gid_t getgid(); | ||
|
||
|
||
|
||
void test_note_1() { | ||
if (setuid(getuid()) == -1) // expected-note{{Assuming the condition is false}} \ | ||
// expected-note{{Taking false branch}} | ||
return; | ||
if (setuid(getuid()) == -1) // expected-note{{Call to 'setuid' found here that removes superuser privileges}} \ | ||
// expected-note{{Assuming the condition is false}} \ | ||
// expected-note{{Taking false branch}} | ||
return; | ||
if (setgid(getgid()) == -1) // expected-warning{{A 'setgid(getgid())' call following a 'setuid(getuid())' call is likely to fail}} \ | ||
// expected-note{{A 'setgid(getgid())' call following a 'setuid(getuid())' call is likely to fail}} | ||
return; | ||
} | ||
|
||
void test_note_2() { | ||
if (setuid(getuid()) == -1) // expected-note{{Call to 'setuid' found here that removes superuser privileges}} \ | ||
// expected-note{{Assuming the condition is false}} \ | ||
// expected-note{{Taking false branch}} \ | ||
// expected-note{{Assuming the condition is false}} \ | ||
// expected-note{{Taking false branch}} | ||
return; | ||
if (setgid(getgid()) == -1) // expected-warning{{A 'setgid(getgid())' call following a 'setuid(getuid())' call is likely to fail}} \ | ||
// expected-note{{A 'setgid(getgid())' call following a 'setuid(getuid())' call is likely to fail}} \ | ||
// expected-note{{Assuming the condition is false}} \ | ||
// expected-note{{Taking false branch}} | ||
return; | ||
if (setuid(getuid()) == -1) // expected-note{{Call to 'setuid' found here that removes superuser privileges}} \ | ||
// expected-note{{Assuming the condition is false}} \ | ||
// expected-note{{Taking false branch}} | ||
return; | ||
if (setgid(getgid()) == -1) // expected-warning{{A 'setgid(getgid())' call following a 'setuid(getuid())' call is likely to fail}} \ | ||
// expected-note{{A 'setgid(getgid())' call following a 'setuid(getuid())' call is likely to fail}} | ||
return; | ||
} | ||
|
||
int f_setuid() { | ||
return setuid(getuid()); // expected-note{{Call to 'setuid' found here that removes superuser privileges}} | ||
} | ||
|
||
int f_setgid() { | ||
return setgid(getgid()); // expected-warning{{A 'setgid(getgid())' call following a 'setuid(getuid())' call is likely to fail}} \ | ||
// expected-note{{A 'setgid(getgid())' call following a 'setuid(getuid())' call is likely to fail}} | ||
} | ||
|
||
void test_note_3() { | ||
if (f_setuid() == -1) // expected-note{{Assuming the condition is false}} \ | ||
// expected-note{{Calling 'f_setuid'}} \ | ||
// expected-note{{Returning from 'f_setuid'}} \ | ||
// expected-note{{Taking false branch}} | ||
return; | ||
if (f_setgid() == -1) // expected-note{{Calling 'f_setgid'}} | ||
return; | ||
} | ||
|
||
void test_note_4() { | ||
if (setuid(getuid()) == 0) { // expected-note{{Assuming the condition is true}} \ | ||
// expected-note{{Call to 'setuid' found here that removes superuser privileges}} \ | ||
// expected-note{{Taking true branch}} | ||
if (setgid(getgid()) == 0) { // expected-warning{{A 'setgid(getgid())' call following a 'setuid(getuid())' call is likely to fail}} \ | ||
// expected-note{{A 'setgid(getgid())' call following a 'setuid(getuid())' call is likely to fail}} | ||
} | ||
} | ||
} |
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.
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.