fix(libSceNet): parse sceNetInetPtonEx IPv4 text as the PS4 does #8056
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8056"
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 ntamas94 on 2026-10-19T19:11:11Z.
What
sceNetInetPtonEx(added in #7823) forwarded tosceNetInetPtonand threw for any flags other than 0. On a PS4 (firmware 10.71) it does neither:inet_atonreads it, not asinet_pton:"1.2.3"is 1.2.0.3,"127.1"is 127.0.0.1, hex (0x,0X) and octal (leading0) parts are accepted, a part value wraps at 32 bits ("1.4294967296"is 1.0.0.0,"18446744073709551617"is 0.0.0.1) and the text ends at the first space, tab or VT (measured); LF, FF and CR are treated the same assceNetInetPtondoes, not measured for this function. TheNET_EINVALfor a nullsrcordstalso followssceNetInetPton, not measured.inet_aton: a part starting with09is decimal ("09"is 9,"0989"is 989,"0919"is 919), while an octal part containing8or9fails ("08","018","019","00919")."0x"alone is accepted as 0.sceNetInetPtondoes (strict, no scope id), which matches the console.sceNetErrnoLocunchanged.The IPv4 parser is a small portable function in
Export.cpp; hostinet_atonis not used, since Winsock has none and glibc rejects the09and wraparound cases. The debt entry forsceNetInetPtonExnow states what was measured and that the PS5 is not.Measured with an OpenOrbis homebrew that calls
sceNetInetPtonExwith the buffer filled with0xaaandsceNetErrnoLocset to 123.Flags (each row was identical for flags 0, 1, 2, 3, 4, 8, 0x10, 0x20, 0x40, 0x80, 0x100, 0x10000, 0x80000000 and -1):
"192.168.1.4"c0a80104"1.2.3"01020003"127.1"7f000001"0x7f.0.0.1"7f000001"010.0.0.1"08000001"1.2.3.4 "01020304"::1"00000000000000000000000000000001"::ffff:1.2.3.4"00000000000000000000ffff01020304"fe80::1%1""fe80::1%em0""1.2.3.4"0x8041012f, errno 47Raw output: flags (14 values x 11 inputs)
Raw output: inet_aton edge cases
Raw output: octal parts
Raw output: part width
Raw output: parts starting with 09
Tested
Windows 11 Pro (26200), WinLibs GCC 15.2.0 r7:
guest_sce_netpasses. WithExport.cppfrom before this change and the new checks,guest_sce_netfails. Linux not run locally. No title or homebrew run on AnyPS5.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T19:25:20Z.
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.
core/libs/prx/libSceNet/Export.cppcore/libs/tests/GuestSceNet.cppdocs/dev/debt/libSceNet.mdcore/libs/tests/GuestSceNet.cppcore/libs/prx/libSceNet/Export.cppcore/libs/prx/libSceNet/Export.cppcore/libs/tests/GuestSceNet.cppcore/libs/prx/libSceNet/Export.cppcore/libs/tests/GuestSceNet.cppdocs/dev/debt/libSceNet.mdcore/libs/prx/libSceNet/Export.cppdocs/dev/debt/libSceNet.mdcore/libs/prx/libSceNet/Export.cppcore/libs/tests/GuestSceNet.cppdocs/dev/debt/libSceNet.mdImported from boykopovar/AnyPS5. Originally posted by rahul05ranjan on 2026-10-19T19:54:39Z.
Review: COMMENTED
The hardware measurements are what make this safe to merge — you didn't guess at
inet_atonsemantics, you measured them, including the two PS4 deviations (the09decimal special case and the octal 8/9 rejection) that would have silently broken under glibc'sinet_aton. Rolling a portable parser instead of using the host function was the correct call for those exact cases.I walked the parser against the test table and every case I traced agrees with the code:
09/9special case: after a leading0, a following9leaves base 10 ("0989"→ 989), while any later8/9digit in a real octal part returns false ("0199"fails) — both branches are pinned by tests;"1.4294967296"→1.0.0.0and"18446744073709551617"→ 1 because the intermediatevalue > 0xfftest sees the wrapped value, which is exactly what the firmware appears to do;0xffffffffu >> (8 * count)as the last-part ceiling matches the per-position limits (a32-bit,a.b24-bit, ...a.b.c.d8-bit) without a second branch;"1.2.3.4 x"passes,"1.2.3.4x"fails, both tested.One subtlety worth knowing (no change needed): with plain
charsigned on the ABI here,*textfor bytes ≥ 0x80 goes negative, so the*text < '0'first-digit check rejects them beforestrchrever sees them — the"1.2.3.4\xa0"negative test passes via that route. If this parser is ever reused somewhere the char type is unsigned, that first comparison still works since bytes ≥ 0x80 are > '9', so the behavior holds either way. Nice that it's not load-bearing.The debt-file rewrite, with what was measured vs. what follows
sceNetInetPtonby assumption, is the part future contributors will thank you for.Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-19T22:29:26Z.
Linux run (the description has Windows only): WSL Ubuntu 24.04, GCC 13.3, Release, BUILD_TESTING=ON. This PR merged onto
main9127ea36d.guest_sce_netpasses 5/5.libSceNet/Export.cppfrommain, new test kept): it aborts.Windows (Windows 11 Home 26300, Ryzen 5 9600X, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON, same base): 7/8 pass, and the reverted control 0/8.
guest_sce_netis load-flaky here; plainmainpassed 6/6 in the same session, and #8013 on the same test passed 19/20.This PR and #8013 both edit
GuestSceNet.cppanddocs/dev/debt/libSceNet.md, and they merge into each other cleanly.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by ntamas94 on 2026-10-20T02:07:47Z.
Thanks @wachi35676 for the Linux and Windows runs and the negative control. The cases this PR adds only parse text and open no sockets, so they should not depend on load. Good to know #8013 merges cleanly with it.