Skip to content

Fix CodeQL issues in PAL tests - #132233

Open
WardenGnaw wants to merge 1 commit into
dotnet:mainfrom
WardenGnaw:waan/fix-pal-test-codeql-findings
Open

Fix CodeQL issues in PAL tests#132233
WardenGnaw wants to merge 1 commit into
dotnet:mainfrom
WardenGnaw:waan/fix-pal-test-codeql-findings

Conversation

@WardenGnaw

Copy link
Copy Markdown
Contributor

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.

Copilot AI lite review requested due to automatic review settings August 12, 2026 20:51
@github-actions github-actions Bot added the area-PAL-coreclr only for closed issues label Aug 12, 2026
@azure-pipelines

Copy link
Copy Markdown
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
WardenGnaw force-pushed the waan/fix-pal-test-codeql-findings branch from 539b9b8 to 242aeba Compare August 12, 2026 20:53
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Aug 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/Fail calls that had mismatched format specifiers vs. provided arguments.
  • Ensures buffers populated via ReadFile/fread are explicitly null-terminated before strcmp/strlen usage.
  • 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: hFileMapping is a HANDLE and should be printed with %p rather than 0x%lx to 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

  • lpMapViewRW is LPVOID. Use %p rather than 0x%lx when 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-PAL-coreclr only for closed issues community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants