Skip to content

Commit 1d71f04

Browse files
committed
C++: Turns out DOMLSParser is not an AbstractDOMParser and works a little differently than I'd thought.
1 parent c6deddb commit 1d71f04

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
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-
| tests5.cpp:18:25:18:38 | call to createLSParser | tests5.cpp:20:2:20:2 | p |
54
| tests.cpp:33:23:33:43 | XercesDOMParser output argument | tests.cpp:35:2:35:2 | p |
65
| tests.cpp:46:23:46:43 | XercesDOMParser output argument | tests.cpp:49:2:49:2 | p |
76
| tests.cpp:53:19:53:19 | VariableAddress [post update] | tests.cpp:55:2:55:2 | p |
@@ -33,8 +32,6 @@ nodes
3332
| tests2.cpp:22:2:22:2 | p | semmle.label | p |
3433
| tests2.cpp:33:17:33:31 | SAXParser output argument | semmle.label | SAXParser output argument |
3534
| tests2.cpp:37:2:37:2 | p | semmle.label | p |
36-
| tests5.cpp:18:25:18:38 | call to createLSParser | semmle.label | call to createLSParser |
37-
| tests5.cpp:20:2:20:2 | p | semmle.label | p |
3835
| tests.cpp:33:23:33:43 | XercesDOMParser output argument | semmle.label | XercesDOMParser output argument |
3936
| tests.cpp:35:2:35:2 | p | semmle.label | p |
4037
| tests.cpp:46:23:46:43 | XercesDOMParser output argument | semmle.label | XercesDOMParser output argument |
@@ -74,7 +71,6 @@ subpaths
7471
#select
7572
| 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 |
7673
| tests2.cpp:37:2:37:2 | p | tests2.cpp:33:17:33:31 | SAXParser output argument | tests2.cpp:37:2:37:2 | p | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests2.cpp:33:17:33:31 | SAXParser output argument | XML parser |
77-
| tests5.cpp:20:2:20:2 | p | tests5.cpp:18:25:18:38 | call to createLSParser | tests5.cpp:20:2:20:2 | p | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests5.cpp:18:25:18:38 | call to createLSParser | XML parser |
7874
| 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 |
7975
| 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 |
8076
| 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 |

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@
44

55
// ---
66

7-
class DOMLSParser : public AbstractDOMParser {
7+
class DOMConfiguration {
8+
public:
9+
void setParameter(const XMLCh *parameter, bool value);
10+
};
11+
12+
class DOMLSParser {
13+
public:
14+
DOMConfiguration *getDomConfig();
15+
16+
void parse(const InputSource &data);
817
};
918

1019
class DOMImplementationLS {
@@ -17,13 +26,13 @@ class DOMImplementationLS {
1726
void test5_1(DOMImplementationLS *impl, InputSource &data) {
1827
DOMLSParser *p = impl->createLSParser();
1928

20-
p->parse(data); // BAD (parser not correctly configured)
29+
p->parse(data); // BAD (parser not correctly configured) [NOT DETECTED]
2130
}
2231

2332
void test5_2(DOMImplementationLS *impl, InputSource &data) {
2433
DOMLSParser *p = impl->createLSParser();
2534

26-
p->setDisableDefaultEntityResolution(true);
35+
p->getDomConfig()->setParameter(XMLUni::fgXercesDisableDefaultEntityResolution, true);
2736
p->parse(data); // GOOD
2837
}
2938

@@ -33,7 +42,7 @@ InputSource *g_data;
3342

3443
void test5_3_init() {
3544
g_p1 = g_impl->createLSParser();
36-
g_p1->setDisableDefaultEntityResolution(true);
45+
g_p1->getDomConfig()->setParameter(XMLUni::fgXercesDisableDefaultEntityResolution, true);
3746

3847
g_p2 = g_impl->createLSParser();
3948
}

0 commit comments

Comments
 (0)