[PATCH v2 01/11] net: net_read_uint32: assert that only 32 bit are read

Sascha Hauer s.hauer at pengutronix.de
Mon Feb 10 03:02:44 EST 2014


On Fri, Feb 07, 2014 at 10:28:03PM +0100, Uwe Kleine-König wrote:
> On some architectures (e.g. alpha, amd64, arm64, ia64, s390x, mips64)
> sizeof(ulong) is 8 which made net_read_uint32 actually read too much and
> even returned the wrong value on big endian machines.
> (Note the second issue isn't that critical though, because the only
> architecture from the list above that uses big endian byte order is s390x
> ...)
> 
> Also change the argument to void * because the pointer is not necessarily
> properly aligned.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig at pengutronix.de>

Applied this series, thanks

Sascha

> ---
>  include/net.h | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/include/net.h b/include/net.h
> index a4cfec712374..8388e2f12ebe 100644
> --- a/include/net.h
> +++ b/include/net.h
> @@ -269,11 +269,11 @@ static inline IPaddr_t net_read_ip(void *from)
>  }
>  
>  /* return uint32 *in network byteorder* */
> -static inline uint32_t net_read_uint32(uint32_t *from)
> +static inline uint32_t net_read_uint32(void *from)
>  {
> -	ulong l;
> -	memcpy((void*)&l, (void*)from, sizeof(l));
> -	return l;
> +	uint32_t tmp;
> +	memcpy(&tmp, from, sizeof(tmp));
> +	return tmp;
>  }
>  
>  /* write IP *in network byteorder* */
> -- 
> 1.8.5.2
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list