diff options
| author | Fariborz Jahanian <fjahanian@apple.com> | 2014-09-18 17:58:27 +0000 |
|---|---|---|
| committer | Fariborz Jahanian <fjahanian@apple.com> | 2014-09-18 17:58:27 +0000 |
| commit | 3e6a0be4c4531d97134daea5bd32c5564e3d34f5 (patch) | |
| tree | 4aebd6f3e972295c7c35cee5fe687efb9a78e7fa /clang/test/Sema | |
| parent | 0bb041b5f405f1e2fba5bff66357f709221499a4 (diff) | |
| download | bcm5719-llvm-3e6a0be4c4531d97134daea5bd32c5564e3d34f5.tar.gz bcm5719-llvm-3e6a0be4c4531d97134daea5bd32c5564e3d34f5.zip | |
Patch to check at compile time for overflow when
__builtin___memcpy_chk and similar builtins are
being used. Patch by Jacques Fortier (with added
clang tests). rdar://11076881
llvm-svn: 218063
Diffstat (limited to 'clang/test/Sema')
| -rw-r--r-- | clang/test/Sema/builtin-object-size.c | 2 | ||||
| -rw-r--r-- | clang/test/Sema/builtins.c | 25 |
2 files changed, 24 insertions, 3 deletions
diff --git a/clang/test/Sema/builtin-object-size.c b/clang/test/Sema/builtin-object-size.c index 0abc27ba187..db4832e347a 100644 --- a/clang/test/Sema/builtin-object-size.c +++ b/clang/test/Sema/builtin-object-size.c @@ -23,6 +23,6 @@ int f3() { // rdar://6252231 - cannot call vsnprintf with va_list on x86_64 void f4(const char *fmt, ...) { __builtin_va_list args; - __builtin___vsnprintf_chk (0, 42, 0, 11, fmt, args); + __builtin___vsnprintf_chk (0, 42, 0, 11, fmt, args); // expected-warning {{'__builtin___vsnprintf_chk' will always overflow destination buffer}} } diff --git a/clang/test/Sema/builtins.c b/clang/test/Sema/builtins.c index 8e3a60ab067..f8df2f85cf6 100644 --- a/clang/test/Sema/builtins.c +++ b/clang/test/Sema/builtins.c @@ -215,10 +215,31 @@ void Test19(void) strlcpy(buf, b, sizeof(b)); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}} \\ // expected-note {{change size argument to be the size of the destination}} __builtin___strlcpy_chk(buf, b, sizeof(b), __builtin_object_size(buf, 0)); // expected-warning {{size argument in '__builtin___strlcpy_chk' call appears to be size of the source; expected the size of the destination}} \ - // expected-note {{change size argument to be the size of the destination}} + // expected-note {{change size argument to be the size of the destination}} \ + // expected-warning {{'__builtin___strlcpy_chk' will always overflow destination buffer}} strlcat(buf, b, sizeof(b)); // expected-warning {{size argument in 'strlcat' call appears to be size of the source; expected the size of the destination}} \ // expected-note {{change size argument to be the size of the destination}} + __builtin___strlcat_chk(buf, b, sizeof(b), __builtin_object_size(buf, 0)); // expected-warning {{size argument in '__builtin___strlcat_chk' call appears to be size of the source; expected the size of the destination}} \ - // expected-note {{change size argument to be the size of the destination}} + // expected-note {{change size argument to be the size of the destination}} \ + // expected-warning {{'__builtin___strlcat_chk' will always overflow destination buffer}} +} + +// rdar://11076881 +char * Test20(char *p, const char *in, unsigned n) +{ + static char buf[10]; + + __builtin___memcpy_chk (&buf[6], in, 5, __builtin_object_size (&buf[6], 0)); // expected-warning {{'__builtin___memcpy_chk' will always overflow destination buffer}} + + __builtin___memcpy_chk (p, "abcde", n, __builtin_object_size (p, 0)); + + __builtin___memcpy_chk (&buf[5], "abcde", 5, __builtin_object_size (&buf[5], 0)); + + __builtin___memcpy_chk (&buf[5], "abcde", n, __builtin_object_size (&buf[5], 0)); + + __builtin___memcpy_chk (&buf[6], "abcde", 5, __builtin_object_size (&buf[6], 0)); // expected-warning {{'__builtin___memcpy_chk' will always overflow destination buffer}} + + return buf; } |

