sandbox: fix signed integer overflow
PATCH 1/2 sandbox: fix signed integer overflow
On a 32-bit host system, UBSan reports:
===============================================================
UBSAN: Undefined behaviour in ./arch/sandbox/os/common.c:115:32
signed integer overflow:
83598 * 1000000000 cannot be represented in type 'long int'
===============================================================
Fix this.
--- arch/sandbox/os/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sandbox/os/common.c +1 -1
@@ -112,7 +112,7 @@ uint64_t linux_get_time(void)clock_gettime (CLOCK_MONOTONIC , &ts); - now = ts.tv_sec *1000 *1000 *1000 + ts.tv_nsec; + now = ts.tv_sec *1000ULL *1000 *1000 + ts.tv_nsec;return now; }
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 2/2 sandbox: hostfile: fix UB-inducing shift
On 32-bit hosts, UBSan reports:
====================================================================
UBSAN: Undefined behaviour in ./arch/sandbox/board/hostfile.c:135:12
shift exponent 32 is too large for 32-bit type 'long unsigned int'
====================================================================
Fix this by using a unsigned long long for base. The upper 32-bit won't be set, but device tree fixups can now read them.
--- arch/sandbox/mach-sandbox/include/mach/hostfile.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sandbox/mach-sandbox/include/mach/hostfile.h +1 -1
@@ -3,7 +3,7 @@struct hf_info {int fd; -unsigned long base; +unsigned long long base;size_t size;const char *devname;const char *filename;
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
AppliedQuoted 8 lines · Ahmad Fatoum
On a 32-bit host system, UBSan reports:
===============================================================
UBSAN: Undefined behaviour in ./arch/sandbox/os/common.c:115:32signed integer overflow:
83598 * 1000000000 cannot be represented in type 'long int'
===============================================================
Quoted 6 lines
Fix this.
Signed-off-by Ahmad Fatoum <[email protected]>--- arch/sandbox/os/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied, thanks
Sascha
Signature · 9 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox