diff options
author | David Carlier <devnexen@gmail.com> | 2018-08-14 05:12:53 +0000 |
---|---|---|
committer | David Carlier <devnexen@gmail.com> | 2018-08-14 05:12:53 +0000 |
commit | 54fc3767fcfd29eadd58ed5c3fad5e18d7724c89 (patch) | |
tree | 24dd9b9dd9c45a44d5c14ae4a64de92fc6a4b319 /clang/test | |
parent | b0a1d3bdf1d0124c555231a518cb6da769cceb05 (diff) | |
download | bcm5719-llvm-54fc3767fcfd29eadd58ed5c3fad5e18d7724c89.tar.gz bcm5719-llvm-54fc3767fcfd29eadd58ed5c3fad5e18d7724c89.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: NoQ, george.karpenkov
Reviewed By: george.karpenkov
Differential Revision: https://reviews.llvm.org/D49722
llvm-svn: 339641
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/Analysis/cstring-syntax.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/clang/test/Analysis/cstring-syntax.c b/clang/test/Analysis/cstring-syntax.c index fe1253bedba..c6d36940605 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]; @@ -33,3 +34,19 @@ void testStrlcpy(const char *src) { strlcpy(dest + 5, src, 5); strlcpy(dest + 5, src, 10); // expected-warning {{The third argument is larger than the size of the input buffer.}} } + +void testStrlcat(const char *src) { + char dest[10]; + size_t badlen = 10; + 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)); // expected-warning {{The third argument allows to potentially copy more bytes than it should. Replace with the value <size> - strlen(dest) - 1 or lower}} + strlcpy(dest, "0123456789", sizeof(dest)); + strlcat(dest, "0123456789", badlen); // expected-warning {{The third argument allows to potentially copy more bytes than it should. Replace with the value 'badlen' - strlen(dest) - 1 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 'badlen' - strlen(<destination buffer>) - 1 or lower}} +} |