-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathStandardLibraryInputoutputFunctionsUsed.ql
More file actions
52 lines (48 loc) · 1.92 KB
/
StandardLibraryInputoutputFunctionsUsed.ql
File metadata and controls
52 lines (48 loc) · 1.92 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* @id c/misra/standard-library-inputoutput-functions-used
* @name RULE-21-6: The Standard Library input/output functions shall not be used
* @description The use of the Standard Library input/output functions may result in undefined
* behavior.
* @kind problem
* @precision very-high
* @problem.severity error
* @tags external/misra/id/rule-21-6
* security
* correctness
* external/misra/obligation/required
*/
import cpp
import codingstandards.c.misra
private string stdInputOutput() {
result =
[
"fread", "fwrite", "fgetc", "getc", "fgets", "fputc", "putc", "fputs", "getchar", "gets",
"gets_s", "putchar", "puts", "ungetc", "scanf", "fscanf", "sscanf", "scanf_s", "fscanf_s",
"sscanf_s", "vscanf", "vfscanf", "vsscanf", "vscanf_s", "vfscanf_s", "vsscanf_s", "printf",
"fprintf", "sprintf", "snprintf", "printf_s", "fprintf_s", "sprintf_s", "snprintf_s",
"vprintf", "vfprintf", "vsprintf", "vsnprintf", "vprintf_s", "vfprintf_s", "vsprintf_s",
"vsnprintf_s",
]
}
private string wcharInputOutput() {
result =
[
"fgetwc", "getwc", "fgetsws", "fputwc", "putwc", "fputws", "getwchar", "putwchar", "ungetwc",
"wscanf", "fwscanf", "swscanf", "wscanf_s", "fwscanf_s", "swscanf_s", "vwscanf", "vfwscanf",
"vswscanf", "vwscanf_s", "vfwscanf_s", "vswscanf_s", "wprintf", "fwprintf", "swprintf",
"wprintf_s", "fwprintf_s", "swprintf_s", "snwprintf_s", "vwprintf", "vfwprintf", "vswprintf",
"vwprintf_s", "vfwprintf_s", "vswprintf_s", "vsnwprintf_s",
]
}
from FunctionCall fc, Function f
where
not isExcluded(fc, BannedPackage::standardHeaderFileUsedSignalhQuery()) and
fc.getTarget() = f and
(
f.getName() = stdInputOutput() and
f.getFile().getBaseName() = "stdio.h"
or
f.getName() = wcharInputOutput() and
f.getFile().getBaseName() = "wchar.h"
)
select fc, "Call to banned function " + f.getName() + "."