-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathFopenWithNonExclusiveFileCreationMode.ql
More file actions
38 lines (34 loc) · 1.09 KB
/
FopenWithNonExclusiveFileCreationMode.ql
File metadata and controls
38 lines (34 loc) · 1.09 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
38
/**
* @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() {
this instanceof BinaryOperation
or
this instanceof Literal
}
}
string prettyPrint(Expr e) {
result = PrintExpr<PrettyPrintExpr>::print(e)
}
from FOpenCall fopen
where
not isExcluded(fopen, IO5Package::fopenWithNonExclusiveFileCreationModeQuery()) and
fopen.mayCreate() and
not fopen.isExclusiveMode()
select fopen,
"Call to create file with non-exclusive creation mode '" + prettyPrint(fopen.getMode()) + "'."