Skip to content

Commit 7fb1069

Browse files
committed
C++: Use GVN on the values passed into set* functions.
1 parent 215453e commit 7fb1069

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import cpp
1616
import semmle.code.cpp.ir.dataflow.DataFlow
1717
import DataFlow::PathGraph
1818
import semmle.code.cpp.ir.IR
19+
import semmle.code.cpp.valuenumbering.GlobalValueNumbering
1920

2021
/**
2122
* A flow state representing a possible configuration of an XML object.
@@ -124,10 +125,10 @@ class DisableDefaultEntityResolutionTranformer extends XXEFlowStateTranformer {
124125
exists(int createEntityReferenceNodes |
125126
encodeXercesFlowState(flowstate, _, createEntityReferenceNodes) and
126127
(
127-
newValue.getValue().toInt() = 1 and // true
128+
globalValueNumber(newValue).getAnExpr().getValue().toInt() = 1 and // true
128129
encodeXercesFlowState(result, 1, createEntityReferenceNodes)
129130
or
130-
not newValue.getValue().toInt() = 1 and // false or unknown
131+
not globalValueNumber(newValue).getAnExpr().getValue().toInt() = 1 and // false or unknown
131132
encodeXercesFlowState(result, 0, createEntityReferenceNodes)
132133
)
133134
)
@@ -156,10 +157,10 @@ class CreateEntityReferenceNodesTranformer extends XXEFlowStateTranformer {
156157
exists(int disabledDefaultEntityResolution |
157158
encodeXercesFlowState(flowstate, disabledDefaultEntityResolution, _) and
158159
(
159-
newValue.getValue().toInt() = 1 and // true
160+
globalValueNumber(newValue).getAnExpr().getValue().toInt() = 1 and // true
160161
encodeXercesFlowState(result, disabledDefaultEntityResolution, 1)
161162
or
162-
not newValue.getValue().toInt() = 1 and // false or unknown
163+
not globalValueNumber(newValue).getAnExpr().getValue().toInt() = 1 and // false or unknown
163164
encodeXercesFlowState(result, disabledDefaultEntityResolution, 0)
164165
)
165166
)

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-
| tests2.cpp:41:17:41:31 | SAXParser output argument | tests2.cpp:45:2:45: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 |
@@ -34,8 +33,6 @@ nodes
3433
| tests2.cpp:22:2:22:2 | p | semmle.label | p |
3534
| tests2.cpp:33:17:33:31 | SAXParser output argument | semmle.label | SAXParser output argument |
3635
| tests2.cpp:37:2:37:2 | p | semmle.label | p |
37-
| tests2.cpp:41:17:41:31 | SAXParser output argument | semmle.label | SAXParser output argument |
38-
| tests2.cpp:45:2:45:2 | p | semmle.label | p |
3936
| tests.cpp:33:23:33:43 | XercesDOMParser output argument | semmle.label | XercesDOMParser output argument |
4037
| tests.cpp:35:2:35:2 | p | semmle.label | p |
4138
| tests.cpp:46:23:46:43 | XercesDOMParser output argument | semmle.label | XercesDOMParser output argument |
@@ -77,7 +74,6 @@ subpaths
7774
#select
7875
| 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 |
7976
| 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 |
80-
| tests2.cpp:45:2:45:2 | p | tests2.cpp:41:17:41:31 | SAXParser output argument | tests2.cpp:45:2:45:2 | p | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests2.cpp:41:17:41:31 | SAXParser output argument | XML parser |
8177
| 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 |
8278
| 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 |
8379
| 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/tests2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ void test2_4(InputSource &data) {
4242
bool v = true;
4343

4444
p->setDisableDefaultEntityResolution(v);
45-
p->parse(data); // GOOD [FALSE POSITIVE]
45+
p->parse(data); // GOOD
4646
}

0 commit comments

Comments
 (0)