Skip to content

Commit f1d346f

Browse files
Query suite updates (#172)
* Suite updates to add additional queries * update windows_driver_mustfix.qls * update readme * qlpack version update * update query packs * update github action * update query suites with missing query * update version * sort query suites * add missing queries * Fix opaqueid fields. For some reason opaque-id causes issues with sarif reader. * fix changed file
1 parent c88a2a1 commit f1d346f

File tree

17 files changed

+194
-140
lines changed

17 files changed

+194
-140
lines changed

.github/workflows/build-codeql.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414
workflow_dispatch:
1515

1616
env:
17-
CODEQL_VERSION: 2.20.1
17+
CODEQL_VERSION: 2.20.4
1818

1919
jobs:
2020
build:
@@ -52,11 +52,11 @@ jobs:
5252

5353
- name: Build must-fix driver suite
5454
shell: cmd
55-
run: .\codeql-cli\codeql.cmd query compile --check-only windows_mustfix_partial.qls
55+
run: .\codeql-cli\codeql.cmd query compile --check-only mustfix.qls
5656

5757
- name: Build recommended driver suite
5858
shell: cmd
59-
run: .\codeql-cli\codeql.cmd query compile --check-only windows_recommended_partial.qls
59+
run: .\codeql-cli\codeql.cmd query compile --check-only recommended.qls
6060

6161
- name: Build CA ported queries
6262
shell: cmd
@@ -196,15 +196,15 @@ jobs:
196196
shell: pwsh
197197
run:
198198
$qlpack_diff = git diff HEAD~1:src/qlpack.yml src/qlpack.yml;
199-
$rec_diff = git diff HEAD~1:src/windows-driver-suites/windows_recommended_partial.qls src/windows-driver-suites/windows_recommended_partial.qls;
200-
$mf_diff = git diff HEAD~1:src/windows-driver-suites/windows_mustfix_partial.qls src/windows-driver-suites/windows_mustfix_partial.qls;
199+
$rec_diff = git diff HEAD~1:src/windows-driver-suites/recommended.qls src/windows-driver-suites/recommended.qls;
200+
$mf_diff = git diff HEAD~1:src/windows-driver-suites/mustfix.qls src/windows-driver-suites/mustfix.qls;
201201
if (!$qlpack_diff -and ($rec_diff -or $mf_diff)) { "Query suite file updated without updating qlpack version"; exit 1 }
202202

203203
$last_qlpack_commit = git log -n 1 --pretty=format:%H -- src/qlpack.yml;
204204
$qlpack_changes =git show $last_qlpack_commit -- .\src\qlpack.yml;
205205

206-
$last_mf_commit = git log -n 1 --pretty=format:%H -- src/windows-driver-suites/windows_mustfix_partial.qls;
207-
$last_rec_commit = git log -n 1 --pretty=format:%H -- src/windows-driver-suites/windows_recommended_partial.qls;
206+
$last_mf_commit = git log -n 1 --pretty=format:%H -- src/windows-driver-suites/mustfix.qls;
207+
$last_rec_commit = git log -n 1 --pretty=format:%H -- src/windows-driver-suites/recommended.qls;
208208
$commits_since_qlpack_change = [int](git rev-list --count HEAD...$last_qlpack_commit);
209209
$commits_since_mf_change = [int](git rev-list --count HEAD...$last_mf_commit);
210210
$commits_since_rec_change = [int](git rev-list --count HEAD...$last_rec_commit);
@@ -214,7 +214,7 @@ jobs:
214214

215215
try{$old_qlpack_version = [version]($qlpack_changes -match "-version").Substring(10);} catch {"Changed qlpack.yml without updating version"; exit 1 }
216216
try{$new_qlpack_version = [version]($qlpack_changes -match "\+version").Substring(10);} catch {"Changed qlpack.yml without updating version"; exit 1 }
217-
if ($new_qlpack_version -gt $old_qlpack_version) { exit 0 } else { "qlpack.yml version not incremented"; exit 1 }
217+
if ($new_qlpack_version -gt $old_qlpack_version) { exit 0 } else { "qlpack.yml version not incremented. Previously updated to version $old_qlpack_version, current version $new_qlpack_version"; exit 1 }
218218

219219
test-create-dvl:
220220
runs-on: windows-latest

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This repository contains open-source components for supplemental use in developi
66

77
| CodeQL CLI version | microsoft/windows-drivers qlpack version | codeql/cpp-queries version |Associated Repo Branch|
88
|--------------------------|-------------------------------------------|------------------------|------------------------|
9-
| 2.15.4 | latest | latest |main |
9+
| latest | latest | latest |main |
1010

1111
### For Windows Hardware Compatibility Program Use
1212

src/codeql-pack.lock.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ dependencies:
1111
version: 1.0.16
1212
codeql/ssa:
1313
version: 1.0.16
14+
codeql/suite-helpers:
15+
version: 1.0.16
1416
codeql/tutorial:
1517
version: 1.0.16
1618
codeql/typeflow:
@@ -21,4 +23,6 @@ dependencies:
2123
version: 2.0.3
2224
codeql/xml:
2325
version: 1.0.16
26+
microsoft/cpp-queries:
27+
version: 0.0.2
2428
compiled: false

src/drivers/general/queries/PointerVariableSize/PointerVariableSize.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import cpp
2323

24-
from SizeofExprOperator e, VariableAccess va, AddressOfExpr a
24+
from SizeofExprOperator e, VariableAccess va
2525
where
2626
va = e.getExprOperand() and
2727
va.getTarget().getUnspecifiedType() instanceof PointerType

src/drivers/kmdf/queries/experimental/DeviceInitApi/DeviceInitApi.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @kind path-problem
88
* @problem.severity error
99
* @precision medium
10-
* @id cpp/windows/wdk/kmdf/DeviceInitApi
10+
* @id cpp/windows/wdk/kmdf/device-init-api
1111
* @tags correctness
1212
* @query-version v1
1313
*/

src/drivers/test/build_create_analyze_test.py

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def upload_results_to_azure(file_to_upload, file_name, file_directory):
189189
file_service = FileService(connection_string=args.connection_string)
190190
file_service.create_file_from_path(share_name=args.share_name, file_name=file_name, directory_name=file_directory, local_file_path=file_to_upload, content_settings=ContentSettings(content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'))
191191

192-
def download_file_from_azure(file_to_download, file_name, file_directory):
192+
def download_file_from_azure(out_file_path, file_name, file_directory):
193193
"""
194194
Downloads a file from Azure.
195195
@@ -200,7 +200,7 @@ def download_file_from_azure(file_to_download, file_name, file_directory):
200200
None
201201
"""
202202
file_service = FileService(connection_string=args.connection_string)
203-
file = file_service.get_file_to_path(share_name=args.share_name, file_name=file_name, directory_name=file_directory, file_path=file_to_download)
203+
file = file_service.get_file_to_path(share_name=args.share_name, file_name=file_name, directory_name=file_directory, file_path=out_file_path)
204204
return file.name
205205

206206
def get_git_root():
@@ -250,7 +250,7 @@ def find_ql_test_paths(directory, extension):
250250
# exclude wfp folder until correct test template is added
251251
ignore_paths = ["wfp", "QueryTemplate", "TestTemplate", ".vs"]
252252
root = root.replace("\\", "/")
253-
if any(path in ignore_paths for x in root.split("/")):
253+
if any(path in ignore_paths for path in root.split("/")):
254254
print_conditionally("Skipping: " + root)
255255
continue
256256
if "TestTemplate" in root:
@@ -265,6 +265,7 @@ def find_ql_test_paths(directory, extension):
265265
ql_obj = ql_test_attributes(use_ntifs=use_ntifs, use_cpp=use_cpp)
266266
ql_obj.set_use_cpp(use_cpp)
267267
ql_files_map[os.path.join(root, file)] = ql_obj
268+
print_conditionally("Found: " + os.path.join(root, file))
268269

269270
return ql_files_map
270271

@@ -780,14 +781,14 @@ def run_tests_external_drivers(ql_tests_dict):
780781
result_file = "external_drivers_results.xlsx"
781782
with pd.ExcelWriter(result_file) as writer:
782783
health_df.to_excel(writer, sheet_name="Results")
783-
codeql_version_df.to_excel(writer, sheet_name="CodeQL Version")
784-
codeql_packs_df.to_excel(writer, sheet_name="CodeQL Packs")
785-
system_info_df.to_excel(writer, sheet_name="System Info")
784+
local_codeql_version_df.to_excel(writer, sheet_name="Local CodeQL Version")
785+
local_codeql_packs_df.to_excel(writer, sheet_name="Local CodeQL Packs")
786+
local_system_info_df.to_excel(writer, sheet_name="Local System Info")
786787
with pd.ExcelWriter("detailed" + result_file) as writer:
787788
detailed_health_df.to_excel(writer, sheet_name="Results")
788-
codeql_version_df.to_excel(writer, sheet_name="CodeQL Version")
789-
codeql_packs_df.to_excel(writer, sheet_name="CodeQL Packs")
790-
system_info_df.to_excel(writer, sheet_name="System Info")
789+
local_codeql_version_df.to_excel(writer, sheet_name="Local CodeQL Version")
790+
local_codeql_packs_df.to_excel(writer, sheet_name="Local CodeQL Packs")
791+
local_system_info_df.to_excel(writer, sheet_name="Local System Info")
791792
if args.compare_results:
792793
compare_health_results("detailed"+result_file)
793794
compare_health_results(result_file)
@@ -838,9 +839,8 @@ def compare_health_results(curr_results_path):
838839
try:
839840
prev_results = 'azure-'+curr_results_path
840841
print_conditionally("Downloading previous results from Azure: " + prev_results)
841-
temp_file = download_file_from_azure(file_to_download=prev_results,
842+
_ = download_file_from_azure(out_file_path=prev_results,
842843
file_name=curr_results_path, file_directory="")
843-
print_conditionally("Downloaded previous results: " + temp_file)
844844

845845
except Exception as e:
846846
if "ResourceNotFound" in str(e):
@@ -853,7 +853,7 @@ def compare_health_results(curr_results_path):
853853
prev_results_df = pd.read_excel(prev_results, index_col=0, sheet_name=0)
854854
prev_results_codeql_version_df = pd.read_excel(prev_results, index_col=0, sheet_name=1)
855855
prev_results_codeql_packs_df = pd.read_excel(prev_results, index_col=0, sheet_name=2)
856-
prev_results_system_info_df = pd.read_excel(prev_results, index_col=0, sheet_name=3)
856+
prev_results_local_system_info_df = pd.read_excel(prev_results, index_col=0, sheet_name=3)
857857
curr_results_df = pd.read_excel(curr_results_path, index_col=0, sheet_name=0)
858858
print_conditionally("Comparing results...")
859859
print_conditionally("Previous results: ", prev_results)
@@ -879,16 +879,29 @@ def compare_health_results(curr_results_path):
879879

880880
with pd.ExcelWriter("diff" + curr_results_path) as writer:
881881
diff_results.to_excel(writer, sheet_name="Diff")
882-
codeql_version_df.to_excel(writer, sheet_name="Current CodeQL Version")
883-
codeql_packs_df.to_excel(writer, sheet_name="Current CodeQL Packs")
884-
system_info_df.to_excel(writer, sheet_name="Current System Info")
885-
prev_results_codeql_version_df.to_excel(writer, sheet_name="Previous CodeQL Version")
886-
prev_results_codeql_packs_df.to_excel(writer, sheet_name="Previous CodeQL Packs")
887-
prev_results_system_info_df.to_excel(writer, sheet_name="Previous System Info")
882+
local_codeql_version_df.to_excel(writer, sheet_name="Local CodeQL Version")
883+
local_codeql_packs_df.to_excel(writer, sheet_name="Local CodeQL Packs")
884+
local_system_info_df.to_excel(writer, sheet_name="Local System Info")
885+
prev_results_codeql_version_df.to_excel(writer, sheet_name="Last Stored CodeQL Version")
886+
prev_results_codeql_packs_df.to_excel(writer, sheet_name="Last Stored CodeQL Packs")
887+
prev_results_local_system_info_df.to_excel(writer, sheet_name="Last Stored System Info")
888888
print_conditionally("Saved diff results")
889889

890890
if not args.local_result_storage:
891891
# upload new results to Azure
892+
if args.overwrite_azure_results:
893+
print("!! Overwriting Azure results !!")
894+
print("Type 'yes' to confirm")
895+
confirm = input()
896+
if confirm != "yes":
897+
print("Exiting")
898+
exit(1)
899+
else:
900+
double_confirm = input("Are you sure?")
901+
if double_confirm != "yes":
902+
print("Exiting")
903+
exit(1)
904+
892905
if args.overwrite_azure_results:
893906
print_conditionally("Uploading results")
894907
upload_results_to_azure(file_to_upload=curr_results_path,
@@ -934,14 +947,14 @@ def run_tests(ql_tests_dict):
934947
result_file = "functiontestresults.xlsx"
935948
with pd.ExcelWriter(result_file) as writer:
936949
health_df.to_excel(writer, sheet_name="Results")
937-
codeql_version_df.to_excel(writer, sheet_name="CodeQL Version")
938-
codeql_packs_df.to_excel(writer, sheet_name="CodeQL Packs")
939-
system_info_df.to_excel(writer, sheet_name="System Info")
950+
local_codeql_version_df.to_excel(writer, sheet_name="Local CodeQL Version")
951+
local_codeql_packs_df.to_excel(writer, sheet_name="Local CodeQL Packs")
952+
local_system_info_df.to_excel(writer, sheet_name="Local System Info")
940953
with pd.ExcelWriter("detailed"+result_file) as writer:
941954
detailed_health_df.to_excel(writer, sheet_name="Results")
942-
codeql_version_df.to_excel(writer, sheet_name="CodeQL Version")
943-
codeql_packs_df.to_excel(writer, sheet_name="CodeQL Packs")
944-
system_info_df.to_excel(writer, sheet_name="System Info")
955+
local_codeql_version_df.to_excel(writer, sheet_name="Local CodeQL Version")
956+
local_codeql_packs_df.to_excel(writer, sheet_name="Local CodeQL Packs")
957+
local_system_info_df.to_excel(writer, sheet_name="Local System Info")
945958
if args.compare_results:
946959
compare_health_results("detailed"+result_file)
947960
compare_health_results(result_file)
@@ -1008,26 +1021,18 @@ def find_sln_file(path):
10081021
parser.add_argument('--overwrite_azure_results', help='Overwrite Azure results',action='store_true',required=False,)
10091022
parser.add_argument('--build_database_only', help='Build database only',action='store_true',required=False,)
10101023
args = parser.parse_args()
1011-
1012-
if args.overwrite_azure_results:
1013-
print("Overwriting Azure results")
1014-
print("Type 'yes' to confirm")
1015-
confirm = input()
1016-
if confirm != "yes":
1017-
print("Exiting")
1018-
exit(1)
1019-
1024+
10201025
if args.codeql_path:
10211026
codeql_path = args.codeql_path
10221027
else:
10231028
codeql_path = "codeql"
10241029

10251030
codeql_version = subprocess.run([codeql_path, "version"], capture_output=True) # test codeql is working
1026-
codeql_version_df = pd.DataFrame([x for x in codeql_version.stdout.decode().split('\n')])
1031+
local_codeql_version_df = pd.DataFrame([x for x in codeql_version.stdout.decode().split('\n')])
10271032
codeql_packs = subprocess.run([codeql_path, "resolve", "qlpacks"], capture_output=True)
1028-
codeql_packs_df = pd.DataFrame([x for x in codeql_packs.stdout.decode().split('\n')])
1033+
local_codeql_packs_df = pd.DataFrame([x for x in codeql_packs.stdout.decode().split('\n')])
10291034
system_info = subprocess.run(["systeminfo"], capture_output=True)
1030-
system_info_df = pd.DataFrame([x for x in system_info.stdout.decode().split('\n')])
1035+
local_system_info_df = pd.DataFrame([x for x in system_info.stdout.decode().split('\n')])
10311036

10321037

10331038
if args.compare_results_no_build:

src/microsoft/Likely Bugs/Boundary Violations/PaddingByteInformationDisclosure.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
// Licensed under the MIT license.
33

44
/**
5+
* @id cpp/paddingbyteinformationdisclosure
56
* @name Possible information leakage from uninitialized padding bytes.
67
* @description A newly allocated struct or class that is initialized member-by-member may
78
* leak information if it includes padding bytes.
89
* @kind problem
910
* @problem.severity warning
1011
* @tags security
1112
* external/cwe/cwe-200
12-
* @opaque-id SM02320
13+
* @opaqueid SM02320
1314
* @microsoft.severity Important
14-
* @id cpp/paddingbyteinformationdisclosure
1515
*/
1616

1717
import cpp

src/microsoft/Likely Bugs/Conversion/BadOverflowGuard.ql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license.
33

44
/**
5+
* @id cpp/badoverflowguard
56
* @name Bad overflow check
67
* @description Checking for overflow of an addition by comparing against one
78
* of the arguments of the addition fails if the size of all the
@@ -12,9 +13,9 @@
1213
* @tags security
1314
* external/cwe/cwe-190
1415
* external/cwe/cwe-191
15-
* @opaque-id SM02324
1616
* @microsoft.severity Important
17-
* @id cpp/badoverflowguard
17+
* @opaqueid SM02324
18+
*
1819
*/
1920

2021
import cpp

src/microsoft/Likely Bugs/Conversion/InfiniteLoop.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license.
33

44
/**
5+
* @id cpp/infiniteloop
56
* @name Comparison of narrow type with wide type in loop condition
67
* @description Comparisons between types of different widths in a loop
78
* condition can cause the loop to fail to terminate.
@@ -11,9 +12,8 @@
1112
* security
1213
* external/cwe/cwe-190
1314
* external/cwe/cwe-197
14-
* @opaque-id SM02323
15+
* @opaqueid SM02323
1516
* @microsoft.severity Important
16-
* @id cpp/infiniteloop
1717
*/
1818

1919
import cpp

src/microsoft/Likely Bugs/UninitializedPtrField.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
// Licensed under the MIT license.
33

44
/**
5+
* @id cpp/uninitializedptrfield
56
* @name Dereference of potentially uninitialized pointer field
67
* @description A pointer field which was not initialized during or since class
78
* construction will cause a null pointer dereference.
89
* @kind problem
910
* @problem.severity warning
1011
* @tags security
1112
* external/cwe/cwe-476
12-
* @opaque-id SM02310
13+
* @opaqueid SM02310
1314
* @microsoft.severity Important
14-
* @id cpp/uninitializedptrfield
1515
*/
1616

1717
import cpp

0 commit comments

Comments
 (0)