RFR: 8227493: Return a more useful error message from lookupAllHostAddr if getaddrinfo results in EAI_SYSTEM error

Daniel Fuchs dfuchs at openjdk.org
Mon Dec 2 15:35:37 UTC 2024


On Mon, 2 Dec 2024 15:26:15 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:

>> Can I please get a review of this minor enhancement to the error text that is reported if the `getaddrinfo()` native call returns the `EAI_SYSTEM` error? This addresses https://bugs.openjdk.org/browse/JDK-8227493.
>> 
>> The `java.net.InetAddress` class, in its implementation for resolving addresses for a host name, calls the `getaddrinfo()` native call on *nix platforms. If `getaddrinfo()` returns an error then we use the `gai_strerror()` native call to convert the error number into an error string that is then propagated to the application. Among other errors, the `getaddrinfo()` is specified to return the error code `EAI_SYSTEM` which as per its documentation represents
>> 
>>> EAI_SYSTEM        system error returned in errno
>> 
>> So calling `gai_strerror()` merely returns a generic "System error" text. The real underlying error is present in the `errno` and that has more useful information. 
>> 
>> The commit in this PR checks the error for `EAI_SYSTEM` and if it matches then it additionally gets the error text corresponding to `errno`. So the error text that gets propagated will now be "System error: Illegal byte sequence", assuming `EILSEQ` was the underlying `errno` for the `getaddrinfo` call (my use of `EILSEQ` in this example is arbitrary and it's merely to show what the error text will look like after this change).
>> 
>> Given the nature of this change no new test has been introduced. Existing tests in tier1, tier2 and tier3 continue to pass with this change.
>
> src/java.base/unix/native/libnet/net_util_md.c line 190:
> 
>> 188:         sys_errno_string = strerror(sys_errno);
>> 189:         format = "%s: %s: %s";
>> 190:         size = strlen(format) + strlen(hostname) + strlen(error_string) + strlen(sys_errno_string) + 2;
> 
> should be + 4, not + 2 here

Actually, IIANM, shouldn't it be + 5 here and + 3 below to account for the null terminator?
snprintf says it will write up to size - 1 characters.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/22484#discussion_r1866064890


More information about the net-dev mailing list