7022386: gethostbyname_r needs a pointer aligned buffer passed to it
authordholmes
Mon, 28 Feb 2011 06:40:46 -0500
changeset 8555 389ce5f9a6d1
parent 8554 14e626e9407b
child 8556 d3d6e4643560
7022386: gethostbyname_r needs a pointer aligned buffer passed to it Summary: Change buffer type to ensure pointer-alignment Reviewed-by: alanb, chegar
jdk/src/solaris/native/java/net/Inet4AddressImpl.c
--- a/jdk/src/solaris/native/java/net/Inet4AddressImpl.c	Mon Feb 28 11:03:52 2011 +0000
+++ b/jdk/src/solaris/native/java/net/Inet4AddressImpl.c	Mon Feb 28 06:40:46 2011 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -77,22 +77,24 @@
          */
 #endif /* __linux__ */
         struct hostent res, res2, *hp;
-        char buf[HENT_BUF_SIZE];
-        char buf2[HENT_BUF_SIZE];
+        // these buffers must be pointer-aligned so they are declared
+        // with pointer type
+        char *buf[HENT_BUF_SIZE/(sizeof (char *))];
+        char *buf2[HENT_BUF_SIZE/(sizeof (char *))];
         int h_error=0;
 
 #ifdef __GLIBC__
-        gethostbyname_r(hostname, &res, buf, sizeof(buf), &hp, &h_error);
+        gethostbyname_r(hostname, &res, (char*)buf, sizeof(buf), &hp, &h_error);
 #else
-        hp = gethostbyname_r(hostname, &res, buf, sizeof(buf), &h_error);
+        hp = gethostbyname_r(hostname, &res, (char*)buf, sizeof(buf), &h_error);
 #endif
         if (hp) {
 #ifdef __GLIBC__
             gethostbyaddr_r(hp->h_addr, hp->h_length, AF_INET,
-                            &res2, buf2, sizeof(buf2), &hp, &h_error);
+                            &res2, (char*)buf2, sizeof(buf2), &hp, &h_error);
 #else
             hp = gethostbyaddr_r(hp->h_addr, hp->h_length, AF_INET,
-                                 &res2, buf2, sizeof(buf2), &h_error);
+                                 &res2, (char*)buf2, sizeof(buf2), &h_error);
 #endif
             if (hp) {
                 /*
@@ -136,7 +138,9 @@
     const char *hostname;
     jobjectArray ret = 0;
     struct hostent res, *hp = 0;
-    char buf[HENT_BUF_SIZE];
+    // this buffer must be pointer-aligned so is declared
+    // with pointer type
+    char *buf[HENT_BUF_SIZE/(sizeof (char *))];
 
     /* temporary buffer, on the off chance we need to expand */
     char *tmp = NULL;
@@ -176,9 +180,9 @@
 
     /* Try once, with our static buffer. */
 #ifdef __GLIBC__
-    gethostbyname_r(hostname, &res, buf, sizeof(buf), &hp, &h_error);
+    gethostbyname_r(hostname, &res, (char*)buf, sizeof(buf), &hp, &h_error);
 #else
-    hp = gethostbyname_r(hostname, &res, buf, sizeof(buf), &h_error);
+    hp = gethostbyname_r(hostname, &res, (char*)buf, sizeof(buf), &h_error);
 #endif
 
     /* With the re-entrant system calls, it's possible that the buffer
@@ -251,7 +255,9 @@
     jstring ret = NULL;
     jint addr;
     struct hostent hent, *hp = 0;
-    char buf[HENT_BUF_SIZE];
+    // this buffer must be pointer-aligned so is declared
+    // with pointer type
+    char *buf[HENT_BUF_SIZE/(sizeof (char *))];
     int h_error = 0;
     char *tmp = NULL;
 
@@ -273,10 +279,10 @@
     addr = htonl(addr);
 #ifdef __GLIBC__
     gethostbyaddr_r((char *)&addr, sizeof(addr), AF_INET, &hent,
-                    buf, sizeof(buf), &hp, &h_error);
+                    (char*)buf, sizeof(buf), &hp, &h_error);
 #else
     hp = gethostbyaddr_r((char *)&addr, sizeof(addr), AF_INET, &hent,
-                         buf, sizeof(buf), &h_error);
+                         (char*)buf, sizeof(buf), &h_error);
 #endif
     /* With the re-entrant system calls, it's possible that the buffer
      * we pass to it is not large enough to hold an exceptionally