libkernel: inet_pton and inet_ntop use the Windows Winsock text rules, which differ from FreeBSD's (leading zeros in an IPv4 tail, ::ffff: and v4-compatible formatting) #3126
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 husseinkad on 2026-10-10T22:42:38Z.
What
The guest
inet_ptonandinet_ntop(core/libs/prx/libkernel/Socket/src/AddressConversion.cpp) call Winsock'sInetPtonAandInetNtopAon Windows, whose text rules differ from FreeBSD'slib/libc/inet/inet_pton.candinet_ntop.c(releng/11.4):inet_pton(AF_INET6, "::01.2.3.4")(and::1.2.3.04,::0.0.0.00) returns 1 where FreeBSD returns 0: no leading zeros are allowed in a dotted-decimal part.inet_ntopprints::ffff:0.0.0.1as::ffff:0:1, and::ffff:0:1:0with a dotted tail (::ffff:0:0.1.0.0), where FreeBSD prints::ffff:0.0.0.1and::ffff:0:1:0.A title that parses or prints addresses and compares the text (or accepts input the console rejects) sees a difference. Linux and macOS hosts already use the same algorithm as FreeBSD (glibc inherited it), so the change that matters is on Windows.
sceNetInetPtonandsceNetInetNtopinlibSceNet/Export.cppstill use the host functions and have the same difference; they are not part of this issue.Fix
A tested fix is on my fork:
husseinkad:fix/libkernel-inet-text-rules(one commit onmain; PR #2768, closed by the intake check). Both functions are implemented without the host, written from the text grammar (RFC 4291 section 2.2, RFC 3493) and FreeBSD's observable rules, not copied from BSD, glibc or musl sources (an earlier attempt of mine was a transcription of the ISC-licensed FreeBSD files, which I dropped over provenance):inet_ptonsplits at::and parses the two halves as group lists,inet_ntopfinds the longest zero run in a separate pass. The rules:AF_INETis four decimal parts of 1 to 3 digits with no leading zero;AF_INET6is up to eight groups of 1 to 4 hex digits with at most one::standing for one or more zero groups, a dotted IPv4 tail only as the last 32 bits, no zone id;inet_ntopprints lowercase hex without leading zeros, compresses the first longest run of two or more zero groups, and prints a dotted tail only for::a.b.c.dand::ffff:a.b.c.d. Return values,EAFNOSUPPORT(47),ENOSPC(28) and the existing NULL handling are unchanged, and the file no longer needs Winsock. A provenance review compared the structure with FreeBSD's files side by side and found none of its distinctive identifiers or structure.guest_addressesgains the leading-zero cases, the::ffff:forms,::2,::,::1,1::, invalid forms such as1:2:3:4:5:6:7:8::and a zone id, exact-fit and one-short buffers and the family errors; it fails without the change. Differential runs against FreeBSD's sources compiled as a reference, comparing return value,errno, every destination byte and guard bytes: more than 3 billion cases and 0 divergences (all strings of length 7 or less for IPv4, of length 6 for IPv6, 153 million strings of length up to 9, 40 million structured and mutated IPv6 forms, every 16-bit value in each group position, all{0, 1, ffff, 0x1234}^8combinations, 1 billion random 16-byte patterns biased to zero runs, 2^28 IPv4 patterns, buffer sizes 0 to 50), and an undefined-behaviour-trapping build found no trap. The expected behaviour is assumed from FreeBSD 11.4 and unverified on a console; that is recorded in TechnicalDebt. Linux not run (the file is now pure C++ shared with the POSIX hosts).AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T12:35:05Z.
The reviewed fix is now in PR #3530. It carries Hussein Kadhim's original commit with authorship preserved. On current
main, the full Linux Release build passed andguest_addressespassed three runs.Conventions and relinker CI jobs fail before evaluating the PR because checkout cannot resolve the existing
3rdparty/imguigitlink onmain; #3511 is tracking that repository-wide issue. The other applicable PR checks pass. I have not independently rerun the Windows differential suite or tested on console hardware.Imported from boykopovar/AnyPS5. Originally posted by husseinkad on 2026-10-11T12:37:13Z.
Thank you @MarcZX100 for carrying this into #3530 with the authorship kept, and for the careful CI notes on the
3rdparty/imguigitlink. For the record, the Windows differential I ran against FreeBSD's sources (more than 3 billion cases, 0 divergences) was on the branch's own commit, so it applies to the carried one if the commit is unchanged.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T12:47:13Z.
Update: #3511 has merged, removing the orphan gitlink from
main. PR #3530 is rebased ontoa11c8f7f; the full Linux Release build andguest_addresses(3/3) pass on the rebased head. CI is running again against the fixed base.