1 // RUN: %clang_analyze_cc1 -analyzer-checker=alpha.security.taint,core,alpha.security.ArrayBoundV2 -analyzer-config alpha.security.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config.yaml -Wno-format-security -verify -std=c++11 %s
6 int scanf(const char*, ...);
10 bool isOutOfRange2(const int*);
15 namespace myNamespace
{
16 void scanf(const char*, ...);
17 void myScanf(const char*, ...);
20 bool isOutOfRange(const int*);
21 bool isOutOfRange2(const int*);
23 void mySink(int, int, int);
27 namespace myAnotherNamespace
{
30 bool isOutOfRange2(const int*);
35 void testConfigurationNamespacePropagation1() {
37 // The built-in functions should be matched only for functions in
38 // the global namespace
39 myNamespace::scanf("%d", &x
);
40 Buffer
[x
] = 1; // no-warning
43 Buffer
[x
] = 1; // expected-warning {{Out of bound memory access }}
46 void testConfigurationNamespacePropagation2() {
48 Buffer
[x
] = 1; // no-warning
50 int y
= myNamespace::mySource3();
51 Buffer
[y
] = 1; // expected-warning {{Out of bound memory access }}
54 void testConfigurationNamespacePropagation3() {
55 int x
= myAnotherNamespace::mySource3();
56 Buffer
[x
] = 1; // expected-warning {{Out of bound memory access }}
59 void testConfigurationNamespacePropagation4() {
61 // Configured functions without scope should match for all function.
62 myNamespace::myScanf("%d", &x
);
63 Buffer
[x
] = 1; // expected-warning {{Out of bound memory access }}
66 void testConfigurationNamespaceFilter1() {
68 if (myNamespace::isOutOfRange2(&x
))
70 Buffer
[x
] = 1; // no-warning
73 if (isOutOfRange2(&y
))
75 Buffer
[y
] = 1; // expected-warning {{Out of bound memory access }}
78 void testConfigurationNamespaceFilter2() {
80 if (myAnotherNamespace::isOutOfRange2(&x
))
82 Buffer
[x
] = 1; // no-warning
85 void testConfigurationNamespaceFilter3() {
87 if (myNamespace::isOutOfRange(&x
))
89 Buffer
[x
] = 1; // no-warning
92 void testConfigurationNamespaceSink1() {
94 mySink2(x
); // no-warning
97 myNamespace::mySink2(y
);
98 // expected-warning@-1 {{Untrusted data is passed to a user-defined sink}}
101 void testConfigurationNamespaceSink2() {
103 myAnotherNamespace::mySink2(x
);
104 // expected-warning@-1 {{Untrusted data is passed to a user-defined sink}}
107 void testConfigurationNamespaceSink3() {
109 myNamespace::mySink(x
, 0, 1);
110 // expected-warning@-1 {{Untrusted data is passed to a user-defined sink}}
114 void scanf(const char*, int*);
115 void myMemberScanf(const char*, int*);
118 void testConfigurationMemberFunc() {
122 Buffer
[x
] = 1; // no-warning
124 foo
.myMemberScanf("%d", &x
);
125 Buffer
[x
] = 1; // expected-warning {{Out of bound memory access }}