summaryrefslogtreecommitdiff
path: root/test/Analysis
diff options
context:
space:
mode:
authorAnna Zaks <ganna@apple.com>2011-12-14 18:34:17 +0000
committerAnna Zaks <ganna@apple.com>2011-12-14 18:34:17 +0000
commit86277c5cd80d4f5911945fa207062aa9a44db8ff (patch)
treef148b133306512c65c863e68f7bc785346a887e2 /test/Analysis
parent0d57ca1449d7a4d7afb927d4c3c1069dc6339372 (diff)
downloadclang-86277c5cd80d4f5911945fa207062aa9a44db8ff.tar.gz
[analyzer] Re-enable the test which was failing on one of the bots.
I cannot reproduce the failures neither on my machine nor on the same buildbot machine (with the clang binary built on it). Let's see if it fails again.. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146574 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Analysis')
-rw-r--r--test/Analysis/taint-tester.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/Analysis/taint-tester.c b/test/Analysis/taint-tester.c
index a769a3d904..2908e60fe8 100644
--- a/test/Analysis/taint-tester.c
+++ b/test/Analysis/taint-tester.c
@@ -76,3 +76,49 @@ void BitwiseOp(int in, char inn) {
m = inn;
int mm = m; // expected-warning {{tainted}}
}
+
+// Test getenv.
+char *getenv(const char *name);
+void getenvTest(char *home) {
+ home = getenv("HOME"); // expected-warning 2 {{tainted}}
+ if (home != 0) { // expected-warning 2 {{tainted}}
+ char d = home[0]; // expected-warning 2 {{tainted}}
+ }
+}
+
+typedef struct _FILE FILE;
+extern FILE *stdin;
+extern FILE *stdout;
+extern FILE *stderr;
+int fscanf(FILE *restrict stream, const char *restrict format, ...);
+int fprintf(FILE *stream, const char *format, ...);
+int fclose(FILE *stream);
+FILE *fopen(const char *path, const char *mode);
+
+int fscanfTest(void) {
+ FILE *fp;
+ char s[80];
+ int t;
+
+ // Check if stdin is treated as tainted.
+ fscanf(stdin, "%s %d", s, &t);
+ // Note, here, s is not tainted, but the data s points to is tainted.
+ char *ts = s;
+ char tss = s[0]; // expected-warning 1 {{tainted}}
+ int tt = t; // expected-warning 1 {{tainted}}
+ if((fp=fopen("test", "w")) == 0) // expected-warning 3 {{tainted}}
+ return 1;
+ fprintf(fp, "%s %d", s, t); // expected-warning 2 {{tainted}}
+ fclose(fp); // expected-warning 1 {{tainted}}
+
+ // Check if we propagate taint from stdin when it's used in an assignment.
+ FILE *pfstd = stdin;
+ fscanf(pfstd, "%s %d", s, &t); // TODO: This should be tainted as well.
+
+ // Test fscanf and fopen.
+ if((fp=fopen("test","r")) == 0) // expected-warning 3 {{tainted}}
+ return 1;
+ fscanf(fp, "%s%d", s, &t); // expected-warning 1 {{tainted}}
+ fprintf(stdout, "%s %d", s, t); // expected-warning 1 {{tainted}}
+ return 0;
+}