1 // RUN: %clang_analyze_cc1 -std=c++11 -Wno-format-security \
2 // RUN: -analyzer-checker=core,optin.taint,alpha.security.ArrayBoundV2,debug.ExprInspection \
3 // RUN: -analyzer-config optin.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config.yaml \
6 template <typename T
> void clang_analyzer_isTainted(T
);
11 int scanf(const char*, ...);
12 template <typename T
= int> T
mySource1();
15 typedef struct _FILE
FILE;
19 int fscanf(FILE *stream
, const char *format
, ...);
21 bool isOutOfRange2(const int*);
26 namespace myNamespace
{
27 void scanf(const char*, ...);
28 void myScanf(const char*, ...);
31 bool isOutOfRange(const int*);
32 bool isOutOfRange2(const int*);
34 void mySink(int, int, int);
38 namespace myAnotherNamespace
{
41 bool isOutOfRange2(const int*);
46 void testConfigurationNamespacePropagation1() {
48 // The built-in functions should be matched only for functions in
49 // the global namespace
50 myNamespace::scanf("%d", &x
);
51 Buffer
[x
] = 1; // no-warning
54 Buffer
[x
] = 1; // expected-warning {{Potential out of bound access }}
57 void testConfigurationNamespacePropagation2() {
59 Buffer
[x
] = 1; // no-warning
61 int y
= myNamespace::mySource3();
62 Buffer
[y
] = 1; // expected-warning {{Potential out of bound access }}
65 void testConfigurationNamespacePropagation3() {
66 int x
= myAnotherNamespace::mySource3();
67 Buffer
[x
] = 1; // expected-warning {{Potential out of bound access }}
70 void testConfigurationNamespacePropagation4() {
72 // Configured functions without scope should match for all function.
73 myNamespace::myScanf("%d", &x
);
74 Buffer
[x
] = 1; // expected-warning {{Potential out of bound access }}
77 void testConfigurationNamespaceFilter1() {
79 if (myNamespace::isOutOfRange2(&x
))
81 Buffer
[x
] = 1; // no-warning
84 if (isOutOfRange2(&y
))
86 Buffer
[y
] = 1; // expected-warning {{Potential out of bound access }}
89 void testConfigurationNamespaceFilter2() {
91 if (myAnotherNamespace::isOutOfRange2(&x
))
93 Buffer
[x
] = 1; // no-warning
96 void testConfigurationNamespaceFilter3() {
98 if (myNamespace::isOutOfRange(&x
))
100 Buffer
[x
] = 1; // no-warning
103 void testConfigurationNamespaceSink1() {
105 mySink2(x
); // no-warning
108 myNamespace::mySink2(y
);
109 // expected-warning@-1 {{Untrusted data is passed to a user-defined sink}}
112 void testConfigurationNamespaceSink2() {
114 myAnotherNamespace::mySink2(x
);
115 // expected-warning@-1 {{Untrusted data is passed to a user-defined sink}}
118 void testConfigurationNamespaceSink3() {
120 myNamespace::mySink(x
, 0, 1);
121 // expected-warning@-1 {{Untrusted data is passed to a user-defined sink}}
125 void scanf(const char*, int*);
126 void myMemberScanf(const char*, int*);
129 void testConfigurationMemberFunc() {
133 Buffer
[x
] = 1; // no-warning
135 foo
.myMemberScanf("%d", &x
);
136 Buffer
[x
] = 1; // expected-warning {{Potential out of bound access }}
139 void testReadingFromStdin(char **p
) {
141 fscanf(stdin
, "%d", &n
);
142 Buffer
[n
] = 1; // expected-warning {{Potential out of bound access }}
153 int Int
= mySource1
<int>();
154 clang_analyzer_isTainted(Int
); // expected-warning {{YES}}
156 Empty E
= mySource1
<Empty
>();
157 clang_analyzer_isTainted(E
); // expected-warning {{YES}}
159 Aggr A
= mySource1
<Aggr
>();
160 clang_analyzer_isTainted(A
); // expected-warning {{YES}}
161 clang_analyzer_isTainted(A
.data
); // expected-warning {{YES}}
163 } // namespace gh114270