diff options
| author | Philipp Stephani | 2017-06-04 19:22:41 +0200 |
|---|---|---|
| committer | Philipp Stephani | 2017-06-04 19:50:51 +0200 |
| commit | a8a93b11cfa673c14c9a0d93ba87a16459dcde00 (patch) | |
| tree | 3915f68dc9df02944e5ddb0d71abb45bcdccc1d3 /src | |
| parent | 549706241e5ce6fe7f1131d7f132a19bdb1abdd9 (diff) | |
| download | emacs-a8a93b11cfa673c14c9a0d93ba87a16459dcde00.tar.gz emacs-a8a93b11cfa673c14c9a0d93ba87a16459dcde00.zip | |
Guard against signed integer overflows
* src/emacs-module.c (module_extract_integer)
(module_copy_string_contents, module_make_string): Guard against
signed integer overflows.
Diffstat (limited to 'src')
| -rw-r--r-- | src/emacs-module.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/emacs-module.c b/src/emacs-module.c index d4047d67a36..f7facb955bf 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c | |||
| @@ -448,6 +448,8 @@ module_eq (emacs_env *env, emacs_value a, emacs_value b) | |||
| 448 | static intmax_t | 448 | static intmax_t |
| 449 | module_extract_integer (emacs_env *env, emacs_value n) | 449 | module_extract_integer (emacs_env *env, emacs_value n) |
| 450 | { | 450 | { |
| 451 | verify (MOST_NEGATIVE_FIXNUM >= INTMAX_MIN); | ||
| 452 | verify (MOST_POSITIVE_FIXNUM <= INTMAX_MAX); | ||
| 451 | MODULE_FUNCTION_BEGIN (0); | 453 | MODULE_FUNCTION_BEGIN (0); |
| 452 | Lisp_Object l = value_to_lisp (n); | 454 | Lisp_Object l = value_to_lisp (n); |
| 453 | CHECK_NUMBER (l); | 455 | CHECK_NUMBER (l); |
| @@ -489,7 +491,9 @@ module_copy_string_contents (emacs_env *env, emacs_value value, char *buffer, | |||
| 489 | 491 | ||
| 490 | Lisp_Object lisp_str_utf8 = ENCODE_UTF_8 (lisp_str); | 492 | Lisp_Object lisp_str_utf8 = ENCODE_UTF_8 (lisp_str); |
| 491 | ptrdiff_t raw_size = SBYTES (lisp_str_utf8); | 493 | ptrdiff_t raw_size = SBYTES (lisp_str_utf8); |
| 492 | ptrdiff_t required_buf_size = raw_size + 1; | 494 | ptrdiff_t required_buf_size; |
| 495 | if (INT_ADD_WRAPV (raw_size, 1, &required_buf_size)) | ||
| 496 | xsignal0 (Qoverflow_error); | ||
| 493 | eassert (required_buf_size > 0); | 497 | eassert (required_buf_size > 0); |
| 494 | 498 | ||
| 495 | eassert (length != NULL); | 499 | eassert (length != NULL); |
| @@ -520,6 +524,8 @@ module_make_string (emacs_env *env, const char *str, ptrdiff_t length) | |||
| 520 | { | 524 | { |
| 521 | MODULE_FUNCTION_BEGIN (module_nil); | 525 | MODULE_FUNCTION_BEGIN (module_nil); |
| 522 | eassert (str != NULL); | 526 | eassert (str != NULL); |
| 527 | if (length < 0 || length > MOST_POSITIVE_FIXNUM) | ||
| 528 | xsignal0 (Qoverflow_error); | ||
| 523 | AUTO_STRING_WITH_LEN (lstr, str, length); | 529 | AUTO_STRING_WITH_LEN (lstr, str, length); |
| 524 | return lisp_to_value (code_convert_string_norecord (lstr, Qutf_8, false)); | 530 | return lisp_to_value (code_convert_string_norecord (lstr, Qutf_8, false)); |
| 525 | } | 531 | } |