Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a437e6c

Browse files
committed
CPP: Extend coverage.
1 parent a1e503f commit a437e6c

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

cpp/ql/src/Security/CWE/CWE-676/PotentiallyDangerousFunction.ql

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@
1212
import cpp
1313

1414
predicate 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 numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
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 |

cpp/ql/test/query-tests/Security/CWE/CWE-676/semmle/PotentiallyDangerousFunction/test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void testGets() {
4545

4646
void 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
}

0 commit comments

Comments
 (0)