Skip to content

Commit 4e2344c

Browse files
committed
C++: Add test cases for SAXParser.
1 parent dc96d55 commit 4e2344c

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

cpp/ql/test/query-tests/Security/CWE/CWE-611/tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
// ---
66

7-
class SecurityManager;
8-
class InputSource;
7+
8+
99

1010
class AbstractDOMParser {
1111
public:
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
// library functions for rule CWE-611
1+
// library/common functions for rule CWE-611
22

3+
class SecurityManager;
4+
class InputSource;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// test cases for rule CWE-611
2+
3+
#include "tests.h"
4+
5+
// ---
6+
7+
class SAXParser
8+
{
9+
public:
10+
SAXParser();
11+
12+
void setDisableDefaultEntityResolution(bool); // default is false
13+
void setSecurityManager(SecurityManager *const manager);
14+
void parse(const InputSource &data);
15+
};
16+
17+
// ---
18+
19+
void test2_1(InputSource &data) {
20+
SAXParser *p = new SAXParser();
21+
22+
p->parse(data); // BAD (parser not correctly configured) [NOT DETECTED]
23+
}
24+
25+
void test2_2(InputSource &data) {
26+
SAXParser *p = new SAXParser();
27+
28+
p->setDisableDefaultEntityResolution(true);
29+
p->parse(data); // GOOD
30+
}
31+
32+
void test2_3(InputSource &data) {
33+
SAXParser *p = new SAXParser();
34+
bool v = false;
35+
36+
p->setDisableDefaultEntityResolution(v);
37+
p->parse(data); // BAD (parser not correctly configured) [NOT DETECTED]
38+
}
39+
40+
void test2_4(InputSource &data) {
41+
SAXParser *p = new SAXParser();
42+
bool v = true;
43+
44+
p->setDisableDefaultEntityResolution(v);
45+
p->parse(data); // GOOD
46+
}

0 commit comments

Comments
 (0)