feat(libc): implement timingsafe_bcmp #12586
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12586"
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 voidlakhan on 2026-10-28T21:30:56Z.
What
Implement
timingsafe_bcmp(NIDaWl82o9ammc) inlibcmatching FreeBSD 11.4 behavior, and add test coverage inGuestStrings.cpp.Reference:
https://github.com/freebsd/freebsd-src/blob/release/11.4.0/lib/libc/string/timingsafe_bcmp.c
Tested
Windows 10,
core/libs/tests/GuestStrings.cppchecking equal, non-equal at start/middle/end, reversed order, sub-lengths, empty buffers, and high-bit byte sequences.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)Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-28T22:15:50Z.
Review: COMMENTED
I ran a host-side check on macOS arm64 (Apple clang,
-fsanitize=address,undefined). The harness holds the function body from 33b5bee04d and the 11 newRequirelines word for word. They all pass, and the NIDaWl82o9ammcrecomputes fromtimingsafe_bcmp.Mutants against the new assertions:
safeD)&instead of^ret == 0invertedp1[i] - p2[i]instead of^return ret;(raw OR of the XORs)return -(ret != 0);The body follows FreeBSD 11.4, where the function returns
(ret != 0), so it gives exactly 1 when the buffers differ. The tests only check!= 0, so nothing would catch a change that returns some other non-zero value. If 1 is the intended contract, two lines pin it down and kill both survivors:Apart from that, and the licence notice @oneandonlydean asked for, this looks right to me. I did not build
guest_stringsitself (the macOS lane here has no submodules), and I did not test on a console.AI-assisted: yes