-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathMultipleFunctionClassAnnotations.ql
More file actions
65 lines (55 loc) · 1.97 KB
/
MultipleFunctionClassAnnotations.ql
File metadata and controls
65 lines (55 loc) · 1.97 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
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/**
* @id cpp/drivers/multiple-function-class-annotations
* @kind problem
* @name Multiple Function Class Annotations
* @description Function is annotated with more than one function class. All but one will be ignored.
* @platform Desktop
* @feature.area Multiple
* @impact Insecure Coding Practice
* @repro.text This warning can be generated when there is a chain of typedefs.
* @owner.email sdat@microsoft.com
* @opaqueid CQLD-c28177
* @problem.severity warning
* @precision medium
* @tags correctness
* ca_ported
* @scope domainspecific
* @query-version v1
*/
import cpp
import drivers.libraries.SAL
class FunctionClassAnnotatedTypedef extends TypedefType {
FunctionClassAnnotation funcAnnotation;
FunctionClassAnnotatedTypedef() { funcAnnotation.getTypedefDeclarations() = this }
FunctionClassAnnotation getFuncClassAnnotation() { result = funcAnnotation }
}
class FunctionClassAnnotation extends SALAnnotation {
string annotationName;
FunctionClassAnnotation() {
this.getMacroName() = ["__drv_functionClass", "_Function_class_"] and
annotationName = this.getMacroName()
}
}
class AnnotatedFunction extends Function {
FunctionClassAnnotation funcClassAnnotation;
AnnotatedFunction() {
funcClassAnnotation.getMacroName() = ["__drv_functionClass", "_Function_class_"] and
exists(FunctionDeclarationEntry fde |
fde = this.getADeclarationEntry() and
funcClassAnnotation.getDeclarationEntry() = fde
)
or
exists(FunctionDeclarationEntry fde |
fde.getFunction() = this and
fde.getTypedefType().(FunctionClassAnnotatedTypedef).getFuncClassAnnotation() =
funcClassAnnotation
)
}
FunctionClassAnnotation getFuncClassAnnotation() { result = funcClassAnnotation }
}
from AnnotatedFunction f
where
count(f.getFuncClassAnnotation() ) > 1
select f, "Function is annotated with more than one function class. All but one will be ignored."