Fix CodeQL issues in PAL tests - #132233
Open
WardenGnaw wants to merge 1 commit into
Open
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Resolve incorrect printf-style argument counts and ensure buffers populated by file reads are explicitly null-terminated before string operations. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0a4c8c68-dc92-4aa0-aa6b-d570392bedeb
WardenGnaw
force-pushed
the
waan/fix-pal-test-codeql-findings
branch
from
August 12, 2026 20:53
539b9b8 to
242aeba
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses CodeQL findings in CoreCLR PALSuite tests by correcting printf-style argument lists and adding explicit null-termination after file reads before performing C-string operations.
Changes:
- Fixes several
Trace/Failcalls that had mismatched format specifiers vs. provided arguments. - Ensures buffers populated via
ReadFile/freadare explicitly null-terminated beforestrcmp/strlenusage. - Minor cleanup of stray trailing whitespace in a couple of test files.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test1/test1.cpp | Fixes missing GetLastError() argument in Trace call. |
| src/coreclr/pal/tests/palsuite/threading/SetEvent/test3/test3.cpp | Fixes missing GetLastError() argument in Fail call. |
| src/coreclr/pal/tests/palsuite/threading/ResetEvent/test3/test3.cpp | Fixes missing GetLastError() argument in Fail call. |
| src/coreclr/pal/tests/palsuite/threading/ResetEvent/test1/test1.cpp | Removes an unused format specifier from a Fail message. |
| src/coreclr/pal/tests/palsuite/threading/CreateThread/test3/test3.cpp | Fixes Trace argument count and removes trailing whitespace line. |
| src/coreclr/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test1/UnmapViewOfFile.cpp | Null-terminates a ReadFile buffer before string operations. |
| src/coreclr/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test5/mapviewoffile.cpp | Fixes Trace argument counts when reporting hFileMapping. |
| src/coreclr/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test3/MapViewOfFile.cpp | Null-terminates a ReadFile buffer before string operations. |
| src/coreclr/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test2/MapViewOfFile.cpp | Null-terminates a ReadFile buffer before string operations. |
| src/coreclr/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/createfilemapping.cpp | Fixes invalid format string for pointer value and removes trailing whitespace line. |
| src/coreclr/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/CreateFileMappingW.cpp | Fixes invalid format string for pointer value and removes trailing whitespace line. |
| src/coreclr/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/CreateFileMappingW.cpp | Fixes invalid format string for pointer values and removes trailing whitespace line. |
| src/coreclr/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/CreateFileMappingW.cpp | Fixes invalid format string for pointer value and removes trailing whitespace line. |
| src/coreclr/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/CreateFileMappingW.cpp | Fixes invalid format string for pointer value and removes trailing whitespace line. |
| src/coreclr/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/CreateFileMappingW.cpp | Fixes invalid format string for pointer value and removes trailing whitespace line. |
| src/coreclr/pal/tests/palsuite/file_io/WriteFile/test3/WriteFile.cpp | Null-terminates fread buffer before strcmp. |
| src/coreclr/pal/tests/palsuite/file_io/SetFilePointer/test3/SetFilePointer.cpp | Null-terminates ReadFile buffers before strcmp. |
| src/coreclr/pal/tests/palsuite/file_io/SetFilePointer/test2/SetFilePointer.cpp | Null-terminates ReadFile buffer before strcmp. |
| src/coreclr/pal/tests/palsuite/file_io/GetFullPathNameW/test4/test4.cpp | Fixes Trace argument count when reporting hFile. |
| src/coreclr/pal/tests/palsuite/file_io/GetFullPathNameW/test3/test3.cpp | Fixes Trace argument count when reporting hFile. |
| src/coreclr/pal/tests/palsuite/file_io/GetFullPathNameA/test4/test4.cpp | Fixes Trace argument count when reporting hFile. |
| src/coreclr/pal/tests/palsuite/file_io/GetFullPathNameA/test3/test3.cpp | Fixes Trace argument count when reporting hFile. |
| src/coreclr/pal/tests/palsuite/file_io/GetFullPathNameA/test2/test2.cpp | Fixes Trace argument count when reporting hFile. |
Review details
Suppressed comments (2)
src/coreclr/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test5/mapviewoffile.cpp:80
- Same as above:
hFileMappingis aHANDLEand should be printed with%prather than0x%lxto avoid varargs type/size mismatches on LLP64.
Trace("ERROR:%u: Able to create a MapViewOfFile with "
"hFileMapping=0x%lx.\n",
GetLastError(),
hFileMapping);
src/coreclr/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/createfilemapping.cpp:141
lpMapViewRWisLPVOID. Use%prather than0x%lxwhen formatting pointers/handles.
Trace("ERROR:%u: Failed to UnmapViewOfFile of \"0x%lx\".\n",
GetLastError(),
lpMapViewRW);
- Files reviewed: 23/23 changed files
- Comments generated: 15
- Review effort level: Lite
| return FALSE; | ||
| } | ||
|
|
||
| szReadString[dwBytesRead] = '\0'; |
Comment on lines
55
to
+58
| Trace("ERROR:%u: Able to create a MapViewOfFile with " | ||
| "hFileMapping=0x%lx.\n", | ||
| GetLastError()); | ||
| GetLastError(), | ||
| hFileMapping); |
Comment on lines
+138
to
140
| Trace("ERROR:%u: Failed to UnmapViewOfFile of \"0x%lx\".\n", | ||
| GetLastError(), | ||
| lpMapViewAddress); |
Comment on lines
+120
to
122
| Trace("ERROR:%u: Failed to UnmapViewOfFile of \"0x%lx\".\n", | ||
| GetLastError(), | ||
| lpMapViewAddress); |
Comment on lines
+144
to
146
| Trace("ERROR:%u: Failed to UnmapViewOfFile of \"0x%lx\".\n", | ||
| GetLastError(), | ||
| lpMapViewRO); |
Comment on lines
133
to
+135
| Trace("ERROR :%ld: CloseHandle failed close hFile=0x%lx.\n", | ||
| GetLastError()); | ||
| GetLastError(), | ||
| hFile); |
Comment on lines
161
to
+163
| Trace("ERROR :%ld: CloseHandle failed close hFile=0x%lx.\n", | ||
| GetLastError()); | ||
| GetLastError(), | ||
| hFile); |
Comment on lines
133
to
+135
| Trace("ERROR :%ld: CloseHandle failed close hFile=0x%lx.\n", | ||
| GetLastError()); | ||
| GetLastError(), | ||
| hFile); |
Comment on lines
158
to
+160
| Trace("ERROR :%ld: CloseHandle failed close hFile=0x%lx.\n", | ||
| GetLastError()); | ||
| GetLastError(), | ||
| hFile); |
Comment on lines
92
to
+94
| Trace("ERROR :%ld: CloseHandle failed close hFile=0x%lx.\n", | ||
| GetLastError()); | ||
| GetLastError(), | ||
| hFile); |
This was referenced Aug 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolve incorrect printf-style argument counts and ensure buffers populated by file reads are explicitly null-terminated before string operations.
Mirrors fix made in the debugger fork of the PAL.