File tree Expand file tree Collapse file tree
test/query-tests/Security/CWE/CWE-676/semmle/PotentiallyDangerousFunction Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212import cpp
1313
1414predicate potentiallyDangerousFunction ( Function f , string message ) {
15- (
16- f .getQualifiedName ( ) = "gmtime" and
17- message = "Call to gmtime is potentially dangerous"
15+ exists ( string name | name = f .getQualifiedName ( ) |
16+ (
17+ name = "gmtime" or
18+ name = "localtime" or
19+ name = "ctime" or
20+ name = "asctime"
21+ ) and
22+ message = "Call to " + name + " is potentially dangerous"
1823 ) or (
1924 f .getQualifiedName ( ) = "gets" and
2025 message = "gets does not guard against buffer overflow"
Original file line number Diff line number Diff line change 11| test.c:31:22:31:27 | call to gmtime | Call to gmtime is potentially dangerous |
22| test.c:42:2:42:5 | call to gets | gets does not guard against buffer overflow |
33| test.c:43:6:43:9 | call to gets | gets does not guard against buffer overflow |
4+ | test.c:48:19:48:27 | call to localtime | Call to localtime is potentially dangerous |
5+ | test.c:49:22:49:26 | call to ctime | Call to ctime is potentially dangerous |
6+ | test.c:50:23:50:29 | call to asctime | Call to asctime is potentially dangerous |
Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ void testGets() {
4545
4646void testTime ()
4747{
48- struct tm * now = localtime (time (NULL )); // BAD: localtime uses shared state [NOT DETECTED]
49- char * time_string = ctime (time (NULL )); // BAD: localtime uses shared state [NOT DETECTED]
50- char * time_string2 = asctime (now ); // BAD: localtime uses shared state [NOT DETECTED]
48+ struct tm * now = localtime (time (NULL )); // BAD: localtime uses shared state
49+ char * time_string = ctime (time (NULL )); // BAD: localtime uses shared state
50+ char * time_string2 = asctime (now ); // BAD: localtime uses shared state
5151}
You can’t perform that action at this time.
0 commit comments