fix(libc): safely probe the state of wcstok_s #20588
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20588"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-11-15T10:34:23Z.
What
wcstok_sread*s1maxand*contextin its argument check, and stored the remaining count, the context and the terminator it writes after a token, all straight through the guest pointers. So ans1maxor context pointing at unmapped memory faulted the host.s1maxand the context are now copied in withGuestCopyIn_nid_no_patchright after the null checks. The remaining count, the context and the terminator are written withGuestCopyOut_nid_no_patch, in the same order as before. An unreadable or unwritable pointer is reported as the "bad argument" runtime-constraint violation (EINVAL) thatwcstok_salready raises for a nulls1max, context or delimiters. The tokens, the remaining counts, the contexts and the missing-token / missing-delimiter violations for valid pointers are unchanged. The string and the delimiters are still read in place.Stacked on #20587 (same file, after #20525 and #20526). The debt entry goes in a fragment under
docs/dev/debt/changes/and records this as a host-safety fallback; console behaviour there is not measured.Tested
Linux (Ubuntu 26.04.1), GCC 15.2, Release.
guest_bounds_checking(CheckWcstok): an unreadables1max(0x10) and an unreadable context (0x10) each return null and raise one "wcstok_s: bad argument" violation with error 22. The existing token, remaining-count, end-of-string, s1max-limit, zero-s1max and null-context cases still pass.BoundsChecking.cppand these tests,guest_bounds_checkingsegfaults.tools/check_conventions.pypasses on the branch and this body;tools/debt_fold.py --checkpasses with this fragment and those of #20525, #20526 and #20587 applied tomain.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Pull request closed