From 23e9e2eb9659057decdc1eb67773d9f9dd200537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20Rodr=C3=ADguez?= Date: Wed, 28 Jan 2026 01:25:16 +0100 Subject: [PATCH] Fix cpnet_getHostByName return value on error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- native/jni/native-lib/cpnet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/jni/native-lib/cpnet.c b/native/jni/native-lib/cpnet.c index 154a7dd7d5..534eaa46ed 100644 --- a/native/jni/native-lib/cpnet.c +++ b/native/jni/native-lib/cpnet.c @@ -661,7 +661,7 @@ jint cpnet_getHostByName (JNIEnv *env, const char *hostname, cpnet_address ***ad result = gethostbyname (hostname); if (result == NULL) - return -errno; + return -h_errno; memcpy (&hret, result, sizeof (struct hostent)); #endif if (ret != 0 || result == NULL)