1+ // Copyright (c) Microsoft Corporation.
2+ // Licensed under the MIT license.
3+ /**
4+ * @id cpp/drivers/multiple-function-class-annotations
5+ * @kind problem
6+ * @name Multiple Function Class Annotations
7+ * @description Function is annotated with more than one function class. All but one will be ignored.
8+ * @platform Desktop
9+ * @feature.area Multiple
10+ * @impact Insecure Coding Practice
11+ * @repro.text This warning can be generated when there is a chain of typedefs.
12+ 13+ * @opaqueid CQLD-c28177
14+ * @problem.severity warning
15+ * @precision medium
16+ * @tags correctness
17+ * @scope domainspecific
18+ * @query-version v1
19+ */
20+
21+ import cpp
22+ import drivers.libraries.SAL
23+
24+ class FunctionClassAnnotatedTypedef extends TypedefType {
25+ FunctionClassAnnotation funcAnnotation ;
26+
27+ FunctionClassAnnotatedTypedef ( ) { funcAnnotation .getTypedefDeclarations ( ) = this }
28+
29+ FunctionClassAnnotation getFuncClassAnnotation ( ) { result = funcAnnotation }
30+ }
31+
32+ class FunctionClassAnnotation extends SALAnnotation {
33+ string annotationName ;
34+
35+ FunctionClassAnnotation ( ) {
36+ this .getMacroName ( ) = [ "__drv_functionClass" , "_Function_class_" ] and
37+ annotationName = this .getMacroName ( )
38+ }
39+ }
40+
41+ class AnnotatedFunction extends Function {
42+ FunctionClassAnnotation funcClassAnnotation ;
43+
44+ AnnotatedFunction ( ) {
45+ funcClassAnnotation .getMacroName ( ) = [ "__drv_functionClass" , "_Function_class_" ] and
46+ exists ( FunctionDeclarationEntry fde |
47+ fde = this .getADeclarationEntry ( ) and
48+ funcClassAnnotation .getDeclarationEntry ( ) = fde
49+ )
50+ or
51+ exists ( FunctionDeclarationEntry fde |
52+ fde .getFunction ( ) = this and
53+ fde .getTypedefType ( ) .( FunctionClassAnnotatedTypedef ) .getFuncClassAnnotation ( ) =
54+ funcClassAnnotation
55+ )
56+ }
57+
58+ FunctionClassAnnotation getFuncClassAnnotation ( ) { result = funcClassAnnotation }
59+ }
60+
61+ from AnnotatedFunction f
62+ where
63+ count ( f .getFuncClassAnnotation ( ) ) > 1
64+ select f , "Function is annotated with more than one function class. All but one will be ignored."
0 commit comments