Skip to content

Commit f02ffcb

Browse files
committed
C++: Modify ParameterIndex to account for varargs.
1 parent d66f608 commit f02ffcb

File tree

5 files changed

+15
-4
lines changed

5 files changed

+15
-4
lines changed

cpp/ql/src/semmle/code/cpp/Parameter.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,8 @@ class Parameter extends LocalScopeVariable, @parameter {
163163
* An `int` that is a parameter index for some function. This is needed for binding in certain cases.
164164
*/
165165
class ParameterIndex extends int {
166-
ParameterIndex() { exists(Parameter p | this = p.getIndex()) }
166+
ParameterIndex() {
167+
exists(Parameter p | this = p.getIndex()) or
168+
exists(Call c | exists(c.getArgument(this))) // permit indexing varargs
169+
}
167170
}

cpp/ql/test/library-tests/dataflow/taint-tests/format.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ void test1()
6060
{
6161
char buffer[256] = {0};
6262
sink(snprintf(buffer, 256, "%s %s %s", "a", "b", string::source()));
63-
sink(buffer); // tainted [NOT DETECTED]
63+
sink(buffer); // tainted
6464
}
6565
{
6666
char buffer[256] = {0};
6767
sink(snprintf(buffer, 256, "%.*s", 10, string::source()));
68-
sink(buffer); // tainted [NOT DETECTED]
68+
sink(buffer); // tainted
6969
}
7070

7171
{
@@ -108,7 +108,7 @@ void test1()
108108
{
109109
char buffer[256] = {0};
110110
sink(mysprintf(buffer, 256, "%s", string::source()));
111-
sink(buffer); // tainted [NOT DETECTED]
111+
sink(buffer); // tainted [NOT DETECTED - implement UserDefinedFormattingFunction.getOutputParameterIndex()]
112112
}
113113

114114
{

cpp/ql/test/library-tests/dataflow/taint-tests/localTaint.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@
3131
| format.cpp:62:17:62:22 | ref arg buffer | format.cpp:63:8:63:13 | buffer | |
3232
| format.cpp:62:30:62:39 | %s %s %s | format.cpp:62:17:62:22 | ref arg buffer | TAINT |
3333
| format.cpp:62:42:62:44 | a | format.cpp:62:17:62:22 | ref arg buffer | TAINT |
34+
| format.cpp:62:47:62:49 | b | format.cpp:62:17:62:22 | ref arg buffer | TAINT |
35+
| format.cpp:62:52:62:65 | call to source | format.cpp:62:17:62:22 | ref arg buffer | TAINT |
3436
| format.cpp:66:21:66:24 | {...} | format.cpp:67:17:67:22 | buffer | |
3537
| format.cpp:66:21:66:24 | {...} | format.cpp:68:8:68:13 | buffer | |
3638
| format.cpp:66:23:66:23 | 0 | format.cpp:66:21:66:24 | {...} | TAINT |
3739
| format.cpp:67:17:67:22 | ref arg buffer | format.cpp:68:8:68:13 | buffer | |
3840
| format.cpp:67:30:67:35 | %.*s | format.cpp:67:17:67:22 | ref arg buffer | TAINT |
3941
| format.cpp:67:38:67:39 | 10 | format.cpp:67:17:67:22 | ref arg buffer | TAINT |
42+
| format.cpp:67:42:67:55 | call to source | format.cpp:67:17:67:22 | ref arg buffer | TAINT |
4043
| format.cpp:72:21:72:24 | {...} | format.cpp:73:17:73:22 | buffer | |
4144
| format.cpp:72:21:72:24 | {...} | format.cpp:74:8:74:13 | buffer | |
4245
| format.cpp:72:23:72:23 | 0 | format.cpp:72:21:72:24 | {...} | TAINT |
@@ -55,6 +58,7 @@
5558
| format.cpp:83:17:83:22 | ref arg buffer | format.cpp:84:8:84:13 | buffer | |
5659
| format.cpp:83:30:83:35 | %.*s | format.cpp:83:17:83:22 | ref arg buffer | TAINT |
5760
| format.cpp:83:38:83:43 | call to source | format.cpp:83:17:83:22 | ref arg buffer | TAINT |
61+
| format.cpp:83:48:83:55 | Hello. | format.cpp:83:17:83:22 | ref arg buffer | TAINT |
5862
| format.cpp:88:21:88:24 | {...} | format.cpp:89:17:89:22 | buffer | |
5963
| format.cpp:88:21:88:24 | {...} | format.cpp:90:8:90:13 | buffer | |
6064
| format.cpp:88:23:88:23 | 0 | format.cpp:88:21:88:24 | {...} | TAINT |

cpp/ql/test/library-tests/dataflow/taint-tests/taint.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
| format.cpp:53:8:53:13 | buffer | format.cpp:52:36:52:49 | call to source |
22
| format.cpp:58:8:58:13 | buffer | format.cpp:57:30:57:43 | call to source |
3+
| format.cpp:63:8:63:13 | buffer | format.cpp:62:52:62:65 | call to source |
4+
| format.cpp:68:8:68:13 | buffer | format.cpp:67:42:67:55 | call to source |
35
| format.cpp:79:8:79:13 | buffer | format.cpp:78:36:78:41 | call to source |
46
| format.cpp:84:8:84:13 | buffer | format.cpp:83:38:83:43 | call to source |
57
| format.cpp:90:8:90:13 | buffer | format.cpp:89:36:89:49 | call to source |

cpp/ql/test/library-tests/dataflow/taint-tests/test_diff.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
| format.cpp:53:8:53:13 | format.cpp:52:36:52:49 | AST only |
22
| format.cpp:58:8:58:13 | format.cpp:57:30:57:43 | AST only |
3+
| format.cpp:63:8:63:13 | format.cpp:62:52:62:65 | AST only |
4+
| format.cpp:68:8:68:13 | format.cpp:67:42:67:55 | AST only |
35
| format.cpp:79:8:79:13 | format.cpp:78:36:78:41 | AST only |
46
| format.cpp:84:8:84:13 | format.cpp:83:38:83:43 | AST only |
57
| format.cpp:90:8:90:13 | format.cpp:89:36:89:49 | AST only |

0 commit comments

Comments
 (0)