Repository navigation
feat(libc): implement vsnprintf_s and vsscanf_s - #1981
overlordxrz-source wants to merge 1 commit into
Conversation
rWSuTWY2JN0 and tfNbpqL3D0M were throwing libcCyberUnknown18/19 stubs. They are the NIDs of vsnprintf_s and vsscanf_s, the C11 Annex K forms that take a guest va_list. The stub comments described a file-size idiom, which contradicts the names, like the comment strnlen_s had. vsnprintf_s rejects a null buffer or format, a zero size, a size above RSIZE_MAX, %n and a null %s argument, writing an empty string when the buffer is usable, and otherwise formats through vsnprintf. vsscanf_s rejects a null input, format or target with EOF and otherwise scans with the sized %s, %c and %[ rules of sscanf_s.
MarcZX10
left a comment
There was a problem hiding this comment.
The tests exercise the behavior this patch implements, and the updated build/conventions checks pass. The stated need is still only the PPSA import lists; the PR explicitly says no current-main NotImplemented call was found and no title was run. CONTRIBUTING.md says an import list alone does not show that a title reaches an export and asks for a reproduced failure or a concrete project need with its evidence limits. Since this adds two nontrivial secure-formatting implementations with assumed console behavior, please provide runtime evidence or a demonstrated project need before review.
|
Thanks. I don't have a current-main runtime line. The only call-site evidence is main's own note from #358's static GOT-xref pass on PPSA04029 ( |
…nf_s Harvested from upstream. Hand merge as for 1952: kept our libc/Export.cpp and deleted the stubs the PR implements elsewhere. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011krDVCnnMQPaEFEqCDnKmA
What
Cyberpunk 2077 (PPSA04029) imports two
libcfunctions that are still throwing stubs onmain,libcCyberUnknown18andlibcCyberUnknown19.tools/nid_names.pyresolves their NIDs:rWSuTWY2JN0vsnprintf_stfNbpqL3D0Mvsscanf_sBoth NIDs are in the PPSA04029 import list attached to #266.
rWSuTWY2JN0is also in the PPSA03396 list in #269.The stub comments described a file-size idiom called as
(handle, 0, 2)and(handle, 0, 0). That contradicts the hash-verified names, as the comment onstrnlen_sdid before b9c1c88. #492 left these two stubs alone because of it. This PR removes the stubs and their comments.These are the C11 Annex K signatures, not MSVC's:
int vsnprintf_s(char*, rsize_t, const char*, va_list)int vsscanf_s(const char*, const char*, va_list)MSVC's
vsnprintf_shas an extracountargument. The guestlibcexports the Annex K-onlyset_constraint_handler_s,abort_handler_sandignore_handler_s, plussnwprintf_s,vsnwprintf_sandwcsnlen_s. It exports none of MSVC's underscore forms such as_vsnprintf_s(see the export list on psdevwiki's LibSceLibcInternal page). The existingsnprintf_s,vsprintf_s,snwprintf_sandsscanf_sexports here already use the C11 shapes. #1498 implementsrWSuTWY2JN0with MSVC'scountargument, so a C11 caller's format pointer would be read ascountthere.vsnprintf_srejects these with a negative result: a null buffer or format, a size of 0 or aboveRSIZE_MAX, any%n(%%nis still literal text), and a null%s,%lsor%Sargument. When the buffer is usable it writes an empty string. To find null strings it walks a copy of the guestva_list(*widths and precisions, integers, doubles,long double, pointers) and stops at the first conversion it doesn't know, leaving that to the formatter. Otherwise it formats through the existingvsnprintfexport, which uses the Windows guest formatter on Windows. It returns the full length and truncates with a terminating null.vsscanf_sreturnsEOFfor a null input, format or target pointer. Otherwise it runs the scannersscanf_salready uses, with sized%s,%cand%[. The size is read asunsigned int, assscanf_sdoes._sexports here do.Log
I don't own Cyberpunk 2077, so I can't paste a line where PPSA04029 stops on
main. I found no stop line for these NIDs in any issue or PR. The evidence is the import lists in #266 and #269. If someone with either title can post theNotImplementedline forrWSuTWY2JN0ortfNbpqL3D0Mfrommain, I'll add it here.Tested
aarch64 Debian 13 host. The full project can't be built here because it needs x86-64.
core/libs/tests/GuestSecureFormatting.cpp(guest_secure_formatting), linked natively againstFormatting.cppthrough the non-Windowsva_listpath, passes and also passes with UBSan. Thevsnprintf_schecks cover formatting, truncation with the full count, literal%%n,%nwith and without flags, null%sand%ls(including after*,%f,%Lf,%c,%pand%lldarguments), null format and buffer, size 0 and a size aboveRSIZE_MAXleaving the buffer alone. Thevsscanf_schecks cover sized%s,%cand%[, a too-small buffer, empty input, and null input, format and targets.Formatting.cpp,Export.cppand the test compile with-Wall -Wextra(Zig 0.17, clang 22). The only warnings are the existing ones fromGeneral.hppandFileStream.hpp. Zig's clang 22 lacks__builtin_sysv_va_list, soFormatting.cpponmaindoesn't compile for x86_64-windows-gnu here either. With those builtins mapped to the plainva_listones, the only errors on that target are the existingva_startlines; the new Windows path (LibcDetail::FormatArguments) compiles. It hasn't been run on Windows.python3 tools/check_conventions.py --base origin/mainpasses.Checklist
main. The one other open PR that changes these functions is feat(libs): implement font, libc, libkernel and misc prx stubs #1498, which also changes these stubs as part of a larger change; see WhatNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)