Skip to content

Commit bd859d9

Browse files
committed
Address review comments
1 parent 5b8f56d commit bd859d9

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class OpenCreationExpr extends FileCreationWithOptionalModeExpr {
9898
override predicate hasModeArgument() { exists(this.getArgument(2)) }
9999

100100
override int getMode() {
101-
if hasModeArgument()
101+
if this.hasModeArgument()
102102
then result = this.getArgument(2).getValue().toInt()
103103
else
104104
// assume anything is permitted
@@ -125,7 +125,7 @@ class OpenatCreationExpr extends FileCreationWithOptionalModeExpr {
125125
override predicate hasModeArgument() { exists(this.getArgument(3)) }
126126

127127
override int getMode() {
128-
if hasModeArgument()
128+
if this.hasModeArgument()
129129
then result = this.getArgument(3).getValue().toInt()
130130
else
131131
// assume anything is permitted

cpp/ql/src/Security/CWE/CWE-732/OpenCallMissingModeArgument.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @name File opened with O_CREAT flag but without mode argument
33
* @description Opening a file with the O_CREAT flag but without mode argument reads arbitrary bytes from the stack.
44
* @kind problem
5-
* @problem.severity warning
5+
* @problem.severity error
66
* @security-severity 7.8
77
* @precision medium
88
* @id cpp/open-call-with-mode-argument
@@ -16,4 +16,4 @@ import FilePermissions
1616
from FileCreationWithOptionalModeExpr fc
1717
where not fc.hasModeArgument()
1818
select fc,
19-
"A file is created here without providing a mode argument, which may leak bits from the stack"
19+
"A file is created here without providing a mode argument, which may leak bits from the stack."
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
typedef unsigned int mode_t;
22

3-
#define O_CREAT 0100
3+
#define O_APPEND 0010
4+
#define O_CREAT 0100
45

56
int open(const char *pathname, int flags, ...);
67

@@ -9,8 +10,10 @@ int openat(int dirfd, const char *pathname, int flags, ...);
910
const char *a_file = "/a_file";
1011

1112
void test_open() {
12-
open(a_file, O_CREAT);
13-
open(a_file, O_CREAT, 0);
14-
openat(0, a_file, O_CREAT);
15-
openat(0, a_file, O_CREAT, 0);
13+
open(a_file, O_APPEND); // GOOD
14+
open(a_file, O_CREAT); // BAD
15+
open(a_file, O_CREAT, 0); // GOOD
16+
openat(0, a_file, O_APPEND); // GOOD
17+
openat(0, a_file, O_CREAT); // BAD
18+
openat(0, a_file, O_CREAT, 0); // GOOD
1619
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| OpenCallMissingModeArgument.c:12:3:12:6 | call to open | A file is created here without providing a mode argument, which may leak bits from the stack |
2-
| OpenCallMissingModeArgument.c:14:3:14:8 | call to openat | A file is created here without providing a mode argument, which may leak bits from the stack |
1+
| OpenCallMissingModeArgument.c:14:3:14:6 | call to open | A file is created here without providing a mode argument, which may leak bits from the stack. |
2+
| OpenCallMissingModeArgument.c:17:3:17:8 | call to openat | A file is created here without providing a mode argument, which may leak bits from the stack. |

0 commit comments

Comments
 (0)