-
Bug
-
Resolution: Fixed
-
P3
-
7
-
b134
-
generic
-
generic
-
Verified
In Inet4AddressImpl.c the functions getLocalHostName and lookupAllHostAddr call gethostbyname_r passing in a buffer declared as a simple char array:
char buf[HENT_BUF_SIZE];
gethostbyname_r will use this buffer to get the requested info and will then update the hostent structure it was also passed, to point to that buffer. In effect given the hostent struct contains:
char **h_addr_list; /* list of addresses */
the code will do:
h->h_addr_list = buf
This requires that buf be pointer-aligned (as it is expected to contain pointers), but the char[] declaration means that buf may only be byte-aligned, and hence on an architecture that requires pointer alignment we can get an access error due to the unaligned pointer access when h is passed to another function.
The fix is to declare buf as being an array of pointers:
char *buf[HENT_BUF_SIZE/(sizeof (char *))];
and to cast it back to char* when passing into other functions.
char buf[HENT_BUF_SIZE];
gethostbyname_r will use this buffer to get the requested info and will then update the hostent structure it was also passed, to point to that buffer. In effect given the hostent struct contains:
char **h_addr_list; /* list of addresses */
the code will do:
h->h_addr_list = buf
This requires that buf be pointer-aligned (as it is expected to contain pointers), but the char[] declaration means that buf may only be byte-aligned, and hence on an architecture that requires pointer alignment we can get an access error due to the unaligned pointer access when h is passed to another function.
The fix is to declare buf as being an array of pointers:
char *buf[HENT_BUF_SIZE/(sizeof (char *))];
and to cast it back to char* when passing into other functions.
- relates to
-
JDK-7114611 (fs) DirectoryStream fails with SIGBUS on some embedded platforms, dirent alignment
-
- Closed
-