9
0
Fork 0

net: net_read_uint32: assert that only 32 bit are read

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@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Uwe Kleine-König 2014-02-07 22:28:03 +01:00 committed by Sascha Hauer
parent 4f2f9150b7
commit 47eb6b50bb
1 changed files with 4 additions and 4 deletions

View File

@ -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* */