[PATCH v2 01/11] net: net_read_uint32: assert that only 32 bit are read
Uwe Kleine-König
u.kleine-koenig at pengutronix.de
Fri Feb 7 16:28:03 EST 2014
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>
---
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
More information about the barebox
mailing list