Repository navigation
fix(libSceNet): parse sceNetInetPtonEx IPv4 text as the PS4 does - #8056
Conversation
On PS4 firmware 10.71 sceNetInetPtonEx reads IPv4 text the way
inet_aton does, not the way sceNetInetPton does: "1.2.3" is 1.2.0.3,
"127.1" is 127.0.0.1, hex and octal parts are accepted, a part value
wraps at 32 bits ("1.4294967296" is 1.0.0.0) and the text ends at the
first whitespace. Two differences from BSD inet_aton were measured: a
part starting with "09" is decimal ("0989" is 989), and an octal part
containing 8 or 9 fails.
The flags argument changed nothing for 0, every single bit up to
0x100, 0x10000, 0x80000000 and -1, so it is ignored instead of
throwing. IPv6 still converts as sceNetInetPton does, which matches
the console.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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.
|
rahul05ranjan
left a comment
There was a problem hiding this comment.
The hardware measurements are what make this safe to merge — you didn't guess at inet_aton semantics, you measured them, including the two PS4 deviations (the 09 decimal special case and the octal 8/9 rejection) that would have silently broken under glibc's inet_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:
- the
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; - wraparound before the final range check reproduces the measured
"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;- trailing garbage is only tolerated when the very first leftover character is whitespace, which is the "ends at the first space, tab or VT" behavior you measured —
"1.2.3.4 x"passes,"1.2.3.4x"fails, both tested.
One subtlety worth knowing (no change needed): with plain char signed on the ABI here, *text for bytes ≥ 0x80 goes negative, so the *text < '0' first-digit check rejects them before strchr ever 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 sceNetInetPton by assumption, is the part future contributors will thank you for.
|
Linux run (the description has Windows only): WSL Ubuntu 24.04, GCC 13.3, Release, BUILD_TESTING=ON. This PR merged onto
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. This PR and #8013 both edit AI-assisted: yes (Claude Code); results above were run on this machine. |
|
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. |
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