Repository navigation
Fix format-string misuse in PAL_GetTransportName - #137010
Merged
Merged
Conversation
PAL_GetTransportName built the IPC transport name by concatenating the directory (GetTempPathA, i.e. $TMPDIR, or the macOS app-group container folder) with "%s-%d-%llu-%s" and then using the result as the snprintf format string. A directory containing '%' (e.g. TMPDIR=/tmp/%s%n/) made snprintf consume the wrong arguments, dereference integers as pointers, or perform %n writes. This runs at every startup via the diagnostics server and the debugger transport pipes. Pass the directory as a "%s" argument instead, cast the disambiguation key for %llu explicitly, and replace the debug-only assert with a real truncation/error check that leaves the name empty on failure (the existing failure convention for callers). The resulting name is byte-for-byte identical for paths without '%', so debuggers and diagnostic tools that compute it independently are unaffected. Also read the directory through the PathCharString rather than the raw buffer pointer, which could be stale after GetApplicationContainerFolder reallocates, and reject GetTempPathA results that leave no room for the name.
filipnavara
marked this pull request as ready for review
November 5, 2026 10:32
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
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.
PAL_GetTransportNamebuilds the IPC transport name (the diagnostics server socketdotnet-diagnostic-<pid>-<key>-socketand the debugger transport pipes) by concatenating the directory with"%s-%d-%llu-%s". The directory comes fromGetTempPathA, meaning$TMPDIR, or on Apple with an application group ID, from the app-group container folder. The concatenated string was then used as thesnprintfformat:If the directory contains
%(for exampleTMPDIR=/tmp/%s%n/),snprintftakes the wrong arguments: it can read an integer as a pointer for%sor write through%n. This code runs at every startup, from the diagnostics server (ds_rt_transport_get_default_name) and from the debugger pipe setup.NativeAOT already does this correctly in
ds_rt_aot_transport_get_default_name(src/coreclr/nativeaot/Runtime/eventpipe/ds-rt-aot.cpp). It passes the directory as an argument to a constant format:Changes
snprintfas a%sargument with a literal format string, matching NativeAOT. Thestrncat_sstep and theIpcNameFormatglobal are removed. Because the format is now a literal,-Wformatcan check the arguments.unsigned long longfor%llu._ASSERTEon the result with a real check. If the name is truncated orsnprintffails,nameis left empty, which is the function's existing failure convention.PathCharStringinstead of the raw buffer pointer. On the Apple app-group path,GetApplicationContainerFoldercan reallocate the string, which would leave that pointer pointing at freed memory. Also rejectGetTempPathAresults that leave no room for the name.For directories without
%, the generated name is byte-for-byte the same as before, so debuggers and diagnostic tools that compute it independently (dotnet-trace, dotnet-counters, dbgshim) still connect.Testing
./build.sh clr.runtime -c Debugon osx-arm64.DOTNET_DefaultDiagnosticPortSuspend=1and listed the diagnostics socket:TMPDIR:dotnet-diagnostic-<pid>-<key>-socket, the same name as before.TMPDIR=.../%s%n%x/andTMPDIR=.../%s%s%s%s%s%s%s%s%s%s%n/: the runtime starts normally and the socket is created inside the literal%directory.