Skip to content

Commit bb451f3

Browse files
committed
C++: Fix result duplication.
1 parent b3e8249 commit bb451f3

File tree

3 files changed

+6
-16
lines changed

3 files changed

+6
-16
lines changed

cpp/ql/src/Security/CWE/CWE-190/TaintedAllocationSize.ql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ class TaintedAllocationSizeConfiguration extends TaintTracking::Configuration {
8888
readsVariable(access.getDef(), checkedVar) and
8989
nodeIsBarrierEqualityCandidate(node, access, checkedVar)
9090
)
91+
or
92+
// block flow to inside of identified allocation functions (this flow leads
93+
// to duplicate results)
94+
any(HeuristicAllocationFunction f).getAParameter() = node.asParameter()
9195
}
9296
}
9397

cpp/ql/test/query-tests/Security/CWE/CWE-190/semmle/TaintedAllocationSize/TaintedAllocationSize.expected

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@ edges
1010
| test.cpp:148:20:148:25 | call to getenv | test.cpp:152:11:152:28 | ... * ... |
1111
| test.cpp:209:8:209:23 | ReturnValue | test.cpp:241:9:241:24 | call to get_tainted_size |
1212
| test.cpp:211:14:211:19 | call to getenv | test.cpp:209:8:209:23 | ReturnValue |
13-
| test.cpp:224:23:224:23 | s | test.cpp:225:21:225:21 | s |
1413
| test.cpp:230:21:230:21 | s | test.cpp:231:21:231:21 | s |
1514
| test.cpp:237:24:237:29 | call to getenv | test.cpp:239:9:239:18 | local_size |
1615
| test.cpp:237:24:237:29 | call to getenv | test.cpp:245:11:245:20 | local_size |
17-
| test.cpp:237:24:237:29 | call to getenv | test.cpp:245:11:245:20 | local_size |
1816
| test.cpp:237:24:237:29 | call to getenv | test.cpp:247:10:247:19 | local_size |
19-
| test.cpp:245:11:245:20 | local_size | test.cpp:224:23:224:23 | s |
2017
| test.cpp:247:10:247:19 | local_size | test.cpp:230:21:230:21 | s |
2118
| test.cpp:251:2:251:9 | (reference dereference) [post update] | test.cpp:289:17:289:20 | size [post update] |
2219
| test.cpp:251:2:251:9 | (reference dereference) [post update] | test.cpp:305:18:305:21 | size [post update] |
@@ -26,11 +23,8 @@ edges
2623
| test.cpp:259:20:259:25 | call to getenv | test.cpp:263:11:263:29 | ... * ... |
2724
| test.cpp:289:17:289:20 | size [post update] | test.cpp:291:11:291:28 | ... * ... |
2825
| test.cpp:305:18:305:21 | size [post update] | test.cpp:308:10:308:27 | ... * ... |
29-
| test.cpp:348:24:348:27 | size | test.cpp:348:46:348:49 | size |
30-
| test.cpp:353:18:353:23 | call to getenv | test.cpp:355:35:355:38 | size |
3126
| test.cpp:353:18:353:23 | call to getenv | test.cpp:355:35:355:38 | size |
3227
| test.cpp:353:18:353:23 | call to getenv | test.cpp:356:35:356:38 | size |
33-
| test.cpp:355:35:355:38 | size | test.cpp:348:24:348:27 | size |
3428
nodes
3529
| test.cpp:39:27:39:30 | argv | semmle.label | argv |
3630
| test.cpp:43:38:43:44 | tainted | semmle.label | tainted |
@@ -47,15 +41,12 @@ nodes
4741
| test.cpp:152:11:152:28 | ... * ... | semmle.label | ... * ... |
4842
| test.cpp:209:8:209:23 | ReturnValue | semmle.label | ReturnValue |
4943
| test.cpp:211:14:211:19 | call to getenv | semmle.label | call to getenv |
50-
| test.cpp:224:23:224:23 | s | semmle.label | s |
51-
| test.cpp:225:21:225:21 | s | semmle.label | s |
5244
| test.cpp:230:21:230:21 | s | semmle.label | s |
5345
| test.cpp:231:21:231:21 | s | semmle.label | s |
5446
| test.cpp:237:24:237:29 | call to getenv | semmle.label | call to getenv |
5547
| test.cpp:239:9:239:18 | local_size | semmle.label | local_size |
5648
| test.cpp:241:9:241:24 | call to get_tainted_size | semmle.label | call to get_tainted_size |
5749
| test.cpp:245:11:245:20 | local_size | semmle.label | local_size |
58-
| test.cpp:245:11:245:20 | local_size | semmle.label | local_size |
5950
| test.cpp:247:10:247:19 | local_size | semmle.label | local_size |
6051
| test.cpp:251:2:251:9 | (reference dereference) [post update] | semmle.label | (reference dereference) [post update] |
6152
| test.cpp:251:18:251:23 | call to getenv | semmle.label | call to getenv |
@@ -65,11 +56,8 @@ nodes
6556
| test.cpp:291:11:291:28 | ... * ... | semmle.label | ... * ... |
6657
| test.cpp:305:18:305:21 | size [post update] | semmle.label | size [post update] |
6758
| test.cpp:308:10:308:27 | ... * ... | semmle.label | ... * ... |
68-
| test.cpp:348:24:348:27 | size | semmle.label | size |
69-
| test.cpp:348:46:348:49 | size | semmle.label | size |
7059
| test.cpp:353:18:353:23 | call to getenv | semmle.label | call to getenv |
7160
| test.cpp:355:35:355:38 | size | semmle.label | size |
72-
| test.cpp:355:35:355:38 | size | semmle.label | size |
7361
| test.cpp:356:35:356:38 | size | semmle.label | size |
7462
subpaths
7563
#select
@@ -82,14 +70,12 @@ subpaths
8270
| test.cpp:128:17:128:22 | call to malloc | test.cpp:124:18:124:23 | call to getenv | test.cpp:128:24:128:41 | ... * ... | This allocation size is derived from $@ and might overflow. | test.cpp:124:18:124:23 | call to getenv | user input (an environment variable) |
8371
| test.cpp:135:3:135:8 | call to malloc | test.cpp:133:19:133:24 | call to getenv | test.cpp:135:10:135:27 | ... * ... | This allocation size is derived from $@ and might overflow. | test.cpp:133:19:133:24 | call to getenv | user input (an environment variable) |
8472
| test.cpp:152:4:152:9 | call to malloc | test.cpp:148:20:148:25 | call to getenv | test.cpp:152:11:152:28 | ... * ... | This allocation size is derived from $@ and might overflow. | test.cpp:148:20:148:25 | call to getenv | user input (an environment variable) |
85-
| test.cpp:225:14:225:19 | call to malloc | test.cpp:237:24:237:29 | call to getenv | test.cpp:225:21:225:21 | s | This allocation size is derived from $@ and might overflow. | test.cpp:237:24:237:29 | call to getenv | user input (an environment variable) |
8673
| test.cpp:231:14:231:19 | call to malloc | test.cpp:237:24:237:29 | call to getenv | test.cpp:231:21:231:21 | s | This allocation size is derived from $@ and might overflow. | test.cpp:237:24:237:29 | call to getenv | user input (an environment variable) |
8774
| test.cpp:239:2:239:7 | call to malloc | test.cpp:237:24:237:29 | call to getenv | test.cpp:239:9:239:18 | local_size | This allocation size is derived from $@ and might overflow. | test.cpp:237:24:237:29 | call to getenv | user input (an environment variable) |
8875
| test.cpp:241:2:241:7 | call to malloc | test.cpp:211:14:211:19 | call to getenv | test.cpp:241:9:241:24 | call to get_tainted_size | This allocation size is derived from $@ and might overflow. | test.cpp:211:14:211:19 | call to getenv | user input (an environment variable) |
8976
| test.cpp:245:2:245:9 | call to my_alloc | test.cpp:237:24:237:29 | call to getenv | test.cpp:245:11:245:20 | local_size | This allocation size is derived from $@ and might overflow. | test.cpp:237:24:237:29 | call to getenv | user input (an environment variable) |
9077
| test.cpp:263:4:263:9 | call to malloc | test.cpp:259:20:259:25 | call to getenv | test.cpp:263:11:263:29 | ... * ... | This allocation size is derived from $@ and might overflow. | test.cpp:259:20:259:25 | call to getenv | user input (an environment variable) |
9178
| test.cpp:291:4:291:9 | call to malloc | test.cpp:251:18:251:23 | call to getenv | test.cpp:291:11:291:28 | ... * ... | This allocation size is derived from $@ and might overflow. | test.cpp:251:18:251:23 | call to getenv | user input (an environment variable) |
9279
| test.cpp:308:3:308:8 | call to malloc | test.cpp:251:18:251:23 | call to getenv | test.cpp:308:10:308:27 | ... * ... | This allocation size is derived from $@ and might overflow. | test.cpp:251:18:251:23 | call to getenv | user input (an environment variable) |
93-
| test.cpp:348:39:348:44 | call to malloc | test.cpp:353:18:353:23 | call to getenv | test.cpp:348:46:348:49 | size | This allocation size is derived from $@ and might overflow. | test.cpp:353:18:353:23 | call to getenv | user input (an environment variable) |
9480
| test.cpp:355:25:355:33 | call to MyMalloc1 | test.cpp:353:18:353:23 | call to getenv | test.cpp:355:35:355:38 | size | This allocation size is derived from $@ and might overflow. | test.cpp:353:18:353:23 | call to getenv | user input (an environment variable) |
9581
| test.cpp:356:25:356:33 | call to MyMalloc2 | test.cpp:353:18:353:23 | call to getenv | test.cpp:356:35:356:38 | size | This allocation size is derived from $@ and might overflow. | test.cpp:353:18:353:23 | call to getenv | user input (an environment variable) |

cpp/ql/test/query-tests/Security/CWE/CWE-190/semmle/TaintedAllocationSize/test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ size_t get_bounded_size()
222222
}
223223

224224
void *my_alloc(size_t s) {
225-
void *ptr = malloc(s); // [additional detection here]
225+
void *ptr = malloc(s);
226226

227227
return ptr;
228228
}
@@ -345,7 +345,7 @@ void equality_barrier() {
345345

346346
// --- custom allocators ---
347347

348-
void *MyMalloc1(size_t size) { return malloc(size); } // [additional detection here]
348+
void *MyMalloc1(size_t size) { return malloc(size); }
349349
void *MyMalloc2(size_t size);
350350

351351
void customAllocatorTests()

0 commit comments

Comments
 (0)