Skip to content

Commit dbac927

Browse files
committed
Take into account that the 4th argument of openat may be omitted
This matches what is done for `open`.
1 parent 8df04c5 commit dbac927

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,18 @@ class CreatCreationExpr extends FileCreationExpr {
111111
class OpenatCreationExpr extends FileCreationExpr {
112112
OpenatCreationExpr() {
113113
this.getTarget().getName() = "openat" and
114-
this.getNumberOfArguments() = 4
114+
sets(this.getArgument(2).getValue().toInt(), o_creat())
115115
}
116116

117117
override Expr getPath() { result = this.getArgument(1) }
118118

119-
override int getMode() { result = this.getArgument(3).getValue().toInt() }
119+
override int getMode() {
120+
if exists(this.getArgument(3))
121+
then result = this.getArgument(3).getValue().toInt()
122+
else
123+
// assume anything is permitted
124+
result = 0.bitNot()
125+
}
120126
}
121127

122128
private int fopenMode() {

0 commit comments

Comments
 (0)