summaryrefslogtreecommitdiff
path: root/nasmlib
diff options
context:
space:
mode:
authorH. Peter Anvin (Intel) <hpa@zytor.com>2018-12-13 13:55:25 -0800
committerH. Peter Anvin (Intel) <hpa@zytor.com>2018-12-13 13:55:25 -0800
commit3b91f4c117003a9f42717fe88257b6025790169e (patch)
treee4e6af5c4151179113d084c99d480a794c1831aa /nasmlib
parent51222ab69e7ac1854587321442638620aa4829ba (diff)
downloadnasm-3b91f4c117003a9f42717fe88257b6025790169e.tar.gz
malloc: handle potential infinite loop in nasm_alloc_failed()
It is possible on memory exhaustion that nasm_fatal() might cause another allocation error, thus calling nasm_alloc_failed() again. If we find us in nasm_alloc_failed() for a second time, try to get a message out and then call abort(). Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Diffstat (limited to 'nasmlib')
-rw-r--r--nasmlib/malloc.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/nasmlib/malloc.c b/nasmlib/malloc.c
index ccbc0c75..dbb7384a 100644
--- a/nasmlib/malloc.c
+++ b/nasmlib/malloc.c
@@ -44,7 +44,23 @@
static no_return nasm_alloc_failed(void)
{
- nasm_fatal(0, "out of memory");
+ /* If nasm_fatal() gets us back here, then croak hard */
+ static bool already_here = false;
+ FILE *errfile;
+
+ if (likely(!already_here)) {
+ already_here = true;
+ nasm_fatal(0, "out of memory!");
+ }
+
+ errfile = error_file;
+ if (!errfile)
+ error_file = stderr;
+
+ fprintf(error_file, "nasm: out of memory!\n");
+ fflush(error_file);
+ fflush(NULL);
+ abort();
}
static inline void *validate_ptr(void *p)