Alignment fixups for gethostbyname_r

Mike Frysinger vapier at gentoo.org
Sun Jan 6 06:35:53 UTC 2008


On Wednesday 19 December 2007, Daniel Jacobowitz wrote:
> --- libc/inet/resolv.c  (revision 189757)
> +++ libc/inet/resolv.c  (local)
> @@ -1534,6 +1534,15 @@ int attribute_hidden __read_etc_hosts_r(
>         char *cp, **alias;
>         int aliases, i, ret = HOST_NOT_FOUND;
>  
> +       /* Align to at least the size of a char * so we can put
> +          pointers in it.  */
> +       i = (unsigned long) buf % sizeof(char *);
> +       i = (sizeof(char *) - i) % sizeof(char *);
> +       if (buflen < i)
> +               return ERANGE;
> +       buf+=i;
> +       buflen-=i;
> +

considering buflen gets checked constantly before being utilized, i dont think 
we need an additional check to see if it could possibly store a pointer.  we  
just need to make sure the adjustment alone doesnt cause size_t underflow.

i think this should be sufficient:
/* Make sure the incoming char * buffer is aligned enough to
 * handle our random structures.  This define is the same as we
 * use for malloc alignment (which has same requirements). */
i = (size_t)buf & __alignof__(double __attribute_aligned__ (sizeof(size_t)));
if (buflen < i)
	return ERANGE;
buf += i;
buflen += i;
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: This is a digitally signed message part.
Url : http://lists.busybox.net/pipermail/uclibc/attachments/20080106/fa500974/attachment-0002.pgp 


More information about the uClibc mailing list