Skip to content

Commit 0f93e5c

Browse files
authored
Merge pull request #11781 from MathiasVP/as-expr-for-arrays
C++: Map more expressions to `OperandNode`s
2 parents 83d751b + e453c7a commit 0f93e5c

12 files changed

Lines changed: 145 additions & 101 deletions

File tree

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -770,32 +770,11 @@ class RawIndirectInstruction extends Node, TRawIndirectInstruction {
770770
}
771771
}
772772

773-
private predicate isFullyConvertedArgument(Expr e) {
774-
exists(Call call |
775-
e = call.getAnArgument().getFullyConverted()
776-
or
777-
e = call.getQualifier().getFullyConverted()
778-
)
779-
}
780-
781-
private predicate isFullyConvertedCall(Expr e) { e = any(Call call).getFullyConverted() }
782-
783-
/** Holds if `Node::asExpr` should map an some operand node to `e`. */
784-
private predicate convertedExprMustBeOperand(Expr e) {
785-
isFullyConvertedArgument(e)
786-
or
787-
isFullyConvertedCall(e)
788-
}
789-
790773
/** Holds if `node` is an `OperandNode` that should map `node.asExpr()` to `e`. */
791774
predicate exprNodeShouldBeOperand(OperandNode node, Expr e) {
792-
exists(Operand operand |
793-
node.getOperand() = operand and
794-
e = operand.getDef().getConvertedResultExpression()
795-
|
796-
convertedExprMustBeOperand(e)
797-
or
798-
node.(IndirectOperand).isIRRepresentationOf(_, _)
775+
exists(Instruction def |
776+
unique( | | getAUse(def)) = node.getOperand() and
777+
e = def.getConvertedResultExpression()
799778
)
800779
}
801780

cpp/ql/test/library-tests/dataflow/fields/ir-path-flow.expected

Lines changed: 35 additions & 31 deletions
Large diffs are not rendered by default.

cpp/ql/test/query-tests/Security/CWE/CWE-078/semmle/ExecTainted/ExecTainted.expected

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ edges
1515
| test.cpp:91:9:91:16 | fread output argument | test.cpp:93:17:93:24 | Convert indirection |
1616
| test.cpp:93:11:93:14 | strncat output argument | test.cpp:94:45:94:48 | Convert indirection |
1717
| test.cpp:93:17:93:24 | Convert indirection | test.cpp:93:11:93:14 | strncat output argument |
18-
| test.cpp:106:20:106:25 | call to getenv | test.cpp:107:33:107:36 | CopyValue indirection |
18+
| test.cpp:106:20:106:25 | Call | test.cpp:107:33:107:36 | CopyValue indirection |
1919
| test.cpp:106:20:106:38 | call to getenv indirection | test.cpp:107:33:107:36 | CopyValue indirection |
2020
| test.cpp:107:31:107:31 | Call | test.cpp:108:18:108:22 | call to c_str indirection |
2121
| test.cpp:107:33:107:36 | CopyValue indirection | test.cpp:107:31:107:31 | Call |
22-
| test.cpp:113:20:113:25 | call to getenv | test.cpp:114:19:114:22 | CopyValue indirection |
22+
| test.cpp:113:20:113:25 | Call | test.cpp:114:19:114:22 | CopyValue indirection |
2323
| test.cpp:113:20:113:38 | call to getenv indirection | test.cpp:114:19:114:22 | CopyValue indirection |
2424
| test.cpp:114:10:114:23 | Convert | test.cpp:114:25:114:29 | call to c_str indirection |
2525
| test.cpp:114:17:114:17 | call to operator+ | test.cpp:114:25:114:29 | call to c_str indirection |
2626
| test.cpp:114:19:114:22 | CopyValue indirection | test.cpp:114:10:114:23 | Convert |
2727
| test.cpp:114:19:114:22 | CopyValue indirection | test.cpp:114:17:114:17 | call to operator+ |
28-
| test.cpp:119:20:119:25 | call to getenv | test.cpp:120:19:120:22 | CopyValue indirection |
28+
| test.cpp:119:20:119:25 | Call | test.cpp:120:19:120:22 | CopyValue indirection |
2929
| test.cpp:119:20:119:38 | call to getenv indirection | test.cpp:120:19:120:22 | CopyValue indirection |
3030
| test.cpp:120:17:120:17 | call to operator+ | test.cpp:120:10:120:30 | call to data indirection |
3131
| test.cpp:120:19:120:22 | CopyValue indirection | test.cpp:120:17:120:17 | call to operator+ |
@@ -122,19 +122,19 @@ nodes
122122
| test.cpp:93:11:93:14 | strncat output argument | semmle.label | strncat output argument |
123123
| test.cpp:93:17:93:24 | Convert indirection | semmle.label | Convert indirection |
124124
| test.cpp:94:45:94:48 | Convert indirection | semmle.label | Convert indirection |
125-
| test.cpp:106:20:106:25 | call to getenv | semmle.label | call to getenv |
125+
| test.cpp:106:20:106:25 | Call | semmle.label | Call |
126126
| test.cpp:106:20:106:38 | call to getenv indirection | semmle.label | call to getenv indirection |
127127
| test.cpp:107:31:107:31 | Call | semmle.label | Call |
128128
| test.cpp:107:33:107:36 | CopyValue indirection | semmle.label | CopyValue indirection |
129129
| test.cpp:108:18:108:22 | call to c_str indirection | semmle.label | call to c_str indirection |
130-
| test.cpp:113:20:113:25 | call to getenv | semmle.label | call to getenv |
130+
| test.cpp:113:20:113:25 | Call | semmle.label | Call |
131131
| test.cpp:113:20:113:38 | call to getenv indirection | semmle.label | call to getenv indirection |
132132
| test.cpp:114:10:114:23 | Convert | semmle.label | Convert |
133133
| test.cpp:114:17:114:17 | call to operator+ | semmle.label | call to operator+ |
134134
| test.cpp:114:19:114:22 | CopyValue indirection | semmle.label | CopyValue indirection |
135135
| test.cpp:114:25:114:29 | call to c_str indirection | semmle.label | call to c_str indirection |
136136
| test.cpp:114:25:114:29 | call to c_str indirection | semmle.label | call to c_str indirection |
137-
| test.cpp:119:20:119:25 | call to getenv | semmle.label | call to getenv |
137+
| test.cpp:119:20:119:25 | Call | semmle.label | Call |
138138
| test.cpp:119:20:119:38 | call to getenv indirection | semmle.label | call to getenv indirection |
139139
| test.cpp:120:10:120:30 | call to data indirection | semmle.label | call to data indirection |
140140
| test.cpp:120:17:120:17 | call to operator+ | semmle.label | call to operator+ |
@@ -217,13 +217,13 @@ subpaths
217217
| test.cpp:65:10:65:16 | command | test.cpp:62:9:62:16 | fread output argument | test.cpp:65:10:65:16 | Convert indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to system(string). | test.cpp:62:9:62:16 | fread output argument | user input (string read by fread) | test.cpp:64:11:64:17 | strncat output argument | strncat output argument |
218218
| test.cpp:85:32:85:38 | command | test.cpp:82:9:82:16 | fread output argument | test.cpp:85:32:85:38 | Convert indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to execl. | test.cpp:82:9:82:16 | fread output argument | user input (string read by fread) | test.cpp:84:11:84:17 | strncat output argument | strncat output argument |
219219
| test.cpp:94:45:94:48 | path | test.cpp:91:9:91:16 | fread output argument | test.cpp:94:45:94:48 | Convert indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to execl. | test.cpp:91:9:91:16 | fread output argument | user input (string read by fread) | test.cpp:93:11:93:14 | strncat output argument | strncat output argument |
220-
| test.cpp:108:18:108:22 | call to c_str | test.cpp:106:20:106:25 | call to getenv | test.cpp:108:18:108:22 | call to c_str indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to system(string). | test.cpp:106:20:106:25 | call to getenv | user input (an environment variable) | test.cpp:107:31:107:31 | Call | Call |
220+
| test.cpp:108:18:108:22 | call to c_str | test.cpp:106:20:106:25 | Call | test.cpp:108:18:108:22 | call to c_str indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to system(string). | test.cpp:106:20:106:25 | Call | user input (an environment variable) | test.cpp:107:31:107:31 | Call | Call |
221221
| test.cpp:108:18:108:22 | call to c_str | test.cpp:106:20:106:38 | call to getenv indirection | test.cpp:108:18:108:22 | call to c_str indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to system(string). | test.cpp:106:20:106:38 | call to getenv indirection | user input (an environment variable) | test.cpp:107:31:107:31 | Call | Call |
222-
| test.cpp:114:25:114:29 | call to c_str | test.cpp:113:20:113:25 | call to getenv | test.cpp:114:25:114:29 | call to c_str indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to system(string). | test.cpp:113:20:113:25 | call to getenv | user input (an environment variable) | test.cpp:114:10:114:23 | Convert | Convert |
223-
| test.cpp:114:25:114:29 | call to c_str | test.cpp:113:20:113:25 | call to getenv | test.cpp:114:25:114:29 | call to c_str indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to system(string). | test.cpp:113:20:113:25 | call to getenv | user input (an environment variable) | test.cpp:114:17:114:17 | call to operator+ | call to operator+ |
222+
| test.cpp:114:25:114:29 | call to c_str | test.cpp:113:20:113:25 | Call | test.cpp:114:25:114:29 | call to c_str indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to system(string). | test.cpp:113:20:113:25 | Call | user input (an environment variable) | test.cpp:114:10:114:23 | Convert | Convert |
223+
| test.cpp:114:25:114:29 | call to c_str | test.cpp:113:20:113:25 | Call | test.cpp:114:25:114:29 | call to c_str indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to system(string). | test.cpp:113:20:113:25 | Call | user input (an environment variable) | test.cpp:114:17:114:17 | call to operator+ | call to operator+ |
224224
| test.cpp:114:25:114:29 | call to c_str | test.cpp:113:20:113:38 | call to getenv indirection | test.cpp:114:25:114:29 | call to c_str indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to system(string). | test.cpp:113:20:113:38 | call to getenv indirection | user input (an environment variable) | test.cpp:114:10:114:23 | Convert | Convert |
225225
| test.cpp:114:25:114:29 | call to c_str | test.cpp:113:20:113:38 | call to getenv indirection | test.cpp:114:25:114:29 | call to c_str indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to system(string). | test.cpp:113:20:113:38 | call to getenv indirection | user input (an environment variable) | test.cpp:114:17:114:17 | call to operator+ | call to operator+ |
226-
| test.cpp:120:25:120:28 | call to data | test.cpp:119:20:119:25 | call to getenv | test.cpp:120:10:120:30 | call to data indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to system(string). | test.cpp:119:20:119:25 | call to getenv | user input (an environment variable) | test.cpp:120:17:120:17 | call to operator+ | call to operator+ |
226+
| test.cpp:120:25:120:28 | call to data | test.cpp:119:20:119:25 | Call | test.cpp:120:10:120:30 | call to data indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to system(string). | test.cpp:119:20:119:25 | Call | user input (an environment variable) | test.cpp:120:17:120:17 | call to operator+ | call to operator+ |
227227
| test.cpp:120:25:120:28 | call to data | test.cpp:119:20:119:38 | call to getenv indirection | test.cpp:120:10:120:30 | call to data indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to system(string). | test.cpp:119:20:119:38 | call to getenv indirection | user input (an environment variable) | test.cpp:120:17:120:17 | call to operator+ | call to operator+ |
228228
| test.cpp:143:10:143:16 | command | test.cpp:140:9:140:11 | fread output argument | test.cpp:143:10:143:16 | Convert indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to system(string). | test.cpp:140:9:140:11 | fread output argument | user input (string read by fread) | test.cpp:142:11:142:17 | sprintf output argument | sprintf output argument |
229229
| test.cpp:183:32:183:38 | command | test.cpp:174:9:174:16 | fread output argument | test.cpp:183:32:183:38 | Convert indirection | This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to execl. | test.cpp:174:9:174:16 | fread output argument | user input (string read by fread) | test.cpp:177:13:177:17 | strncat output argument | strncat output argument |

cpp/ql/test/query-tests/Security/CWE/CWE-089/SqlTainted/SqlTainted.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ edges
55
| test.c:15:20:15:23 | argv | test.c:21:18:21:23 | query1 |
66
| test.c:15:20:15:23 | argv | test.c:21:18:21:23 | query1 |
77
| test.c:15:20:15:23 | argv | test.c:21:18:21:23 | query1 |
8+
| test.c:15:20:15:23 | argv | test.c:21:18:21:23 | query1 |
9+
| test.c:15:20:15:23 | argv | test.c:21:18:21:23 | query1 |
810
| test.cpp:43:27:43:30 | argv | test.cpp:43:27:43:33 | access to array |
911
| test.cpp:43:27:43:30 | argv | test.cpp:43:27:43:33 | access to array |
1012
| test.cpp:43:27:43:30 | argv | test.cpp:43:27:43:33 | access to array |
@@ -18,6 +20,7 @@ nodes
1820
| test.c:21:18:21:23 | query1 | semmle.label | query1 |
1921
| test.c:21:18:21:23 | query1 | semmle.label | query1 |
2022
| test.c:21:18:21:23 | query1 | semmle.label | query1 |
23+
| test.c:21:18:21:23 | query1 | semmle.label | query1 |
2124
| test.cpp:43:27:43:30 | argv | semmle.label | argv |
2225
| test.cpp:43:27:43:30 | argv | semmle.label | argv |
2326
| test.cpp:43:27:43:33 | access to array | semmle.label | access to array |

cpp/ql/test/query-tests/Security/CWE/CWE-114/semmle/UncontrolledProcessOperation/UncontrolledProcessOperation.expected

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ edges
1313
| test.cpp:56:12:56:17 | buffer | test.cpp:62:10:62:15 | buffer |
1414
| test.cpp:56:12:56:17 | buffer | test.cpp:62:10:62:15 | buffer |
1515
| test.cpp:56:12:56:17 | buffer | test.cpp:62:10:62:15 | buffer |
16+
| test.cpp:56:12:56:17 | buffer | test.cpp:62:10:62:15 | buffer |
17+
| test.cpp:56:12:56:17 | buffer | test.cpp:62:10:62:15 | buffer |
1618
| test.cpp:56:12:56:17 | buffer | test.cpp:63:10:63:13 | data |
1719
| test.cpp:56:12:56:17 | buffer | test.cpp:63:10:63:13 | data |
1820
| test.cpp:56:12:56:17 | buffer | test.cpp:63:10:63:13 | data |
@@ -36,6 +38,7 @@ edges
3638
| test.cpp:56:12:56:17 | fgets output argument | test.cpp:62:10:62:15 | buffer |
3739
| test.cpp:56:12:56:17 | fgets output argument | test.cpp:62:10:62:15 | buffer |
3840
| test.cpp:56:12:56:17 | fgets output argument | test.cpp:62:10:62:15 | buffer |
41+
| test.cpp:56:12:56:17 | fgets output argument | test.cpp:62:10:62:15 | buffer |
3942
| test.cpp:56:12:56:17 | fgets output argument | test.cpp:63:10:63:13 | data |
4043
| test.cpp:56:12:56:17 | fgets output argument | test.cpp:63:10:63:13 | data |
4144
| test.cpp:56:12:56:17 | fgets output argument | test.cpp:63:10:63:13 | data |
@@ -52,6 +55,9 @@ edges
5255
| test.cpp:76:12:76:17 | buffer | test.cpp:78:10:78:15 | buffer |
5356
| test.cpp:76:12:76:17 | buffer | test.cpp:78:10:78:15 | buffer |
5457
| test.cpp:76:12:76:17 | buffer | test.cpp:78:10:78:15 | buffer |
58+
| test.cpp:76:12:76:17 | buffer | test.cpp:78:10:78:15 | buffer |
59+
| test.cpp:76:12:76:17 | buffer | test.cpp:78:10:78:15 | buffer |
60+
| test.cpp:76:12:76:17 | fgets output argument | test.cpp:78:10:78:15 | buffer |
5561
| test.cpp:76:12:76:17 | fgets output argument | test.cpp:78:10:78:15 | buffer |
5662
| test.cpp:76:12:76:17 | fgets output argument | test.cpp:78:10:78:15 | buffer |
5763
| test.cpp:76:12:76:17 | fgets output argument | test.cpp:78:10:78:15 | buffer |
@@ -61,15 +67,21 @@ edges
6167
| test.cpp:98:17:98:22 | buffer | test.cpp:99:15:99:20 | buffer |
6268
| test.cpp:98:17:98:22 | buffer | test.cpp:99:15:99:20 | buffer |
6369
| test.cpp:98:17:98:22 | buffer | test.cpp:99:15:99:20 | buffer |
70+
| test.cpp:98:17:98:22 | buffer | test.cpp:99:15:99:20 | buffer |
71+
| test.cpp:98:17:98:22 | buffer | test.cpp:99:15:99:20 | buffer |
6472
| test.cpp:98:17:98:22 | recv output argument | test.cpp:99:15:99:20 | buffer |
6573
| test.cpp:98:17:98:22 | recv output argument | test.cpp:99:15:99:20 | buffer |
6674
| test.cpp:98:17:98:22 | recv output argument | test.cpp:99:15:99:20 | buffer |
75+
| test.cpp:98:17:98:22 | recv output argument | test.cpp:99:15:99:20 | buffer |
76+
| test.cpp:106:17:106:22 | buffer | test.cpp:107:15:107:20 | buffer |
6777
| test.cpp:106:17:106:22 | buffer | test.cpp:107:15:107:20 | buffer |
6878
| test.cpp:106:17:106:22 | buffer | test.cpp:107:15:107:20 | buffer |
6979
| test.cpp:106:17:106:22 | buffer | test.cpp:107:15:107:20 | buffer |
7080
| test.cpp:106:17:106:22 | buffer | test.cpp:107:15:107:20 | buffer |
7181
| test.cpp:106:17:106:22 | buffer | test.cpp:107:15:107:20 | buffer |
7282
| test.cpp:106:17:106:22 | buffer | test.cpp:107:15:107:20 | buffer |
83+
| test.cpp:106:17:106:22 | buffer | test.cpp:107:15:107:20 | buffer |
84+
| test.cpp:106:17:106:22 | recv output argument | test.cpp:107:15:107:20 | buffer |
7385
| test.cpp:106:17:106:22 | recv output argument | test.cpp:107:15:107:20 | buffer |
7486
| test.cpp:106:17:106:22 | recv output argument | test.cpp:107:15:107:20 | buffer |
7587
| test.cpp:106:17:106:22 | recv output argument | test.cpp:107:15:107:20 | buffer |
@@ -91,6 +103,7 @@ nodes
91103
| test.cpp:62:10:62:15 | buffer | semmle.label | buffer |
92104
| test.cpp:62:10:62:15 | buffer | semmle.label | buffer |
93105
| test.cpp:62:10:62:15 | buffer | semmle.label | buffer |
106+
| test.cpp:62:10:62:15 | buffer | semmle.label | buffer |
94107
| test.cpp:63:10:63:13 | data | semmle.label | data |
95108
| test.cpp:63:10:63:13 | data | semmle.label | data |
96109
| test.cpp:63:10:63:13 | data | semmle.label | data |
@@ -107,18 +120,21 @@ nodes
107120
| test.cpp:78:10:78:15 | buffer | semmle.label | buffer |
108121
| test.cpp:78:10:78:15 | buffer | semmle.label | buffer |
109122
| test.cpp:78:10:78:15 | buffer | semmle.label | buffer |
123+
| test.cpp:78:10:78:15 | buffer | semmle.label | buffer |
110124
| test.cpp:98:17:98:22 | buffer | semmle.label | buffer |
111125
| test.cpp:98:17:98:22 | buffer | semmle.label | buffer |
112126
| test.cpp:98:17:98:22 | recv output argument | semmle.label | recv output argument |
113127
| test.cpp:99:15:99:20 | buffer | semmle.label | buffer |
114128
| test.cpp:99:15:99:20 | buffer | semmle.label | buffer |
115129
| test.cpp:99:15:99:20 | buffer | semmle.label | buffer |
130+
| test.cpp:99:15:99:20 | buffer | semmle.label | buffer |
116131
| test.cpp:106:17:106:22 | buffer | semmle.label | buffer |
117132
| test.cpp:106:17:106:22 | buffer | semmle.label | buffer |
118133
| test.cpp:106:17:106:22 | recv output argument | semmle.label | recv output argument |
119134
| test.cpp:107:15:107:20 | buffer | semmle.label | buffer |
120135
| test.cpp:107:15:107:20 | buffer | semmle.label | buffer |
121136
| test.cpp:107:15:107:20 | buffer | semmle.label | buffer |
137+
| test.cpp:107:15:107:20 | buffer | semmle.label | buffer |
122138
#select
123139
| test.cpp:26:10:26:16 | command | test.cpp:42:18:42:23 | call to getenv | test.cpp:26:10:26:16 | command | The value of this argument may come from $@ and is being passed to system. | test.cpp:42:18:42:23 | call to getenv | call to getenv |
124140
| test.cpp:31:10:31:16 | command | test.cpp:43:18:43:23 | call to getenv | test.cpp:31:10:31:16 | command | The value of this argument may come from $@ and is being passed to system. | test.cpp:43:18:43:23 | call to getenv | call to getenv |

0 commit comments

Comments
 (0)