diff options
| author | Paul Eggert | 2022-05-27 11:44:34 -0700 |
|---|---|---|
| committer | Paul Eggert | 2022-05-27 11:45:01 -0700 |
| commit | eb37e4814e354befaa12f80dc5e75368ad489a1e (patch) | |
| tree | 20faeb664f6ea83f632cff1481d7699198732d6d /src | |
| parent | cb57db513b3b5e2c5e09d197e63d6a921188d599 (diff) | |
| download | emacs-eb37e4814e354befaa12f80dc5e75368ad489a1e.tar.gz emacs-eb37e4814e354befaa12f80dc5e75368ad489a1e.zip | |
Fix unlikely null pointer dereference
* src/xselect.c (Fx_get_atom_name): Fix unlikely core dump when
build_string is called on a null pointer. Found by GCC -fanalyzer.
Diffstat (limited to 'src')
| -rw-r--r-- | src/xselect.c | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/src/xselect.c b/src/xselect.c index ae15fecccc5..3f35842daa0 100644 --- a/src/xselect.c +++ b/src/xselect.c | |||
| @@ -2454,9 +2454,6 @@ If the value is 0 or the atom is not known, return the empty string. */) | |||
| 2454 | (Lisp_Object value, Lisp_Object frame) | 2454 | (Lisp_Object value, Lisp_Object frame) |
| 2455 | { | 2455 | { |
| 2456 | struct frame *f = decode_window_system_frame (frame); | 2456 | struct frame *f = decode_window_system_frame (frame); |
| 2457 | char *name = 0; | ||
| 2458 | char empty[] = ""; | ||
| 2459 | Lisp_Object ret = Qnil; | ||
| 2460 | Display *dpy = FRAME_X_DISPLAY (f); | 2457 | Display *dpy = FRAME_X_DISPLAY (f); |
| 2461 | struct x_display_info *dpyinfo; | 2458 | struct x_display_info *dpyinfo; |
| 2462 | Atom atom; | 2459 | Atom atom; |
| @@ -2468,17 +2465,16 @@ If the value is 0 or the atom is not known, return the empty string. */) | |||
| 2468 | 2465 | ||
| 2469 | block_input (); | 2466 | block_input (); |
| 2470 | x_catch_errors (dpy); | 2467 | x_catch_errors (dpy); |
| 2471 | name = (atom ? x_get_atom_name (dpyinfo, atom, | 2468 | char *name = atom ? x_get_atom_name (dpyinfo, atom, &need_sync) : NULL; |
| 2472 | &need_sync) : empty); | ||
| 2473 | had_errors_p = need_sync && x_had_errors_p (dpy); | 2469 | had_errors_p = need_sync && x_had_errors_p (dpy); |
| 2474 | x_uncatch_errors_after_check (); | 2470 | x_uncatch_errors_after_check (); |
| 2475 | 2471 | Lisp_Object ret = empty_unibyte_string; | |
| 2476 | if (!had_errors_p) | 2472 | if (name) |
| 2477 | ret = build_string (name); | 2473 | { |
| 2478 | 2474 | if (!had_errors_p) | |
| 2479 | if (atom && name) xfree (name); | 2475 | ret = build_string (name); |
| 2480 | if (NILP (ret)) ret = empty_unibyte_string; | 2476 | xfree (name); |
| 2481 | 2477 | } | |
| 2482 | unblock_input (); | 2478 | unblock_input (); |
| 2483 | 2479 | ||
| 2484 | return ret; | 2480 | return ret; |