|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT license. |
| 3 | +/** |
| 4 | + * @id cpp/drivers/annotation-syntax |
| 5 | + * @kind problem |
| 6 | + * @name Annotation syntax error |
| 7 | + * @description A syntax error in the annotations was found for the property in the function. |
| 8 | + * @platform Desktop |
| 9 | + * @feature.area Multiple |
| 10 | + * @impact Annotations |
| 11 | + * @repro.text |
| 12 | + |
| 13 | + * @opaqueid CQLD-C28266 |
| 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 | +from SALAnnotation sa |
| 25 | +where |
| 26 | + // restoreIRQLGlobal was not on the whole function |
| 27 | + // saveIRQLGlobal was not on the whole function |
| 28 | + ( |
| 29 | + sa.toString().matches("%restoresIRQLGlobal%") or //restoreIRQLGlobal //__drv_restoresIRQLGlobal //_IRQL_restores_global_ |
| 30 | + sa.toString().matches("%_IRQL_saves_global_%") or //restoreIRQLGlobal //__drv_restoresIRQLGlobal //_IRQL_restores_global_ |
| 31 | + sa.toString().matches("%savesIRQLGlobal%") or //saveIRQLGlobal //__drv_savesIRQLGlobal //_IRQL_saves_global_ |
| 32 | + sa.toString().matches("%_IRQL_restores_global_%") |
| 33 | + ) and |
| 34 | + exists(SALParameter sp | sp.getAnnotation() = sa) |
| 35 | + or |
| 36 | + ( |
| 37 | + sa.toString().matches("%_When_%") or |
| 38 | + sa.toString().matches("%drv_when%") |
| 39 | + ) and |
| 40 | + ( |
| 41 | + //_Kernel_clear_do_init_ was not \"yes\" or \"no\"") |
| 42 | + exists(int i | |
| 43 | + sa.getUnexpandedArgument(i).toString().matches("%_Kernel_clear_do_init_%") and |
| 44 | + not sa.getUnexpandedArgument(i).toString().matches("_Kernel_clear_do_init_(%yes%)") and |
| 45 | + not sa.getUnexpandedArgument(i).toString().matches("_Kernel_clear_do_init_(%no%)") |
| 46 | + ) |
| 47 | + or |
| 48 | + //__drv_dispatchType cannot be used with __drv_when |
| 49 | + exists(int i | sa.getUnexpandedArgument(i).toString().matches("%__drv_dispatchType%")) |
| 50 | + ) |
| 51 | + or |
| 52 | + sa.toString().matches("%_Kernel_clear_do_init_%") and |
| 53 | + not sa.getUnexpandedArgument(0).toString().toLowerCase().matches("\"yes\"") and |
| 54 | + not sa.getUnexpandedArgument(0).toString().toLowerCase().matches("\"no\"") |
| 55 | + or |
| 56 | + //__drv_dispatch value out of range val > 63 || val < -1 |
| 57 | + sa.toString().matches("%drv_dispatch%") and |
| 58 | + ( |
| 59 | + sa.getUnexpandedArgument(0).toInt() > 63 or |
| 60 | + sa.getUnexpandedArgument(0).toInt() < -1 |
| 61 | + ) |
| 62 | +select sa, "Possible annotation syntax error" |
0 commit comments