diff options
author | David Carlier <devnexen@gmail.com> | 2018-09-23 08:30:17 +0000 |
---|---|---|
committer | David Carlier <devnexen@gmail.com> | 2018-09-23 08:30:17 +0000 |
commit | 75cb0dd5ed61a2052875c23a7c1059f08f998ba4 (patch) | |
tree | 57cf86ebfd22992ad00cf3b7f2ac3aabd0f716c1 /clang/test/Analysis/cstring-syntax.c | |
parent | f750f7f3fbb868635c0bb7d250b459acb290b985 (diff) | |
download | bcm5719-llvm-75cb0dd5ed61a2052875c23a7c1059f08f998ba4.tar.gz bcm5719-llvm-75cb0dd5ed61a2052875c23a7c1059f08f998ba4.zip |
[CStringSyntaxChecker] Check strlcat sizeof check
Assuming strlcat is used with strlcpy we check as we can if the last argument does not equal os not larger than the buffer.
Advising the proper usual pattern.
Reviewers: george.karpenkov, NoQ, MaskRay
Reviewed By: MaskRay
Differential Revision: https://reviews.llvm.org/D49722
llvm-svn: 342832
Diffstat (limited to 'clang/test/Analysis/cstring-syntax.c')
-rw-r--r-- | clang/test/Analysis/cstring-syntax.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/clang/test/Analysis/cstring-syntax.c b/clang/test/Analysis/cstring-syntax.c index fe1253bedba..d2e12e8303b 100644 --- a/clang/test/Analysis/cstring-syntax.c +++ b/clang/test/Analysis/cstring-syntax.c @@ -7,6 +7,7 @@ typedef __SIZE_TYPE__ size_t; char *strncat(char *, const char *, size_t); size_t strlen (const char *s); size_t strlcpy(char *, const char *, size_t); +size_t strlcat(char *, const char *, size_t); void testStrncat(const char *src) { char dest[10]; @@ -27,9 +28,27 @@ void testStrlcpy(const char *src) { strlcpy(dest, src, sizeof(dest)); strlcpy(dest, src, destlen); strlcpy(dest, src, 10); - strlcpy(dest, src, 20); // expected-warning {{The third argument is larger than the size of the input buffer. Replace with the value 'sizeof(dest)` or lower}} - strlcpy(dest, src, badlen); // expected-warning {{The third argument is larger than the size of the input buffer. Replace with the value 'sizeof(dest)` or lower}} + strlcpy(dest, src, 20); // expected-warning {{The third argument allows to potentially copy more bytes than it should. Replace with the value sizeof(dest) or lower}} + strlcpy(dest, src, badlen); // expected-warning {{The third argument allows to potentially copy more bytes than it should. Replace with the value sizeof(dest) or lower}} strlcpy(dest, src, ulen); strlcpy(dest + 5, src, 5); - strlcpy(dest + 5, src, 10); // expected-warning {{The third argument is larger than the size of the input buffer.}} + strlcpy(dest + 5, src, 10); // expected-warning {{The third argument allows to potentially copy more bytes than it should. Replace with the value sizeof(<destination buffer>) or lower}} +} + +void testStrlcat(const char *src) { + char dest[10]; + size_t badlen = 20; + size_t ulen; + strlcpy(dest, "aaaaa", sizeof("aaaaa") - 1); + strlcat(dest, "bbbb", (sizeof("bbbb") - 1) - sizeof(dest) - 1); + strlcpy(dest, "012345678", sizeof(dest)); + strlcat(dest, "910", sizeof(dest)); + strlcpy(dest, "0123456789", sizeof(dest)); + strlcpy(dest, "0123456789", sizeof(dest)); + strlcat(dest, "0123456789", badlen / 2); + strlcat(dest, "0123456789", badlen); // expected-warning {{The third argument allows to potentially copy more bytes than it should. Replace with the value sizeof(dest) or lower}} + strlcat(dest, "0123456789", badlen - strlen(dest) - 1); + strlcat(dest, src, ulen); + strlcpy(dest, src, 5); + strlcat(dest + 5, src, badlen); // expected-warning {{The third argument allows to potentially copy more bytes than it should. Replace with the value sizeof(<destination buffer>) or lower}} } |