aboutsummaryrefslogtreecommitdiff
path: root/test/Sema/format-strings.c
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-08-10 20:18:51 +0000
committerChris Lattner <sabre@nondot.org>2007-08-10 20:18:51 +0000
commit59907c4d8f6fc8aacfdaa0273bd7a9c140fbb45f (patch)
tree4711e49c7f24d8b8d4a18d0ffa00e0bdc02aa704 /test/Sema/format-strings.c
parentaf6f528b2bd6c3ee517e02d346238addb74159cc (diff)
initial support for checking format strings, patch by Ted Kremenek:
"I've coded up some support in clang to flag warnings for non-constant format strings used in calls to printf-like functions (all the functions listed in "man fprintf"). Non-constant format strings are a source of many security exploits in C/C++ programs, and I believe are currently detected by gcc using the flag -Wformat-nonliteral." git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41003 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Sema/format-strings.c')
-rw-r--r--test/Sema/format-strings.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c
new file mode 100644
index 0000000000..f71cd58645
--- /dev/null
+++ b/test/Sema/format-strings.c
@@ -0,0 +1,23 @@
+// RUN: clang -parse-ast-check %s
+
+#include <stdio.h>
+#include <stdarg.h>
+
+void check_string_literal( FILE* fp, const char* s, char *buf, ... ) {
+
+ char * b;
+ va_list ap;
+ va_start(ap,buf);
+
+ printf(s); // expected-warning {{format string is not a string literal}}
+ vprintf(s,ap); // expected-warning {{format string is not a string liter}}
+ fprintf(fp,s); // expected-warning {{format string is not a string literal}}
+ vfprintf(fp,s,ap); // expected-warning {{format string is not a string lit}}
+ asprintf(&b,s); // expected-warning {{format string is not a string lit}}
+ vasprintf(&b,s,ap); // expected-warning {{format string is not a string lit}}
+ sprintf(buf,s); // expected-warning {{format string is not a string literal}}
+ snprintf(buf,2,s); // expected-warning {{format string is not a string lit}}
+ vsprintf(buf,s,ap); // expected-warning {{format string is not a string lit}}
+ vsnprintf(buf,2,s,ap); // expected-warning {{mat string is not a string lit}}
+}
+