libkernel_sys: readlink checks the path before the buffer size, where FreeBSD checks the size first; fix branch ready #8602
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 xXPBSXx on 2026-10-20T18:05:15Z.
On Windows,
readlinkandreadlinkatfail a NULL path withEFAULTand an empty path withENOENTbefore they look at the buffer size. FreeBSD 11.4 returnsEINVALfor a size aboveIOSIZE_MAXfirst (kern_readlinkat, beforenameiat :2238). Soreadlink(NULL, buf, SIZE_MAX),readlink("", buf, SIZE_MAX)andreadlink(<missing path>, buf, SIZE_MAX)returnEINVALthere; we returnEFAULT,ENOENT(the missing path already returnedEINVAL, because its lookup comes after our size check). The same order applies toreadlinkat.Cause.
readlink_nid_postfixandreadlinkat_nid_postfixtest the path pointer and the empty string before the size.Observed on
main892a4f1328, Windows 10 (10.0.19045), WinLibs GCC 15.2.0 r7, Release: the new assertions inguest_kernel_sysfail without the change at the first one (readlink(NULL, buffer, SIZE_MAX): guest errno 14 instead of 22) and pass with it. I did not run the other calls one by one againstmain; the other results above come from reading the source. I have not found a title that stops on this.Fix, ready to cherry-pick.
xXPBSXx:fix/libkernel-sys-readlink-size-first(994fb42929, one commit onmain892a4f1328, two files, +9/-2): the size check moves to the top of both functions; a NULL or empty path with a valid size still returnsEFAULTorENOENT.AI-assisted (Claude Code).