Skip to content

Commit 6f9752e

Browse files
authored
Merge pull request #9019 from geoffw0/xxe4
C++: More XXE Tests
2 parents 0c71849 + 5aa862a commit 6f9752e

File tree

6 files changed

+224
-115
lines changed

6 files changed

+224
-115
lines changed
Lines changed: 67 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
11
edges
22
| tests2.cpp:20:17:20:31 | SAXParser output argument | tests2.cpp:22:2:22:2 | p |
33
| tests2.cpp:33:17:33:31 | SAXParser output argument | tests2.cpp:37:2:37:2 | p |
4-
| tests.cpp:33:23:33:43 | XercesDOMParser output argument | tests.cpp:35:2:35:2 | p |
5-
| tests.cpp:46:23:46:43 | XercesDOMParser output argument | tests.cpp:49:2:49:2 | p |
6-
| tests.cpp:53:19:53:19 | VariableAddress [post update] | tests.cpp:55:2:55:2 | p |
7-
| tests.cpp:53:23:53:43 | XercesDOMParser output argument | tests.cpp:53:19:53:19 | VariableAddress [post update] |
4+
| tests.cpp:15:23:15:43 | XercesDOMParser output argument | tests.cpp:17:2:17:2 | p |
5+
| tests.cpp:28:23:28:43 | XercesDOMParser output argument | tests.cpp:31:2:31:2 | p |
6+
| tests.cpp:35:19:35:19 | VariableAddress [post update] | tests.cpp:37:2:37:2 | p |
7+
| tests.cpp:35:23:35:43 | XercesDOMParser output argument | tests.cpp:35:19:35:19 | VariableAddress [post update] |
8+
| tests.cpp:37:2:37:2 | p | tests.cpp:38:2:38:2 | p |
9+
| tests.cpp:38:2:38:2 | p | tests.cpp:39:2:39:2 | p |
10+
| tests.cpp:51:19:51:19 | VariableAddress [post update] | tests.cpp:53:2:53:2 | p |
11+
| tests.cpp:51:23:51:43 | XercesDOMParser output argument | tests.cpp:51:19:51:19 | VariableAddress [post update] |
12+
| tests.cpp:53:2:53:2 | p | tests.cpp:54:2:54:2 | p |
13+
| tests.cpp:54:2:54:2 | p | tests.cpp:55:2:55:2 | p |
14+
| tests.cpp:55:2:55:2 | p | tests.cpp:56:2:56:2 | p |
815
| tests.cpp:55:2:55:2 | p | tests.cpp:56:2:56:2 | p |
916
| tests.cpp:56:2:56:2 | p | tests.cpp:57:2:57:2 | p |
10-
| tests.cpp:69:19:69:19 | VariableAddress [post update] | tests.cpp:71:2:71:2 | p |
11-
| tests.cpp:69:23:69:43 | XercesDOMParser output argument | tests.cpp:69:19:69:19 | VariableAddress [post update] |
12-
| tests.cpp:71:2:71:2 | p | tests.cpp:72:2:72:2 | p |
13-
| tests.cpp:72:2:72:2 | p | tests.cpp:73:2:73:2 | p |
14-
| tests.cpp:73:2:73:2 | p | tests.cpp:74:2:74:2 | p |
15-
| tests.cpp:73:2:73:2 | p | tests.cpp:74:2:74:2 | p |
16-
| tests.cpp:74:2:74:2 | p | tests.cpp:75:2:75:2 | p |
17-
| tests.cpp:75:2:75:2 | p | tests.cpp:76:2:76:2 | p |
18-
| tests.cpp:76:2:76:2 | p | tests.cpp:77:2:77:2 | p |
19-
| tests.cpp:77:2:77:2 | p | tests.cpp:78:2:78:2 | p |
20-
| tests.cpp:84:23:84:43 | XercesDOMParser output argument | tests.cpp:87:2:87:2 | p |
21-
| tests.cpp:91:23:91:43 | XercesDOMParser output argument | tests.cpp:98:2:98:2 | p |
22-
| tests.cpp:103:24:103:44 | XercesDOMParser output argument | tests.cpp:106:3:106:3 | q |
23-
| tests.cpp:118:24:118:44 | XercesDOMParser output argument | tests.cpp:122:3:122:3 | q |
24-
| tests.cpp:130:39:130:39 | p | tests.cpp:131:2:131:2 | p |
25-
| tests.cpp:134:39:134:39 | p | tests.cpp:135:2:135:2 | p |
26-
| tests.cpp:140:23:140:43 | XercesDOMParser output argument | tests.cpp:144:18:144:18 | q |
27-
| tests.cpp:140:23:140:43 | XercesDOMParser output argument | tests.cpp:146:18:146:18 | q |
28-
| tests.cpp:144:18:144:18 | q | tests.cpp:130:39:130:39 | p |
29-
| tests.cpp:146:18:146:18 | q | tests.cpp:134:39:134:39 | p |
30-
| tests.cpp:150:19:150:32 | call to createLSParser | tests.cpp:152:2:152:2 | p |
17+
| tests.cpp:57:2:57:2 | p | tests.cpp:58:2:58:2 | p |
18+
| tests.cpp:58:2:58:2 | p | tests.cpp:59:2:59:2 | p |
19+
| tests.cpp:59:2:59:2 | p | tests.cpp:60:2:60:2 | p |
20+
| tests.cpp:66:23:66:43 | XercesDOMParser output argument | tests.cpp:69:2:69:2 | p |
21+
| tests.cpp:73:23:73:43 | XercesDOMParser output argument | tests.cpp:80:2:80:2 | p |
22+
| tests.cpp:85:24:85:44 | XercesDOMParser output argument | tests.cpp:88:3:88:3 | q |
23+
| tests.cpp:100:24:100:44 | XercesDOMParser output argument | tests.cpp:104:3:104:3 | q |
24+
| tests.cpp:112:39:112:39 | p | tests.cpp:113:2:113:2 | p |
25+
| tests.cpp:116:39:116:39 | p | tests.cpp:117:2:117:2 | p |
26+
| tests.cpp:122:23:122:43 | XercesDOMParser output argument | tests.cpp:126:18:126:18 | q |
27+
| tests.cpp:122:23:122:43 | XercesDOMParser output argument | tests.cpp:128:18:128:18 | q |
28+
| tests.cpp:126:18:126:18 | q | tests.cpp:112:39:112:39 | p |
29+
| tests.cpp:128:18:128:18 | q | tests.cpp:116:39:116:39 | p |
3130
nodes
3231
| tests2.cpp:20:17:20:31 | SAXParser output argument | semmle.label | SAXParser output argument |
3332
| tests2.cpp:22:2:22:2 | p | semmle.label | p |
@@ -38,43 +37,41 @@ nodes
3837
| tests4.cpp:46:34:46:68 | ... \| ... | semmle.label | ... \| ... |
3938
| tests4.cpp:77:34:77:38 | flags | semmle.label | flags |
4039
| tests4.cpp:130:39:130:55 | (int)... | semmle.label | (int)... |
41-
| tests.cpp:33:23:33:43 | XercesDOMParser output argument | semmle.label | XercesDOMParser output argument |
42-
| tests.cpp:35:2:35:2 | p | semmle.label | p |
43-
| tests.cpp:46:23:46:43 | XercesDOMParser output argument | semmle.label | XercesDOMParser output argument |
44-
| tests.cpp:49:2:49:2 | p | semmle.label | p |
45-
| tests.cpp:53:19:53:19 | VariableAddress [post update] | semmle.label | VariableAddress [post update] |
46-
| tests.cpp:53:23:53:43 | XercesDOMParser output argument | semmle.label | XercesDOMParser output argument |
40+
| tests.cpp:15:23:15:43 | XercesDOMParser output argument | semmle.label | XercesDOMParser output argument |
41+
| tests.cpp:17:2:17:2 | p | semmle.label | p |
42+
| tests.cpp:28:23:28:43 | XercesDOMParser output argument | semmle.label | XercesDOMParser output argument |
43+
| tests.cpp:31:2:31:2 | p | semmle.label | p |
44+
| tests.cpp:35:19:35:19 | VariableAddress [post update] | semmle.label | VariableAddress [post update] |
45+
| tests.cpp:35:23:35:43 | XercesDOMParser output argument | semmle.label | XercesDOMParser output argument |
46+
| tests.cpp:37:2:37:2 | p | semmle.label | p |
47+
| tests.cpp:38:2:38:2 | p | semmle.label | p |
48+
| tests.cpp:39:2:39:2 | p | semmle.label | p |
49+
| tests.cpp:51:19:51:19 | VariableAddress [post update] | semmle.label | VariableAddress [post update] |
50+
| tests.cpp:51:23:51:43 | XercesDOMParser output argument | semmle.label | XercesDOMParser output argument |
51+
| tests.cpp:53:2:53:2 | p | semmle.label | p |
52+
| tests.cpp:54:2:54:2 | p | semmle.label | p |
4753
| tests.cpp:55:2:55:2 | p | semmle.label | p |
4854
| tests.cpp:56:2:56:2 | p | semmle.label | p |
55+
| tests.cpp:56:2:56:2 | p | semmle.label | p |
4956
| tests.cpp:57:2:57:2 | p | semmle.label | p |
50-
| tests.cpp:69:19:69:19 | VariableAddress [post update] | semmle.label | VariableAddress [post update] |
51-
| tests.cpp:69:23:69:43 | XercesDOMParser output argument | semmle.label | XercesDOMParser output argument |
52-
| tests.cpp:71:2:71:2 | p | semmle.label | p |
53-
| tests.cpp:72:2:72:2 | p | semmle.label | p |
54-
| tests.cpp:73:2:73:2 | p | semmle.label | p |
55-
| tests.cpp:74:2:74:2 | p | semmle.label | p |
56-
| tests.cpp:74:2:74:2 | p | semmle.label | p |
57-
| tests.cpp:75:2:75:2 | p | semmle.label | p |
58-
| tests.cpp:76:2:76:2 | p | semmle.label | p |
59-
| tests.cpp:77:2:77:2 | p | semmle.label | p |
60-
| tests.cpp:78:2:78:2 | p | semmle.label | p |
61-
| tests.cpp:84:23:84:43 | XercesDOMParser output argument | semmle.label | XercesDOMParser output argument |
62-
| tests.cpp:87:2:87:2 | p | semmle.label | p |
63-
| tests.cpp:91:23:91:43 | XercesDOMParser output argument | semmle.label | XercesDOMParser output argument |
64-
| tests.cpp:98:2:98:2 | p | semmle.label | p |
65-
| tests.cpp:103:24:103:44 | XercesDOMParser output argument | semmle.label | XercesDOMParser output argument |
66-
| tests.cpp:106:3:106:3 | q | semmle.label | q |
67-
| tests.cpp:118:24:118:44 | XercesDOMParser output argument | semmle.label | XercesDOMParser output argument |
68-
| tests.cpp:122:3:122:3 | q | semmle.label | q |
69-
| tests.cpp:130:39:130:39 | p | semmle.label | p |
70-
| tests.cpp:131:2:131:2 | p | semmle.label | p |
71-
| tests.cpp:134:39:134:39 | p | semmle.label | p |
72-
| tests.cpp:135:2:135:2 | p | semmle.label | p |
73-
| tests.cpp:140:23:140:43 | XercesDOMParser output argument | semmle.label | XercesDOMParser output argument |
74-
| tests.cpp:144:18:144:18 | q | semmle.label | q |
75-
| tests.cpp:146:18:146:18 | q | semmle.label | q |
76-
| tests.cpp:150:19:150:32 | call to createLSParser | semmle.label | call to createLSParser |
77-
| tests.cpp:152:2:152:2 | p | semmle.label | p |
57+
| tests.cpp:58:2:58:2 | p | semmle.label | p |
58+
| tests.cpp:59:2:59:2 | p | semmle.label | p |
59+
| tests.cpp:60:2:60:2 | p | semmle.label | p |
60+
| tests.cpp:66:23:66:43 | XercesDOMParser output argument | semmle.label | XercesDOMParser output argument |
61+
| tests.cpp:69:2:69:2 | p | semmle.label | p |
62+
| tests.cpp:73:23:73:43 | XercesDOMParser output argument | semmle.label | XercesDOMParser output argument |
63+
| tests.cpp:80:2:80:2 | p | semmle.label | p |
64+
| tests.cpp:85:24:85:44 | XercesDOMParser output argument | semmle.label | XercesDOMParser output argument |
65+
| tests.cpp:88:3:88:3 | q | semmle.label | q |
66+
| tests.cpp:100:24:100:44 | XercesDOMParser output argument | semmle.label | XercesDOMParser output argument |
67+
| tests.cpp:104:3:104:3 | q | semmle.label | q |
68+
| tests.cpp:112:39:112:39 | p | semmle.label | p |
69+
| tests.cpp:113:2:113:2 | p | semmle.label | p |
70+
| tests.cpp:116:39:116:39 | p | semmle.label | p |
71+
| tests.cpp:117:2:117:2 | p | semmle.label | p |
72+
| tests.cpp:122:23:122:43 | XercesDOMParser output argument | semmle.label | XercesDOMParser output argument |
73+
| tests.cpp:126:18:126:18 | q | semmle.label | q |
74+
| tests.cpp:128:18:128:18 | q | semmle.label | q |
7875
subpaths
7976
#select
8077
| tests2.cpp:22:2:22:2 | p | tests2.cpp:20:17:20:31 | SAXParser output argument | tests2.cpp:22:2:22:2 | p | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests2.cpp:20:17:20:31 | SAXParser output argument | XML parser |
@@ -84,15 +81,14 @@ subpaths
8481
| tests4.cpp:46:34:46:68 | ... \| ... | tests4.cpp:46:34:46:68 | ... \| ... | tests4.cpp:46:34:46:68 | ... \| ... | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests4.cpp:46:34:46:68 | ... \| ... | XML parser |
8582
| tests4.cpp:77:34:77:38 | flags | tests4.cpp:77:34:77:38 | flags | tests4.cpp:77:34:77:38 | flags | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests4.cpp:77:34:77:38 | flags | XML parser |
8683
| tests4.cpp:130:39:130:55 | (int)... | tests4.cpp:130:39:130:55 | (int)... | tests4.cpp:130:39:130:55 | (int)... | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests4.cpp:130:39:130:55 | (int)... | XML parser |
87-
| tests.cpp:35:2:35:2 | p | tests.cpp:33:23:33:43 | XercesDOMParser output argument | tests.cpp:35:2:35:2 | p | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:33:23:33:43 | XercesDOMParser output argument | XML parser |
88-
| tests.cpp:49:2:49:2 | p | tests.cpp:46:23:46:43 | XercesDOMParser output argument | tests.cpp:49:2:49:2 | p | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:46:23:46:43 | XercesDOMParser output argument | XML parser |
89-
| tests.cpp:57:2:57:2 | p | tests.cpp:53:23:53:43 | XercesDOMParser output argument | tests.cpp:57:2:57:2 | p | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:53:23:53:43 | XercesDOMParser output argument | XML parser |
90-
| tests.cpp:74:2:74:2 | p | tests.cpp:69:23:69:43 | XercesDOMParser output argument | tests.cpp:74:2:74:2 | p | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:69:23:69:43 | XercesDOMParser output argument | XML parser |
91-
| tests.cpp:78:2:78:2 | p | tests.cpp:69:23:69:43 | XercesDOMParser output argument | tests.cpp:78:2:78:2 | p | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:69:23:69:43 | XercesDOMParser output argument | XML parser |
92-
| tests.cpp:87:2:87:2 | p | tests.cpp:84:23:84:43 | XercesDOMParser output argument | tests.cpp:87:2:87:2 | p | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:84:23:84:43 | XercesDOMParser output argument | XML parser |
93-
| tests.cpp:98:2:98:2 | p | tests.cpp:91:23:91:43 | XercesDOMParser output argument | tests.cpp:98:2:98:2 | p | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:91:23:91:43 | XercesDOMParser output argument | XML parser |
94-
| tests.cpp:106:3:106:3 | q | tests.cpp:103:24:103:44 | XercesDOMParser output argument | tests.cpp:106:3:106:3 | q | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:103:24:103:44 | XercesDOMParser output argument | XML parser |
95-
| tests.cpp:122:3:122:3 | q | tests.cpp:118:24:118:44 | XercesDOMParser output argument | tests.cpp:122:3:122:3 | q | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:118:24:118:44 | XercesDOMParser output argument | XML parser |
96-
| tests.cpp:131:2:131:2 | p | tests.cpp:140:23:140:43 | XercesDOMParser output argument | tests.cpp:131:2:131:2 | p | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:140:23:140:43 | XercesDOMParser output argument | XML parser |
97-
| tests.cpp:135:2:135:2 | p | tests.cpp:140:23:140:43 | XercesDOMParser output argument | tests.cpp:135:2:135:2 | p | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:140:23:140:43 | XercesDOMParser output argument | XML parser |
98-
| tests.cpp:152:2:152:2 | p | tests.cpp:150:19:150:32 | call to createLSParser | tests.cpp:152:2:152:2 | p | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:150:19:150:32 | call to createLSParser | XML parser |
84+
| tests.cpp:17:2:17:2 | p | tests.cpp:15:23:15:43 | XercesDOMParser output argument | tests.cpp:17:2:17:2 | p | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:15:23:15:43 | XercesDOMParser output argument | XML parser |
85+
| tests.cpp:31:2:31:2 | p | tests.cpp:28:23:28:43 | XercesDOMParser output argument | tests.cpp:31:2:31:2 | p | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:28:23:28:43 | XercesDOMParser output argument | XML parser |
86+
| tests.cpp:39:2:39:2 | p | tests.cpp:35:23:35:43 | XercesDOMParser output argument | tests.cpp:39:2:39:2 | p | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:35:23:35:43 | XercesDOMParser output argument | XML parser |
87+
| tests.cpp:56:2:56:2 | p | tests.cpp:51:23:51:43 | XercesDOMParser output argument | tests.cpp:56:2:56:2 | p | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:51:23:51:43 | XercesDOMParser output argument | XML parser |
88+
| tests.cpp:60:2:60:2 | p | tests.cpp:51:23:51:43 | XercesDOMParser output argument | tests.cpp:60:2:60:2 | p | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:51:23:51:43 | XercesDOMParser output argument | XML parser |
89+
| tests.cpp:69:2:69:2 | p | tests.cpp:66:23:66:43 | XercesDOMParser output argument | tests.cpp:69:2:69:2 | p | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:66:23:66:43 | XercesDOMParser output argument | XML parser |
90+
| tests.cpp:80:2:80:2 | p | tests.cpp:73:23:73:43 | XercesDOMParser output argument | tests.cpp:80:2:80:2 | p | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:73:23:73:43 | XercesDOMParser output argument | XML parser |
91+
| tests.cpp:88:3:88:3 | q | tests.cpp:85:24:85:44 | XercesDOMParser output argument | tests.cpp:88:3:88:3 | q | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:85:24:85:44 | XercesDOMParser output argument | XML parser |
92+
| tests.cpp:104:3:104:3 | q | tests.cpp:100:24:100:44 | XercesDOMParser output argument | tests.cpp:104:3:104:3 | q | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:100:24:100:44 | XercesDOMParser output argument | XML parser |
93+
| tests.cpp:113:2:113:2 | p | tests.cpp:122:23:122:43 | XercesDOMParser output argument | tests.cpp:113:2:113:2 | p | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:122:23:122:43 | XercesDOMParser output argument | XML parser |
94+
| tests.cpp:117:2:117:2 | p | tests.cpp:122:23:122:43 | XercesDOMParser output argument | tests.cpp:117:2:117:2 | p | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:122:23:122:43 | XercesDOMParser output argument | XML parser |

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

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,14 @@
1-
// test cases for rule CWE-611
1+
// test cases for rule CWE-611 (XercesDOMParser)
22

33
#include "tests.h"
44

55
// ---
66

7-
8-
9-
10-
class AbstractDOMParser {
11-
public:
12-
AbstractDOMParser();
13-
14-
void setDisableDefaultEntityResolution(bool); // default is false
15-
void setCreateEntityReferenceNodes(bool); // default is true
16-
void setSecurityManager(SecurityManager *const manager);
17-
void parse(const InputSource &data);
18-
};
19-
207
class XercesDOMParser: public AbstractDOMParser {
218
public:
229
XercesDOMParser();
2310
};
2411

25-
class DOMLSParser : public AbstractDOMParser {
26-
};
27-
28-
DOMLSParser *createLSParser();
29-
3012
// ---
3113

3214
void test1(InputSource &data) {
@@ -145,26 +127,3 @@ void test10(InputSource &data) {
145127
test10_doParseC(p, data);
146128
test10_doParseC(q, data);
147129
}
148-
149-
void test11(InputSource &data) {
150-
DOMLSParser *p = createLSParser();
151-
152-
p->parse(data); // BAD (parser not correctly configured)
153-
}
154-
155-
void test12(InputSource &data) {
156-
DOMLSParser *p = createLSParser();
157-
158-
p->setDisableDefaultEntityResolution(true);
159-
p->parse(data); // GOOD
160-
}
161-
162-
DOMLSParser *g_p1 = createLSParser();
163-
DOMLSParser *g_p2 = createLSParser();
164-
InputSource *g_data;
165-
166-
void test13() {
167-
g_p1->setDisableDefaultEntityResolution(true);
168-
g_p1->parse(*g_data); // GOOD
169-
g_p2->parse(*g_data); // BAD (parser not correctly configured) [NOT DETECTED]
170-
}
Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
// library/common functions for rule CWE-611
22

3+
#define NULL (0)
4+
35
class SecurityManager;
46
class InputSource;
57

6-
#define NULL (0)
8+
class AbstractDOMParser {
9+
public:
10+
AbstractDOMParser();
11+
12+
void setDisableDefaultEntityResolution(bool); // default is false
13+
void setCreateEntityReferenceNodes(bool); // default is true
14+
void setSecurityManager(SecurityManager *const manager);
15+
void parse(const InputSource &data);
16+
};
17+
18+
typedef unsigned int XMLCh;
19+
20+
class XMLUni
21+
{
22+
public:
23+
static const XMLCh fgXercesDisableDefaultEntityResolution[];
24+
};
25+

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// test cases for rule CWE-611
1+
// test cases for rule CWE-611 (SAXParser)
22

33
#include "tests.h"
44

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// test cases for rule CWE-611 (SAX2XMLReader)
2+
3+
#include "tests.h"
4+
5+
// ---
6+
7+
class SAX2XMLReader
8+
{
9+
public:
10+
void setFeature(const XMLCh *feature, bool value);
11+
void parse(const InputSource &data);
12+
};
13+
14+
class XMLReaderFactory
15+
{
16+
public:
17+
static SAX2XMLReader *createXMLReader();
18+
};
19+
20+
// ---
21+
22+
void test3_1(InputSource &data) {
23+
SAX2XMLReader *p = XMLReaderFactory::createXMLReader();
24+
25+
p->parse(data); // BAD (parser not correctly configured) [NOT DETECTED]
26+
}
27+
28+
void test3_2(InputSource &data) {
29+
SAX2XMLReader *p = XMLReaderFactory::createXMLReader();
30+
31+
p->setFeature(XMLUni::fgXercesDisableDefaultEntityResolution, true);
32+
p->parse(data); // GOOD
33+
}
34+
35+
SAX2XMLReader *p_3_3 = XMLReaderFactory::createXMLReader();
36+
37+
void test3_3(InputSource &data) {
38+
p_3_3->parse(data); // BAD (parser not correctly configured) [NOT DETECTED]
39+
}
40+
41+
SAX2XMLReader *p_3_4 = XMLReaderFactory::createXMLReader();
42+
43+
void test3_4(InputSource &data) {
44+
p_3_4->setFeature(XMLUni::fgXercesDisableDefaultEntityResolution, true);
45+
p_3_4->parse(data); // GOOD
46+
}
47+
48+
SAX2XMLReader *p_3_5 = XMLReaderFactory::createXMLReader();
49+
50+
void test3_5_init() {
51+
p_3_5->setFeature(XMLUni::fgXercesDisableDefaultEntityResolution, true);
52+
}
53+
54+
void test3_5(InputSource &data) {
55+
test3_5_init();
56+
p_3_5->parse(data); // GOOD
57+
}

0 commit comments

Comments
 (0)