Skip to content

Commit fcd5325

Browse files
authored
Add files via upload
1 parent 20d1b24 commit fcd5325

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| test.c:4:3:4:9 | call to strncat | if the used buffer is full, writing out of the buffer is possible |
2+
| test.c:11:3:11:9 | call to strncat | if the used buffer is full, writing out of the buffer is possible |
3+
| test.c:19:3:19:9 | call to strncat | if the used buffer is full, writing out of the buffer is possible |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
experimental/Security/CWE/CWE-788/AccessOfMemoryLocationAfterEndOfBufferUsingStrncat.ql
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
void workFunction_0(char *s) {
2+
char buf[80];
3+
strncat(buf, s, sizeof(buf)-strlen(buf)-1); // GOOD
4+
strncat(buf, s, sizeof(buf)-strlen(buf)); // BAD
5+
strncat(buf, "fix", sizeof(buf)-strlen(buf)); // BAD but usually the size of the buffer is calculated manually.
6+
}
7+
void workFunction_1(char *s) {
8+
#define MAX_SIZE 80
9+
char buf[MAX_SIZE];
10+
strncat(buf, s, MAX_SIZE-strlen(buf)-1); // GOOD
11+
strncat(buf, s, MAX_SIZE-strlen(buf)); // BAD
12+
strncat(buf, "fix", MAX_SIZE-strlen(buf)); // BAD but usually the size of the buffer is calculated manually.
13+
}
14+
void workFunction_2_0(char *s) {
15+
char * buf;
16+
int len=80;
17+
buf = (char *) malloc(len);
18+
strncat(buf, s, len-strlen(buf)-1); // GOOD
19+
strncat(buf, s, len-strlen(buf)); // BAD
20+
strncat(buf, "fix", len-strlen(buf)); // BAD but usually the size of the buffer is calculated manually.
21+
}
22+
void workFunction_2_1(char *s) {
23+
char * buf;
24+
int len=80;
25+
buf = (char *) malloc(len+1);
26+
strncat(buf, s, len-strlen(buf)-1); // GOOD
27+
strncat(buf, s, len-strlen(buf)); // GOOD
28+
}

0 commit comments

Comments
 (0)