From 1ba90ab655fab036f00ba0185ca7b456612a12bd Mon Sep 17 00:00:00 2001 From: Mansour Moufid Date: Mon, 19 Sep 2011 21:25:23 -0400 Subject: [PATCH 1/2] Fix a potentially useless integer overflow check. GCC 4.2 and maybe other compilers optimize away unsigned integer overflow checks of the form (foo + bar < foo), for all bar. Fix one such check in `src/common/OpenBSD_malloc_Linux.c'. --- src/common/OpenBSD_malloc_Linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/OpenBSD_malloc_Linux.c b/src/common/OpenBSD_malloc_Linux.c index 19dac77657..445135c6bb 100644 --- a/src/common/OpenBSD_malloc_Linux.c +++ b/src/common/OpenBSD_malloc_Linux.c @@ -1236,7 +1236,7 @@ imalloc(size_t size) ptralloc = 1; size = malloc_pagesize; } - if ((size + malloc_pagesize) < size) { /* Check for overflow */ + if (size > SIZE_MAX - malloc_pagesize) { /* Check for overflow */ result = NULL; errno = ENOMEM; } else if (size <= malloc_maxsize) From bfa75f70bb5eef7b470068df8bf9e3c7fa88c21a Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 20 Sep 2011 09:56:26 -0400 Subject: [PATCH 2/2] changes file for bug 4059 --- changes/bug4059 | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changes/bug4059 diff --git a/changes/bug4059 b/changes/bug4059 new file mode 100644 index 0000000000..82a4b1a10c --- /dev/null +++ b/changes/bug4059 @@ -0,0 +1,5 @@ + o Minor bugfixes: + - Change an integer overflow check in the OpenBSD_Malloc code so + that GCC is less likely to eliminate it as impossible. Patch + from Mansour Moufid. Fixes bug 4059. +