diff options
| author | Eli Zaretskii | 2019-05-05 17:06:01 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2019-05-05 17:06:01 +0300 |
| commit | 708d117a85107331c8a06a9a4887abffcc18ec24 (patch) | |
| tree | 0127bf17b68c25150421835112e097868c9ad11b /src | |
| parent | 64f95e4011242110fb51ae52d3c19a70000de1e6 (diff) | |
| download | emacs-708d117a85107331c8a06a9a4887abffcc18ec24.tar.gz emacs-708d117a85107331c8a06a9a4887abffcc18ec24.zip | |
Avoid crashes in read_integer
* src/lread.c (read_integer): Always allocate a buffer, since
we need to use it even when the radix is invalid. (Bug#35576)
Diffstat (limited to 'src')
| -rw-r--r-- | src/lread.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/src/lread.c b/src/lread.c index 1c97805ca7a..c37719e0d24 100644 --- a/src/lread.c +++ b/src/lread.c | |||
| @@ -2660,11 +2660,12 @@ read_integer (Lisp_Object readcharfun, EMACS_INT radix) | |||
| 2660 | Also, room for invalid syntax diagnostic. */ | 2660 | Also, room for invalid syntax diagnostic. */ |
| 2661 | size_t len = max (1 + 1 + UINTMAX_WIDTH + 1, | 2661 | size_t len = max (1 + 1 + UINTMAX_WIDTH + 1, |
| 2662 | sizeof "integer, radix " + INT_STRLEN_BOUND (EMACS_INT)); | 2662 | sizeof "integer, radix " + INT_STRLEN_BOUND (EMACS_INT)); |
| 2663 | char *buf = NULL; | 2663 | char *buf = xmalloc (len); |
| 2664 | char *p = buf; | 2664 | char *p = buf; |
| 2665 | int valid = -1; /* 1 if valid, 0 if not, -1 if incomplete. */ | 2665 | int valid = -1; /* 1 if valid, 0 if not, -1 if incomplete. */ |
| 2666 | 2666 | ||
| 2667 | ptrdiff_t count = SPECPDL_INDEX (); | 2667 | ptrdiff_t count = SPECPDL_INDEX (); |
| 2668 | record_unwind_protect_ptr (free_contents, &buf); | ||
| 2668 | 2669 | ||
| 2669 | if (radix < 2 || radix > 36) | 2670 | if (radix < 2 || radix > 36) |
| 2670 | valid = 0; | 2671 | valid = 0; |
| @@ -2672,8 +2673,6 @@ read_integer (Lisp_Object readcharfun, EMACS_INT radix) | |||
| 2672 | { | 2673 | { |
| 2673 | int c, digit; | 2674 | int c, digit; |
| 2674 | 2675 | ||
| 2675 | buf = xmalloc (len); | ||
| 2676 | record_unwind_protect_ptr (free_contents, &buf); | ||
| 2677 | p = buf; | 2676 | p = buf; |
| 2678 | 2677 | ||
| 2679 | c = READCHAR; | 2678 | c = READCHAR; |