mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] sandbox: fix signed integer overflow
@ 2020-02-03  8:27 Ahmad Fatoum
  2020-02-03  8:27 ` [PATCH 2/2] sandbox: hostfile: fix UB-inducing shift Ahmad Fatoum
  2020-02-10  8:09 ` [PATCH 1/2] sandbox: fix signed integer overflow Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2020-02-03  8:27 UTC (permalink / raw)
  To: barebox

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.

Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
 arch/sandbox/os/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c
index 3ad12b4a30cd..3f9cc70770f6 100644
--- a/arch/sandbox/os/common.c
+++ b/arch/sandbox/os/common.c
@@ -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;
 }
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] sandbox: hostfile: fix UB-inducing shift
  2020-02-03  8:27 [PATCH 1/2] sandbox: fix signed integer overflow Ahmad Fatoum
@ 2020-02-03  8:27 ` Ahmad Fatoum
  2020-02-10  8:09 ` [PATCH 1/2] sandbox: fix signed integer overflow Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2020-02-03  8:27 UTC (permalink / raw)
  To: barebox

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.

Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
 arch/sandbox/mach-sandbox/include/mach/hostfile.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sandbox/mach-sandbox/include/mach/hostfile.h b/arch/sandbox/mach-sandbox/include/mach/hostfile.h
index 627fe28e765b..54f690be5f7f 100644
--- a/arch/sandbox/mach-sandbox/include/mach/hostfile.h
+++ b/arch/sandbox/mach-sandbox/include/mach/hostfile.h
@@ -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;
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] sandbox: fix signed integer overflow
  2020-02-03  8:27 [PATCH 1/2] sandbox: fix signed integer overflow Ahmad Fatoum
  2020-02-03  8:27 ` [PATCH 2/2] sandbox: hostfile: fix UB-inducing shift Ahmad Fatoum
@ 2020-02-10  8:09 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2020-02-10  8:09 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Mon, Feb 03, 2020 at 09:27:58AM +0100, Ahmad Fatoum wrote:
> 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.
> 
> Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
> ---
>  arch/sandbox/os/common.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks

Sascha


-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-02-10  8:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-03  8:27 [PATCH 1/2] sandbox: fix signed integer overflow Ahmad Fatoum
2020-02-03  8:27 ` [PATCH 2/2] sandbox: hostfile: fix UB-inducing shift Ahmad Fatoum
2020-02-10  8:09 ` [PATCH 1/2] sandbox: fix signed integer overflow Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox