diff options
| author | Paul Eggert | 2011-06-21 10:49:46 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-06-21 10:49:46 -0700 |
| commit | aaafe47af10d234df2483bace35336a79736cc8b (patch) | |
| tree | bc2b5a6ad4347de31a74c3a6763595504cf8ad88 /src | |
| parent | da3f12b238fbbf4632bdf137b08446b1ee655faf (diff) | |
| download | emacs-aaafe47af10d234df2483bace35336a79736cc8b.tar.gz emacs-aaafe47af10d234df2483bace35336a79736cc8b.zip | |
* xsettings.c (apply_xft_settings): Fix potential buffer overrun.
This is unlikely, but can occur if DPI is outlandish.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 3 | ||||
| -rw-r--r-- | src/xsettings.c | 36 |
2 files changed, 24 insertions, 15 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 0c7cac342d9..ad84e3271e4 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,8 @@ | |||
| 1 | 2011-06-21 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2011-06-21 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 2 | ||
| 3 | * xsettings.c (apply_xft_settings): Fix potential buffer overrun. | ||
| 4 | This is unlikely, but can occur if DPI is outlandish. | ||
| 5 | |||
| 3 | * xselect.c (Fx_get_atom_name): Avoid need for strlen. | 6 | * xselect.c (Fx_get_atom_name): Avoid need for strlen. |
| 4 | 7 | ||
| 5 | * xrdb.c: Don't assume strlen fits in int; avoid some strlens. | 8 | * xrdb.c: Don't assume strlen fits in int; avoid some strlens. |
diff --git a/src/xsettings.c b/src/xsettings.c index 2513bcc5aa8..c8cb9529647 100644 --- a/src/xsettings.c +++ b/src/xsettings.c | |||
| @@ -18,6 +18,8 @@ You should have received a copy of the GNU General Public License | |||
| 18 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | 18 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
| 19 | 19 | ||
| 20 | #include <config.h> | 20 | #include <config.h> |
| 21 | |||
| 22 | #include <float.h> | ||
| 21 | #include <limits.h> | 23 | #include <limits.h> |
| 22 | #include <setjmp.h> | 24 | #include <setjmp.h> |
| 23 | #include <fcntl.h> | 25 | #include <fcntl.h> |
| @@ -434,10 +436,8 @@ apply_xft_settings (struct x_display_info *dpyinfo, | |||
| 434 | FcPattern *pat; | 436 | FcPattern *pat; |
| 435 | struct xsettings oldsettings; | 437 | struct xsettings oldsettings; |
| 436 | int changed = 0; | 438 | int changed = 0; |
| 437 | char buf[256]; | ||
| 438 | 439 | ||
| 439 | memset (&oldsettings, 0, sizeof (oldsettings)); | 440 | memset (&oldsettings, 0, sizeof (oldsettings)); |
| 440 | buf[0] = '\0'; | ||
| 441 | pat = FcPatternCreate (); | 441 | pat = FcPatternCreate (); |
| 442 | XftDefaultSubstitute (dpyinfo->display, | 442 | XftDefaultSubstitute (dpyinfo->display, |
| 443 | XScreenNumberOfScreen (dpyinfo->screen), | 443 | XScreenNumberOfScreen (dpyinfo->screen), |
| @@ -458,7 +458,6 @@ apply_xft_settings (struct x_display_info *dpyinfo, | |||
| 458 | ++changed; | 458 | ++changed; |
| 459 | oldsettings.aa = settings->aa; | 459 | oldsettings.aa = settings->aa; |
| 460 | } | 460 | } |
| 461 | sprintf (buf, "Antialias: %d", oldsettings.aa); | ||
| 462 | 461 | ||
| 463 | if ((settings->seen & SEEN_HINTING) != 0 | 462 | if ((settings->seen & SEEN_HINTING) != 0 |
| 464 | && oldsettings.hinting != settings->hinting) | 463 | && oldsettings.hinting != settings->hinting) |
| @@ -468,8 +467,6 @@ apply_xft_settings (struct x_display_info *dpyinfo, | |||
| 468 | ++changed; | 467 | ++changed; |
| 469 | oldsettings.hinting = settings->hinting; | 468 | oldsettings.hinting = settings->hinting; |
| 470 | } | 469 | } |
| 471 | if (strlen (buf) > 0) strcat (buf, ", "); | ||
| 472 | sprintf (buf+strlen (buf), "Hinting: %d", oldsettings.hinting); | ||
| 473 | if ((settings->seen & SEEN_RGBA) != 0 && oldsettings.rgba != settings->rgba) | 470 | if ((settings->seen & SEEN_RGBA) != 0 && oldsettings.rgba != settings->rgba) |
| 474 | { | 471 | { |
| 475 | FcPatternDel (pat, FC_RGBA); | 472 | FcPatternDel (pat, FC_RGBA); |
| @@ -477,8 +474,6 @@ apply_xft_settings (struct x_display_info *dpyinfo, | |||
| 477 | oldsettings.rgba = settings->rgba; | 474 | oldsettings.rgba = settings->rgba; |
| 478 | ++changed; | 475 | ++changed; |
| 479 | } | 476 | } |
| 480 | if (strlen (buf) > 0) strcat (buf, ", "); | ||
| 481 | sprintf (buf+strlen (buf), "RGBA: %d", oldsettings.rgba); | ||
| 482 | 477 | ||
| 483 | /* Older fontconfig versions don't have FC_LCD_FILTER. */ | 478 | /* Older fontconfig versions don't have FC_LCD_FILTER. */ |
| 484 | if ((settings->seen & SEEN_LCDFILTER) != 0 | 479 | if ((settings->seen & SEEN_LCDFILTER) != 0 |
| @@ -489,8 +484,6 @@ apply_xft_settings (struct x_display_info *dpyinfo, | |||
| 489 | ++changed; | 484 | ++changed; |
| 490 | oldsettings.lcdfilter = settings->lcdfilter; | 485 | oldsettings.lcdfilter = settings->lcdfilter; |
| 491 | } | 486 | } |
| 492 | if (strlen (buf) > 0) strcat (buf, ", "); | ||
| 493 | sprintf (buf+strlen (buf), "LCDFilter: %d", oldsettings.lcdfilter); | ||
| 494 | 487 | ||
| 495 | # ifdef FC_HINT_STYLE | 488 | # ifdef FC_HINT_STYLE |
| 496 | if ((settings->seen & SEEN_HINTSTYLE) != 0 | 489 | if ((settings->seen & SEEN_HINTSTYLE) != 0 |
| @@ -502,8 +495,6 @@ apply_xft_settings (struct x_display_info *dpyinfo, | |||
| 502 | oldsettings.hintstyle = settings->hintstyle; | 495 | oldsettings.hintstyle = settings->hintstyle; |
| 503 | } | 496 | } |
| 504 | # endif | 497 | # endif |
| 505 | if (strlen (buf) > 0) strcat (buf, ", "); | ||
| 506 | sprintf (buf+strlen (buf), "Hintstyle: %d", oldsettings.hintstyle); | ||
| 507 | 498 | ||
| 508 | if ((settings->seen & SEEN_DPI) != 0 && oldsettings.dpi != settings->dpi | 499 | if ((settings->seen & SEEN_DPI) != 0 && oldsettings.dpi != settings->dpi |
| 509 | && settings->dpi > 0) | 500 | && settings->dpi > 0) |
| @@ -523,16 +514,31 @@ apply_xft_settings (struct x_display_info *dpyinfo, | |||
| 523 | XFRAME (frame)->resy = XFRAME (frame)->resx = settings->dpi; | 514 | XFRAME (frame)->resy = XFRAME (frame)->resx = settings->dpi; |
| 524 | } | 515 | } |
| 525 | 516 | ||
| 526 | if (strlen (buf) > 0) strcat (buf, ", "); | ||
| 527 | sprintf (buf+strlen (buf), "DPI: %lf", oldsettings.dpi); | ||
| 528 | |||
| 529 | if (changed) | 517 | if (changed) |
| 530 | { | 518 | { |
| 519 | static char const format[] = | ||
| 520 | "Antialias: %d, Hinting: %d, RGBA: %d, LCDFilter: %d, " | ||
| 521 | "Hintstyle: %d, DPI: %lf"; | ||
| 522 | enum | ||
| 523 | { | ||
| 524 | d_formats = 5, | ||
| 525 | d_growth = INT_BUFSIZE_BOUND (int) - sizeof "%d", | ||
| 526 | lf_formats = 1, | ||
| 527 | max_f_integer_digits = DBL_MAX_10_EXP + 1, | ||
| 528 | f_precision = 6, | ||
| 529 | lf_growth = (sizeof "-." + max_f_integer_digits + f_precision | ||
| 530 | - sizeof "%lf") | ||
| 531 | }; | ||
| 532 | char buf[sizeof format + d_formats * d_growth + lf_formats * lf_growth]; | ||
| 533 | |||
| 531 | XftDefaultSet (dpyinfo->display, pat); | 534 | XftDefaultSet (dpyinfo->display, pat); |
| 532 | if (send_event_p) | 535 | if (send_event_p) |
| 533 | store_config_changed_event (Qfont_render, | 536 | store_config_changed_event (Qfont_render, |
| 534 | XCAR (dpyinfo->name_list_element)); | 537 | XCAR (dpyinfo->name_list_element)); |
| 535 | Vxft_settings = make_string (buf, strlen (buf)); | 538 | sprintf (buf, format, oldsettings.aa, oldsettings.hinting, |
| 539 | oldsettings.rgba, oldsettings.lcdfilter, | ||
| 540 | oldsettings.hintstyle, oldsettings.dpi); | ||
| 541 | Vxft_settings = build_string (buf); | ||
| 536 | } | 542 | } |
| 537 | else | 543 | else |
| 538 | FcPatternDestroy (pat); | 544 | FcPatternDestroy (pat); |