Repository navigation
feat(libc): implement timingsafe_bcmp - #12586
Conversation
|
@voidlakhan thanks, the port reads well: the body matches FreeBSD 11.4's One thing before it can go in: the repository owner decided on 28 Oct that code ported from FreeBSD or other permissively licensed sources keeps its original copyright notice and licence text, verbatim. |
rooklz
left a comment
There was a problem hiding this comment.
I ran a host-side check on macOS arm64 (Apple clang, -fsanitize=address,undefined). The harness holds the function body from 33b5bee and the 11 new Require lines word for word. They all pass, and the NID aWl82o9ammc recomputes from timingsafe_bcmp.
Mutants against the new assertions:
| Mutant | Result |
|---|---|
| loop starts at 1 | killed (safeD) |
| loop stops one byte early | killed |
& instead of ^ |
killed |
ret == 0 inverted |
killed |
p1[i] - p2[i] instead of ^ |
equivalent (non-zero exactly when the bytes differ) |
return ret; (raw OR of the XORs) |
survives |
return -(ret != 0); |
survives |
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:
Require(timingsafe_bcmp_nid_postfix(highB, highA, 2) != 0);
+ Require(timingsafe_bcmp_nid_postfix(safeA, safeB, 6) == 1);
+ Require(timingsafe_bcmp_nid_postfix(highA, highB, 2) == 1);
Apart from that, and the licence notice @oneandonlydean asked for, this looks right to me. I did not build guest_strings itself (the macOS lane here has no submodules), and I did not test on a console.
AI-assisted: yes
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
5b02f8a to
6b3ffd4
Compare
|
@oneandonlydean @rooklz Updated:
|
6b3ffd4 to
1264958
Compare
|
@adriadam10 The merge conflict has now been resolved. I've rebased PR #12586 onto the latest The focused Could you please take another look at the updated head when convenient? Thanks! |
|
Investigated the macOS This failure is unrelated to the The failure was caused by duplicate CTest registrations in
The duplicate registrations caused CMake configuration to fail before the build or tests could run. This was a pre-existing issue on the base branch and was addressed separately in PR #13220 ( No changes to the |
# Conflicts: # docs/dev/debt/libc.md
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)