diff options
| author | Paul Eggert | 2011-07-28 18:13:10 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-07-28 18:13:10 -0700 |
| commit | 5f2ab479cdd2e76862e80e37b9c0825471af8d4c (patch) | |
| tree | 794acd034534a978fe96e8fd54de2a823b096514 /src | |
| parent | 1d5689025c709551296684432b04d1ad39e90c71 (diff) | |
| download | emacs-5f2ab479cdd2e76862e80e37b9c0825471af8d4c.tar.gz emacs-5f2ab479cdd2e76862e80e37b9c0825471af8d4c.zip | |
* search.c: Integer and memory overflow fixes.
(Freplace_match): Check for size calculation overflow.
(Fset_match_data): Don't assume list lengths fit in 'int'.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 4 | ||||
| -rw-r--r-- | src/search.c | 16 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index a80c370e0ad..7570b0ba979 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,9 @@ | |||
| 1 | 2011-07-29 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2011-07-29 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 2 | ||
| 3 | * search.c: Integer and memory overflow fixes. | ||
| 4 | (Freplace_match): Check for size calculation overflow. | ||
| 5 | (Fset_match_data): Don't assume list lengths fit in 'int'. | ||
| 6 | |||
| 3 | * scroll.c: Integer and memory overflow fixes. | 7 | * scroll.c: Integer and memory overflow fixes. |
| 4 | (do_line_insertion_deletion_costs): Check for size calculation overflow. | 8 | (do_line_insertion_deletion_costs): Check for size calculation overflow. |
| 5 | Don't bother calling xmalloc when xrealloc will do. | 9 | Don't bother calling xmalloc when xrealloc will do. |
diff --git a/src/search.c b/src/search.c index a56df784cd2..79ef8b046df 100644 --- a/src/search.c +++ b/src/search.c | |||
| @@ -2648,6 +2648,8 @@ since only regular expressions have distinguished subexpressions. */) | |||
| 2648 | int really_changed = 0; | 2648 | int really_changed = 0; |
| 2649 | 2649 | ||
| 2650 | substed_alloc_size = length * 2 + 100; | 2650 | substed_alloc_size = length * 2 + 100; |
| 2651 | if (min (PTRDIFF_MAX, SIZE_MAX) - 1 < substed_alloc_size) | ||
| 2652 | memory_full (SIZE_MAX); | ||
| 2651 | substed = (unsigned char *) xmalloc (substed_alloc_size + 1); | 2653 | substed = (unsigned char *) xmalloc (substed_alloc_size + 1); |
| 2652 | substed_len = 0; | 2654 | substed_len = 0; |
| 2653 | 2655 | ||
| @@ -2736,6 +2738,13 @@ since only regular expressions have distinguished subexpressions. */) | |||
| 2736 | /* Make sure SUBSTED is big enough. */ | 2738 | /* Make sure SUBSTED is big enough. */ |
| 2737 | if (substed_len + add_len >= substed_alloc_size) | 2739 | if (substed_len + add_len >= substed_alloc_size) |
| 2738 | { | 2740 | { |
| 2741 | ptrdiff_t add_len_max = | ||
| 2742 | min (PTRDIFF_MAX, SIZE_MAX) - 1 - 500 - substed_len; | ||
| 2743 | if (add_len_max < add_len) | ||
| 2744 | { | ||
| 2745 | xfree (substed); | ||
| 2746 | memory_full (SIZE_MAX); | ||
| 2747 | } | ||
| 2739 | substed_alloc_size = substed_len + add_len + 500; | 2748 | substed_alloc_size = substed_len + add_len + 500; |
| 2740 | substed = (unsigned char *) xrealloc (substed, | 2749 | substed = (unsigned char *) xrealloc (substed, |
| 2741 | substed_alloc_size + 1); | 2750 | substed_alloc_size + 1); |
| @@ -2973,7 +2982,7 @@ LIST should have been created by calling `match-data' previously. | |||
| 2973 | If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */) | 2982 | If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */) |
| 2974 | (register Lisp_Object list, Lisp_Object reseat) | 2983 | (register Lisp_Object list, Lisp_Object reseat) |
| 2975 | { | 2984 | { |
| 2976 | register int i; | 2985 | ptrdiff_t i; |
| 2977 | register Lisp_Object marker; | 2986 | register Lisp_Object marker; |
| 2978 | 2987 | ||
| 2979 | if (running_asynch_code) | 2988 | if (running_asynch_code) |
| @@ -2987,10 +2996,13 @@ If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */) | |||
| 2987 | 2996 | ||
| 2988 | /* Allocate registers if they don't already exist. */ | 2997 | /* Allocate registers if they don't already exist. */ |
| 2989 | { | 2998 | { |
| 2990 | int length = XFASTINT (Flength (list)) / 2; | 2999 | ptrdiff_t length = XFASTINT (Flength (list)) / 2; |
| 2991 | 3000 | ||
| 2992 | if (length > search_regs.num_regs) | 3001 | if (length > search_regs.num_regs) |
| 2993 | { | 3002 | { |
| 3003 | if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof (regoff_t) < length) | ||
| 3004 | memory_full (SIZE_MAX); | ||
| 3005 | |||
| 2994 | if (search_regs.num_regs == 0) | 3006 | if (search_regs.num_regs == 0) |
| 2995 | { | 3007 | { |
| 2996 | search_regs.start | 3008 | search_regs.start |