[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 66839a7 2/2: * src/fns.c (Flocale_info): Avoid fixn
From: |
Philipp Stephani |
Subject: |
[Emacs-diffs] master 66839a7 2/2: * src/fns.c (Flocale_info): Avoid fixnum overflow under ASan. |
Date: |
Sat, 5 Oct 2019 07:08:01 -0400 (EDT) |
branch: master
commit 66839a74bb74efa16f9f531e93d58cadf6ab7196
Author: Philipp Stephani <address@hidden>
Commit: Philipp Stephani <address@hidden>
* src/fns.c (Flocale_info): Avoid fixnum overflow under ASan.
---
src/fns.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/fns.c b/src/fns.c
index fa52e5e..37c581f 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -3176,8 +3176,14 @@ The data read from the system are decoded using
`locale-coding-system'. */)
# endif
# ifdef HAVE_LANGINFO__NL_PAPER_WIDTH
if (EQ (item, Qpaper))
- return list2i ((intptr_t) nl_langinfo (_NL_PAPER_WIDTH),
- (intptr_t) nl_langinfo (_NL_PAPER_HEIGHT));
+ /* We have to cast twice here: first to a correctly-sized integer,
+ then to int, because that's what nl_langinfo is documented to
+ return for _NO_PAPER_{WIDTH,HEIGHT}. The first cast doesn't
+ suffice because it could overflow an Emacs fixnum. This can
+ happen when running under ASan, which fills allocated but
+ uninitialized memory with 0xBE bytes. */
+ return list2i ((int) (intptr_t) nl_langinfo (_NL_PAPER_WIDTH),
+ (int) (intptr_t) nl_langinfo (_NL_PAPER_HEIGHT));
# endif
#endif /* HAVE_LANGINFO_CODESET*/
return Qnil;