-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathFopenWithNonExclusiveFileCreationMode.ql
More file actions
37 lines (34 loc) · 1.16 KB
/
FopenWithNonExclusiveFileCreationMode.ql
File metadata and controls
37 lines (34 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* @id c/cert/fopen-with-non-exclusive-file-creation-mode
* @name FIO03-C: Do not make assumptions about fopen() and file creation
* @description Usage of fopen() without the proper exclusion mode can lead to a program overwriting
* over accessing an unintended file.
* @kind problem
* @precision high
* @problem.severity error
* @tags external/cert/id/fio03-c
* correctness
* security
* external/cert/obligation/recommendation
*/
import cpp
import codingstandards.c.cert
import codingstandards.cpp.alertreporting.PrintExpr
import codingstandards.cpp.standardlibrary.FileAccess
class PrettyPrintExpr extends Expr {
PrettyPrintExpr() {
exists(FOpenCall fopen | this.getParent*() = fopen.getMode()) and
(
this instanceof BinaryOperation
or
this instanceof Literal
)
}
}
from FOpenCall fopen, string modeStr
where
not isExcluded(fopen, IO5Package::fopenWithNonExclusiveFileCreationModeQuery()) and
fopen.mayCreate() and
not fopen.isExclusiveMode() and
modeStr = PrintExpr<PrettyPrintExpr>::print(fopen.getMode())
select fopen, "Call to create file with non-exclusive creation mode '" + modeStr + "'."