Skip to content

Commit 6ada1bd

Browse files
committed
C++: Match createLSParser more precisely.
1 parent a21af8e commit 6ada1bd

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

cpp/ql/src/Security/CWE/CWE-611/XXE.ql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,10 @@ class ParseFunction extends Function {
167167
* The `createLSParser` function that returns a newly created `LSParser` object.
168168
*/
169169
class CreateLSParser extends Function {
170-
CreateLSParser() { this.hasName("createLSParser") }
170+
CreateLSParser() {
171+
this.hasName("createLSParser") and
172+
this.getType().(PointerType).getBaseType().getName() = "DOMLSParser" // returns a `DOMLSParser *`.
173+
}
171174
}
172175

173176
/**

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ edges
2525
| tests.cpp:140:23:140:43 | XercesDOMParser output argument | tests.cpp:146:18:146:18 | q |
2626
| tests.cpp:144:18:144:18 | q | tests.cpp:130:39:130:39 | p |
2727
| tests.cpp:146:18:146:18 | q | tests.cpp:134:39:134:39 | p |
28-
| tests.cpp:150:16:150:29 | call to createLSParser | tests.cpp:152:2:152:2 | p |
28+
| tests.cpp:150:19:150:32 | call to createLSParser | tests.cpp:152:2:152:2 | p |
2929
nodes
3030
| tests.cpp:33:23:33:43 | XercesDOMParser output argument | semmle.label | XercesDOMParser output argument |
3131
| tests.cpp:35:2:35:2 | p | semmle.label | p |
@@ -62,7 +62,7 @@ nodes
6262
| tests.cpp:140:23:140:43 | XercesDOMParser output argument | semmle.label | XercesDOMParser output argument |
6363
| tests.cpp:144:18:144:18 | q | semmle.label | q |
6464
| tests.cpp:146:18:146:18 | q | semmle.label | q |
65-
| tests.cpp:150:16:150:29 | call to createLSParser | semmle.label | call to createLSParser |
65+
| tests.cpp:150:19:150:32 | call to createLSParser | semmle.label | call to createLSParser |
6666
| tests.cpp:152:2:152:2 | p | semmle.label | p |
6767
subpaths
6868
#select
@@ -77,4 +77,4 @@ subpaths
7777
| 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 |
7878
| 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 |
7979
| 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 |
80-
| tests.cpp:152:2:152:2 | p | tests.cpp:150:16:150:29 | 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:16:150:29 | call to createLSParser | XML parser |
80+
| 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 |

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ class XercesDOMParser: public AbstractDOMParser {
2222
XercesDOMParser();
2323
};
2424

25-
class LSParser: public AbstractDOMParser {
25+
class DOMLSParser : public AbstractDOMParser {
2626
};
2727

28-
LSParser *createLSParser();
28+
DOMLSParser *createLSParser();
2929

3030
// ---
3131

@@ -147,20 +147,20 @@ void test10(InputSource &data) {
147147
}
148148

149149
void test11(InputSource &data) {
150-
LSParser *p = createLSParser();
150+
DOMLSParser *p = createLSParser();
151151

152152
p->parse(data); // BAD (parser not correctly configured)
153153
}
154154

155155
void test12(InputSource &data) {
156-
LSParser *p = createLSParser();
156+
DOMLSParser *p = createLSParser();
157157

158158
p->setDisableDefaultEntityResolution(true);
159159
p->parse(data); // GOOD
160160
}
161161

162-
LSParser *g_p1 = createLSParser();
163-
LSParser *g_p2 = createLSParser();
162+
DOMLSParser *g_p1 = createLSParser();
163+
DOMLSParser *g_p2 = createLSParser();
164164
InputSource *g_data;
165165

166166
void test13() {

0 commit comments

Comments
 (0)