diff options
| author | Eli Zaretskii | 2012-11-12 17:25:34 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2012-11-12 17:25:34 +0200 |
| commit | 325202732506c35fec0a7bd772d218eaf0ac659f (patch) | |
| tree | 52dd6a03fab8b8ab3bd61db62a184d0f8e0b10c6 /src | |
| parent | 2e6625b527f5ad134e28af5c2eba0349c640c942 (diff) | |
| download | emacs-325202732506c35fec0a7bd772d218eaf0ac659f.tar.gz emacs-325202732506c35fec0a7bd772d218eaf0ac659f.zip | |
Fix bug #12867 with crashes due to large field width in mode-line format.
src/xdisp.c (decode_mode_spec): Limit the value of WIDTH argument
passed to pint2str and pint2hrstr to be at most the size of the
frame's decode_mode_spec_buffer. This avoids crashes with very
large values of FIELD_WIDTH argument to decode_mode_spec.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 8 | ||||
| -rw-r--r-- | src/xdisp.c | 16 |
2 files changed, 19 insertions, 5 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 9e0f92f557e..494b2179516 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2012-11-12 Eli Zaretskii <eliz@gnu.org> | ||
| 2 | |||
| 3 | * xdisp.c (decode_mode_spec): Limit the value of WIDTH argument | ||
| 4 | passed to pint2str and pint2hrstr to be at most the size of the | ||
| 5 | frame's decode_mode_spec_buffer. This avoids crashes with very | ||
| 6 | large values of FIELD_WIDTH argument to decode_mode_spec. | ||
| 7 | (Bug#12867) | ||
| 8 | |||
| 1 | 2012-11-07 Martin Rudalics <rudalics@gmx.at> | 9 | 2012-11-07 Martin Rudalics <rudalics@gmx.at> |
| 2 | 10 | ||
| 3 | * window.c (Fsplit_window_internal): Set combination limit of | 11 | * window.c (Fsplit_window_internal): Set combination limit of |
diff --git a/src/xdisp.c b/src/xdisp.c index c7195504c4c..290c3a07fe9 100644 --- a/src/xdisp.c +++ b/src/xdisp.c | |||
| @@ -21380,6 +21380,12 @@ decode_mode_spec (struct window *w, register int c, int field_width, | |||
| 21380 | Lisp_Object obj; | 21380 | Lisp_Object obj; |
| 21381 | struct frame *f = XFRAME (WINDOW_FRAME (w)); | 21381 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
| 21382 | char *decode_mode_spec_buf = f->decode_mode_spec_buffer; | 21382 | char *decode_mode_spec_buf = f->decode_mode_spec_buffer; |
| 21383 | /* We are going to use f->decode_mode_spec_buffer as the buffer to | ||
| 21384 | produce strings from numerical values, so limit preposterously | ||
| 21385 | large values of FIELD_WIDTH to avoid overrunning the buffer's | ||
| 21386 | end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE | ||
| 21387 | bytes plus the terminating null. */ | ||
| 21388 | int width = min (field_width, FRAME_MESSAGE_BUF_SIZE (f)); | ||
| 21383 | struct buffer *b = current_buffer; | 21389 | struct buffer *b = current_buffer; |
| 21384 | 21390 | ||
| 21385 | obj = Qnil; | 21391 | obj = Qnil; |
| @@ -21475,7 +21481,7 @@ decode_mode_spec (struct window *w, register int c, int field_width, | |||
| 21475 | { | 21481 | { |
| 21476 | ptrdiff_t col = current_column (); | 21482 | ptrdiff_t col = current_column (); |
| 21477 | wset_column_number_displayed (w, make_number (col)); | 21483 | wset_column_number_displayed (w, make_number (col)); |
| 21478 | pint2str (decode_mode_spec_buf, field_width, col); | 21484 | pint2str (decode_mode_spec_buf, width, col); |
| 21479 | return decode_mode_spec_buf; | 21485 | return decode_mode_spec_buf; |
| 21480 | } | 21486 | } |
| 21481 | 21487 | ||
| @@ -21506,14 +21512,14 @@ decode_mode_spec (struct window *w, register int c, int field_width, | |||
| 21506 | case 'i': | 21512 | case 'i': |
| 21507 | { | 21513 | { |
| 21508 | ptrdiff_t size = ZV - BEGV; | 21514 | ptrdiff_t size = ZV - BEGV; |
| 21509 | pint2str (decode_mode_spec_buf, field_width, size); | 21515 | pint2str (decode_mode_spec_buf, width, size); |
| 21510 | return decode_mode_spec_buf; | 21516 | return decode_mode_spec_buf; |
| 21511 | } | 21517 | } |
| 21512 | 21518 | ||
| 21513 | case 'I': | 21519 | case 'I': |
| 21514 | { | 21520 | { |
| 21515 | ptrdiff_t size = ZV - BEGV; | 21521 | ptrdiff_t size = ZV - BEGV; |
| 21516 | pint2hrstr (decode_mode_spec_buf, field_width, size); | 21522 | pint2hrstr (decode_mode_spec_buf, width, size); |
| 21517 | return decode_mode_spec_buf; | 21523 | return decode_mode_spec_buf; |
| 21518 | } | 21524 | } |
| 21519 | 21525 | ||
| @@ -21620,12 +21626,12 @@ decode_mode_spec (struct window *w, register int c, int field_width, | |||
| 21620 | line_number_displayed = 1; | 21626 | line_number_displayed = 1; |
| 21621 | 21627 | ||
| 21622 | /* Make the string to show. */ | 21628 | /* Make the string to show. */ |
| 21623 | pint2str (decode_mode_spec_buf, field_width, topline + nlines); | 21629 | pint2str (decode_mode_spec_buf, width, topline + nlines); |
| 21624 | return decode_mode_spec_buf; | 21630 | return decode_mode_spec_buf; |
| 21625 | no_value: | 21631 | no_value: |
| 21626 | { | 21632 | { |
| 21627 | char* p = decode_mode_spec_buf; | 21633 | char* p = decode_mode_spec_buf; |
| 21628 | int pad = field_width - 2; | 21634 | int pad = width - 2; |
| 21629 | while (pad-- > 0) | 21635 | while (pad-- > 0) |
| 21630 | *p++ = ' '; | 21636 | *p++ = ' '; |
| 21631 | *p++ = '?'; | 21637 | *p++ = '?'; |