Skip to content

Commit faadcd9

Browse files
committed
C++: Exclude memsets that clear a variable that has no other uses.
1 parent 2777ca4 commit faadcd9

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

cpp/ql/src/Security/CWE/CWE-014/MemsetMayBeDeleted.ql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ where
5252
// Reference-typed variables get special treatment in `variableAddressEscapesTree` so we leave them
5353
// out of this query.
5454
not v.getUnspecifiedType() instanceof ReferenceType and
55+
// `v` is not only just used in the call to `memset`.
56+
exists(Access acc |
57+
acc = v.getAnAccess() and not call.getArgument(0).getAChild*() = acc and not acc.isUnevaluated()
58+
) and
5559
// There is no later use of `v`.
5660
not v.getAnAccess() = call.getASuccessor*() and
5761
// Not using the `-fno-builtin-memset` flag

0 commit comments

Comments
 (0)