Skip to content

Commit 4d03082

Browse files
committed
Ensure that O_CREAT and O_TMPFILE are unique
1 parent e1ca5dd commit 4d03082

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

cpp/ql/src/Security/CWE/CWE-732/FilePermissions.qll

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,21 @@ int parseHex(string input) {
1515
}
1616

1717
int o_creat() {
18-
exists(Macro m | m.getName() = "O_CREAT" |
19-
result = parseHex(m.getBody()) or result = UnixConstants::parseOctal(m.getBody())
20-
)
18+
result =
19+
unique(int v |
20+
exists(Macro m | m.getName() = "O_CREAT" |
21+
v = parseHex(m.getBody()) or v = UnixConstants::parseOctal(m.getBody())
22+
)
23+
)
2124
}
2225

2326
int o_tmpfile() {
24-
exists(Macro m | m.getName() = "O_TMPFILE" |
25-
result = parseHex(m.getBody()) or result = UnixConstants::parseOctal(m.getBody())
26-
)
27+
result =
28+
unique(int v |
29+
exists(Macro m | m.getName() = "O_TMPFILE" |
30+
v = parseHex(m.getBody()) or v = UnixConstants::parseOctal(m.getBody())
31+
)
32+
)
2733
}
2834

2935
bindingset[n, digit]

0 commit comments

Comments
 (0)