Skip to content

Fix cpnet_getHostByName return value on error#38

Merged
guillerodriguez merged 1 commit intomasterfrom
fix/gethostbyname-h_errno
Feb 13, 2026
Merged

Fix cpnet_getHostByName return value on error#38
guillerodriguez merged 1 commit intomasterfrom
fix/gethostbyname-h_errno

Conversation

@guillerodriguez
Copy link
Contributor

In platforms lacking gethostbyname_r, such as Darwin (macOS), cpnet_getHostByName incorrectly returns -errno when gethostbyname fails. It should return -h_errno instead.

Since errno is not set by gethostbyname, the value returned by cpnet_getHostByName is undefined at that point. It could be 0 or a stale value from a previous unrelated system call.

If cpnet_getHostByName returns 0 (CPNATIVE_OK) the caller (Java_java_net_VMInetAddress_getHostByName) then proceeds to access the addresses pointer, which was never initialized, typically leading to a crash (SIGBUS/SIGSEGV).

Fix by returning -h_errno on error.

Fixes #37 (BZ#124082)

In platforms lacking gethostbyname_r, such as Darwin (macOS),
cpnet_getHostByName incorrectly returns -errno when gethostbyname
fails. It should return -h_errno instead.

Since errno is not set by gethostbyname, the value returned by
cpnet_getHostByName is undefined at that point. It could be 0 or
a stale value from a previous unrelated system call.

If cpnet_getHostByName returns 0 (CPNATIVE_OK) the caller
(Java_java_net_VMInetAddress_getHostByName) then proceeds to
access the addresses pointer, which was never initialized,
typically leading to a crash (SIGBUS/SIGSEGV).

Fix by returning -h_errno on error.

Fixes #37 (BZ#124082)

Signed-off-by: Guillermo Rodríguez <grodriguez@ingelabs.com>
@guillerodriguez guillerodriguez merged commit 23e9e2e into master Feb 13, 2026
2 checks passed
@guillerodriguez guillerodriguez deleted the fix/gethostbyname-h_errno branch February 13, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cpnet_getHostByName returns invalid error value, may cause crash

2 participants