Date: | Tue, 23 Dec 2008 10:21:37 -0500 |
From: | "Jorgen Wahlsten" <jorgen@wahlsten.com> |
To: | krb5-bugs@MIT.EDU |
Subject: | Alignment problem in resolver test |
Hello!
In compiling krb5, version 1.6.3, I ran into a core dump (bus error) during 'gmake check' on a Solaris 2.10/Sun Fire T200 build system, when it tried to run tests/resolve/resolve.
It seems there is an alignment problem with the automatic 'addrcopy' variable in src/tests/resolve/resolve.c. I forced it to align (and execute successfully) after the change below. I figured this was an easier test, than changing the code to use an in_addr struct -- which is perhaps a more "correct" fix.
Thanks
/Jorgen Wahlsten
+++ resolve.c 2008-12-23 10:09:31.475658000 -0500
@@ -77,7 +77,11 @@
{
char myname[MAXHOSTNAMELEN+1];
char *ptr;
- char addrcopy[4];
+ /* char addrcopy[4]; */
+ union {
+ char addrcopy[4];
+ int make_me_aligned;
+ } u;
struct hostent *host;
int quiet = 0;
@@ -123,10 +127,10 @@
printf("Host address: %d.%d.%d.%d\n",
UC(ptr[0]), UC(ptr[1]), UC(ptr[2]), UC(ptr[3]));
- memcpy(addrcopy, ptr, 4);
+ memcpy(u.addrcopy, ptr, 4);
/* Convert back to full name */
- if((host = gethostbyaddr(addrcopy, 4, AF_INET)) == NULL) {
+ if((host = gethostbyaddr(u.addrcopy, 4, AF_INET)) == NULL) {
fprintf(stderr, "Error looking up IP address - fatal\n");
exit(2);
}
In compiling krb5, version 1.6.3, I ran into a core dump (bus error) during 'gmake check' on a Solaris 2.10/Sun Fire T200 build system, when it tried to run tests/resolve/resolve.
It seems there is an alignment problem with the automatic 'addrcopy' variable in src/tests/resolve/resolve.c. I forced it to align (and execute successfully) after the change below. I figured this was an easier test, than changing the code to use an in_addr struct -- which is perhaps a more "correct" fix.
Thanks
/Jorgen Wahlsten
Show quoted text
============================== cut here ==============================
--- resolve.c~ 2003-07-22 14:02:34.000000000 -0400+++ resolve.c 2008-12-23 10:09:31.475658000 -0500
@@ -77,7 +77,11 @@
{
char myname[MAXHOSTNAMELEN+1];
char *ptr;
- char addrcopy[4];
+ /* char addrcopy[4]; */
+ union {
+ char addrcopy[4];
+ int make_me_aligned;
+ } u;
struct hostent *host;
int quiet = 0;
@@ -123,10 +127,10 @@
printf("Host address: %d.%d.%d.%d\n",
UC(ptr[0]), UC(ptr[1]), UC(ptr[2]), UC(ptr[3]));
- memcpy(addrcopy, ptr, 4);
+ memcpy(u.addrcopy, ptr, 4);
/* Convert back to full name */
- if((host = gethostbyaddr(addrcopy, 4, AF_INET)) == NULL) {
+ if((host = gethostbyaddr(u.addrcopy, 4, AF_INET)) == NULL) {
fprintf(stderr, "Error looking up IP address - fatal\n");
exit(2);
}
Show quoted text
============================== cut here ==============================