This is the mail archive of the glibc-bugs@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gethostid() output sign-extended on 64-bit platforms


There is a signed int to signed long bug in gethostid() for 64-bit
platforms.  If the 31st bit of the hostid is a 1, it gets signed
extended to 64 bits.  It should instead be cast as an unsigned int on
return.  Example:

# hostid
ffffffffa2802df3

With the attached patch, it returns to the expected output:

# hostid
a2802df3

Signed-off-by: Greg Edwards <edwardsg@sgi.com>
---

 sysdeps/unix/sysv/linux/gethostid.c |    2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)

Index: libc/sysdeps/unix/sysv/linux/gethostid.c
===================================================================
--- libc.orig/sysdeps/unix/sysv/linux/gethostid.c	2004-12-15 22:12:57.000000000 -0600
+++ libc/sysdeps/unix/sysv/linux/gethostid.c	2005-06-15 11:23:32.496024451 -0500
@@ -118,6 +118,6 @@ gethostid ()
 
   /* For the return value to be not exactly the IP address we do some
      bit fiddling.  */
-  return (int32_t) (in.s_addr << 16 | in.s_addr >> 16);
+  return (uint32_t) (in.s_addr << 16 | in.s_addr >> 16);
 }
 #endif


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]