fix(libSceLibcInternal): take a getopt_long argument only inside argc #15126
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15126"
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 MarcZX10 on 2026-11-02T17:43:50Z.
What
Three libSceLibcInternal fixes:
inet_atonaccepted a single number above0xffffffffand wrapped the 64-bit accumulation. It now rejects it.getopt_longreadarguments[optind]for a required argument without checkingargc. It now takes the argument only insideargc._Lstatfollowed symbolic links, so it reported the target's type. It now reports the link itself.Commits:
Tested
ctest -R '^(guest_getopt|guest_inet_address|guest_lstat_link)$': 3 of 3 passed.single number above 32 bits,required argument beyond argc,_Lstat reports a file link as a symbolic link).tools/check_conventions.py --base upstream/mainandgit diff --check upstream/main: clean.Not verified
__inet_atoninStringExtensions.cpp; it is out of scope here.Spawn.cppandPathStatistics.cppwere not compiled.Inet.cpp; the functions it adds are different.Checklist
main; no open PR implements these three fixesImported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T19:07:11Z.
Review: DISMISSED
Two of the three fixes move away from the console, and the third is unclear, so I'd hold all three. Firmware 13.42's
system/common/lib/libSceLibcInternal.sprx(sha256a01795ab49df639dd40abd6194956ada062244826824ce486c9acab227bf5285), read from disassembly only, not measured on a console:_Lstatfollows links on the console._ZNSt10filesystem6_LstatEPKcPNS_5permsEPi(tizCFt051h8,0x902d0) and_ZNSt10filesystem5_StatEPKcPNS_5permsEPi(8KeeeFcEdls,0x901d0) are both 0xe9 bytes. Apart from position-relative offsets their instructions are identical, and they make the same calls in the same order (0x124330,0x124950,0x124330five times,0x124310). So in 13.42_Lstatgives the same result as_Statfor any path, which is whatmaindoes now by sharingStatType. Reporting the link itself would differ from the console.inet_atondoesn't range-check a single number. AtISTLytNGT0c(0x8ae20), the parts switch checks the last part only for 2, 3 and 4 parts:So
"4294967296"returns 1 and stores 0.0.0.0. That matches FreeBSD 11.4'sinet_aton:u_long val, andcase 1:has no check. The newRejects("4294967296")andRejects("0x100000000")rows pin a result neither gives. I didn't check the digit loop for an overflow test, so I can't say what a value past 64 bits does.getopt_longwith the argument atargv[argc]. FreeBSD 11.4'sparse_long_optionstakesoptarg = nargv[optind++]without comparing againstnargc, then reports a missing argument only if that is NULL and stepsoptindback. With a NULL-terminatedargvthe two agree, but for the new case (getopt_long(2, …)over"foo --required bar"), FreeBSD takes"bar"as the argument rather than returning'?'. I haven't traced the 13.42getopt_long(8VVXJxB5nlk,0x8bc00) far enough to say which the console does, so this one needs evidence either way. If the intent is a host-safety bound (anargvthat isn't NULL-terminated), it should be listed as a divergence in the debt file.Tested on Windows 11, WinLibs GCC 15.2.0, with this head merged onto
main:guest_getoptandguest_inet_addresspass. Withmain'sInet.cpp,Getopt.cppandFilesystem.cpp, they fail on the new rows.guest_lstat_linkaborts at "create file link" here, because this account can't create symlinks, so it aborts instead of skipping where links are unavailable.The three changes are also unrelated (network parsing, option parsing, filesystem). The template asks for one topic per PR, so splitting them would let the parts that hold up go in on their own.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-11-06T23:36:01Z.
Review: CHANGES_REQUESTED
Thanks for the fixes. Going through the existing review points against the head, none of the three is shown to match the console, so I can't merge them as they are:
inet_aton(Inet.cpp:77,:82): FreeBSD 11.4'scase 1has no range check, and the 13.42libSceLibcInternal.sprxdisassembly @BunnyFl posted (ISTLytNGT0c,0x8ae20) checks only the 2, 3 and 4 part forms, then stores the low 32 bits. So"4294967296"parses as0.0.0.0on the console, and the newRejects(...)rows inGuestInetAddress.cpp:48pin a result it doesn't give. Please drop these two commits, or send console evidence for the rejection._Lstat(Filesystem.cpp:6-21): in the same disassembly_Lstat(tizCFt051h8) and_Stat(8KeeeFcEdls) are identical apart from relative offsets, so the console follows links in both, which is whatmaindoes. Please drop the change andGuestLstatLink.cpp, or show the console reports the link itself.getopt_long(Getopt.cpp:165): FreeBSD'sparse_long_optionstakesnargv[optind++]with nonargccomparison. If this is a host-safety bound for a non-NULL-terminatedargv, say so and list it as a divergence indocs/dev/debt/libSceLibcInternal.md; otherwise show what the console does atargv[argc](8VVXJxB5nlk,0x8bc00). The removed--optindon the missing-argument path also needs the same evidence.GuestLstatLink.cpp:31: it aborts when the account can't create symbolic links (Windows without the privilege). It should skip with the exit code the CI skip rules accept.windowsjob is red on this head; please check its log.Feel free to push the parts that come with console evidence.