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

Skip to content

Commit a1e503f

Browse files
committed
CPP: Add test cases for PotentiallyDangerousFunction.
1 parent 15fa4f8 commit a1e503f

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
| test.c:28:22:28:27 | call to gmtime | Call to gmtime is potentially dangerous |
2-
| test.c:39:2:39:5 | call to gets | gets does not guard against buffer overflow |
3-
| test.c:40:6:40:9 | call to gets | gets does not guard against buffer overflow |
1+
| test.c:31:22:31:27 | call to gmtime | Call to gmtime is potentially dangerous |
2+
| test.c:42:2:42:5 | call to gets | gets does not guard against buffer overflow |
3+
| test.c:43:6:43:9 | call to gets | gets does not guard against buffer overflow |

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ struct tm {
2121

2222
struct tm *gmtime(const time_t *timer);
2323
time_t time(time_t *timer);
24+
struct tm *localtime(const time_t *timer);
25+
char *ctime(const time_t *timer);
26+
char *asctime(const struct tm *timeptr);
2427

2528
// Code under test
2629

@@ -39,3 +42,10 @@ void testGets() {
3942
gets(buf1); // BAD: use of gets
4043
s = gets(buf2); // BAD: use of gets
4144
}
45+
46+
void testTime()
47+
{
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]
51+
}

0 commit comments

Comments
 (0)