* bug#8318: int overflow problem in SAFE_ALLOCA, SAFE_ALLOCA_LISP
@ 2011-03-22 9:12 Paul Eggert
0 siblings, 0 replies; only message in thread
From: Paul Eggert @ 2011-03-22 9:12 UTC (permalink / raw)
To: 8318
The SAFE_ALLOCA macro assumes that adding 1 to the integer
variable sa_must_free cannot overflow, but this assumption
is incorrect in some cases. I plan to commit the following
patch to fix this.
I found this bug using gcc 4.5.2 -O2 -Wstrict-overflow.
* lisp.h (SAFE_ALLOCA, SAFE_ALLOCA_LISP): Avoid 'int' overflow
leading to a memory leak, possible in functions like
load_charset_map_from_file that can allocate an unbounded number
of objects.
=== modified file 'src/lisp.h'
--- src/lisp.h 2011-03-18 04:58:44 +0000
+++ src/lisp.h 2011-03-22 09:04:53 +0000
@@ -3602,7 +3602,7 @@
else \
{ \
buf = (type) xmalloc (size); \
- sa_must_free++; \
+ sa_must_free = 1; \
record_unwind_protect (safe_alloca_unwind, \
make_save_value (buf, 0)); \
} \
@@ -3632,7 +3632,7 @@
buf = (Lisp_Object *) xmalloc (size_); \
arg_ = make_save_value (buf, nelt); \
XSAVE_VALUE (arg_)->dogc = 1; \
- sa_must_free++; \
+ sa_must_free = 1; \
record_unwind_protect (safe_alloca_unwind, arg_); \
} \
} while (0)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2011-03-22 9:12 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-22 9:12 bug#8318: int overflow problem in SAFE_ALLOCA, SAFE_ALLOCA_LISP Paul Eggert
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).