Skip to content

Commit 2c5f007

Browse files
authored
Merge pull request #16929 from MathiasVP/add-unsafe-strncat-fp
2 parents f87e680 + d5d04f2 commit 2c5f007

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

cpp/ql/test/query-tests/Likely Bugs/Memory Management/SuspiciousCallToStrncat/SuspiciousCallToStrncat.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
| test.c:67:3:67:9 | call to strncat | Potentially unsafe call to strncat. |
44
| test.c:75:3:75:9 | call to strncat | Potentially unsafe call to strncat. |
55
| test.c:76:3:76:9 | call to strncat | Potentially unsafe call to strncat. |
6+
| test.c:91:3:91:9 | call to strncat | Potentially unsafe call to strncat. |
7+
| test.c:99:3:99:9 | call to strncat | Potentially unsafe call to strncat. |

cpp/ql/test/query-tests/Likely Bugs/Memory Management/SuspiciousCallToStrncat/test.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,20 @@ void strncat_test5(char *s) {
8282
strncat(buf, s, len - strlen(buf) - 1); // GOOD
8383
strncat(buf, s, len - strlen(buf)); // GOOD
8484
}
85+
86+
void strncat_test6() {
87+
{
88+
char dest[60];
89+
dest[0] = '\0';
90+
// Will write `dest[0 .. 5]`
91+
strncat(dest, "small", sizeof(dest)); // GOOD [FALSE POSITIVE]
92+
}
93+
94+
{
95+
char dest[60];
96+
memset(dest, 'a', sizeof(dest));
97+
dest[54] = '\0';
98+
// Will write `dest[54 .. 59]`
99+
strncat(dest, "small", sizeof(dest)); // GOOD [FALSE POSITIVE]
100+
}
101+
}

0 commit comments

Comments
 (0)