Skip to content

Commit bdfde88

Browse files
authored
Merge pull request #7630 from JarLob/patch-2
C++: Reduce FPs in IncorrectPrivilegeAssignment.ql
2 parents 55f787b + a1b0315 commit bdfde88

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

cpp/ql/src/experimental/Security/CWE/CWE-266/IncorrectPrivilegeAssignment.ql

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,15 @@ where
5353
fctmp.getTarget().hasGlobalOrStdName("fopen") or
5454
fctmp.getTarget().hasGlobalOrStdName("open")
5555
) and
56-
not fctmp.getArgument(1).getValue().matches("r%") and
56+
(
57+
fctmp.getArgument(1).getValue().matches("%a%") or
58+
fctmp.getArgument(1).getValue().matches("%w%") or
59+
// unfortunately cannot use numeric value here because // O_CREAT is defined differently on different OSes:
60+
// https://github.com/red/red/blob/92feb0c0d5f91e087ab35fface6906afbf99b603/runtime/definitions.reds#L477-L491
61+
// this may introduce false negatives
62+
fctmp.getArgument(1).(BitwiseOrExpr).getAChild*().getValueText().matches("O_CREAT") or
63+
fctmp.getArgument(1).getValueText().matches("%O_CREAT%")
64+
) and
5765
fctmp.getNumberOfArguments() = 2 and
5866
not fctmp.getArgument(0).getValue() = "/dev/null" and
5967
fcsnd = fctmp

0 commit comments

Comments
 (0)