diff options
| author | Paul Eggert | 2011-05-15 22:15:51 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-05-15 22:15:51 -0700 |
| commit | 06d6db334ef501be6280e950b9158c539c24eb4d (patch) | |
| tree | ce31b6356d354490a2bbc9b07c804abc1a804d33 /src | |
| parent | 2b4560a850d2ea0767d0a3c4db19e4468f61b4eb (diff) | |
| download | emacs-06d6db334ef501be6280e950b9158c539c24eb4d.tar.gz emacs-06d6db334ef501be6280e950b9158c539c24eb4d.zip | |
* insdel.c (count_size_as_multibyte): Check for string overflow.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 2 | ||||
| -rw-r--r-- | src/insdel.c | 12 |
2 files changed, 12 insertions, 2 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 944a5dfbecb..b7bf4599d63 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,7 @@ | |||
| 1 | 2011-05-16 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2011-05-16 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 2 | ||
| 3 | * insdel.c (count_size_as_multibyte): Check for string overflow. | ||
| 4 | |||
| 3 | * character.c (lisp_string_width): Check for string overflow. | 5 | * character.c (lisp_string_width): Check for string overflow. |
| 4 | Use EMACS_INT, not int, for string indexes and lengths; in | 6 | Use EMACS_INT, not int, for string indexes and lengths; in |
| 5 | particular, 2nd arg is now EMACS_INT, not int. Do not crash if | 7 | particular, 2nd arg is now EMACS_INT, not int. Do not crash if |
diff --git a/src/insdel.c b/src/insdel.c index 2662858c2a1..de9e8aa570a 100644 --- a/src/insdel.c +++ b/src/insdel.c | |||
| @@ -20,6 +20,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 20 | 20 | ||
| 21 | #include <config.h> | 21 | #include <config.h> |
| 22 | #include <setjmp.h> | 22 | #include <setjmp.h> |
| 23 | |||
| 24 | #include <intprops.h> | ||
| 25 | |||
| 23 | #include "lisp.h" | 26 | #include "lisp.h" |
| 24 | #include "intervals.h" | 27 | #include "intervals.h" |
| 25 | #include "buffer.h" | 28 | #include "buffer.h" |
| @@ -581,14 +584,19 @@ count_size_as_multibyte (const unsigned char *ptr, EMACS_INT nbytes) | |||
| 581 | for (i = 0; i < nbytes; i++) | 584 | for (i = 0; i < nbytes; i++) |
| 582 | { | 585 | { |
| 583 | unsigned int c = *ptr++; | 586 | unsigned int c = *ptr++; |
| 587 | int n; | ||
| 584 | 588 | ||
| 585 | if (ASCII_CHAR_P (c)) | 589 | if (ASCII_CHAR_P (c)) |
| 586 | outgoing_nbytes++; | 590 | n = 1; |
| 587 | else | 591 | else |
| 588 | { | 592 | { |
| 589 | c = BYTE8_TO_CHAR (c); | 593 | c = BYTE8_TO_CHAR (c); |
| 590 | outgoing_nbytes += CHAR_BYTES (c); | 594 | n = CHAR_BYTES (c); |
| 591 | } | 595 | } |
| 596 | |||
| 597 | if (INT_ADD_OVERFLOW (outgoing_nbytes, n)) | ||
| 598 | string_overflow (); | ||
| 599 | outgoing_nbytes += n; | ||
| 592 | } | 600 | } |
| 593 | 601 | ||
| 594 | return outgoing_nbytes; | 602 | return outgoing_nbytes; |