emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master eb37e4814e 3/3: Fix unlikely null pointer dereference


From: Paul Eggert
Subject: master eb37e4814e 3/3: Fix unlikely null pointer dereference
Date: Fri, 27 May 2022 14:46:36 -0400 (EDT)

branch: master
commit eb37e4814e354befaa12f80dc5e75368ad489a1e
Author: Paul Eggert <eggert@cs.ucla.edu>
Commit: Paul Eggert <eggert@cs.ucla.edu>

    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.
---
 src/xselect.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/src/xselect.c b/src/xselect.c
index ae15fecccc..3f35842daa 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.  */)
   (Lisp_Object value, Lisp_Object frame)
 {
   struct frame *f = decode_window_system_frame (frame);
-  char *name = 0;
-  char empty[] = "";
-  Lisp_Object ret = Qnil;
   Display *dpy = FRAME_X_DISPLAY (f);
   struct x_display_info *dpyinfo;
   Atom atom;
@@ -2468,17 +2465,16 @@ If the value is 0 or the atom is not known, return the 
empty string.  */)
 
   block_input ();
   x_catch_errors (dpy);
-  name = (atom ? x_get_atom_name (dpyinfo, atom,
-                                 &need_sync) : empty);
+  char *name = atom ? x_get_atom_name (dpyinfo, atom, &need_sync) : NULL;
   had_errors_p = need_sync && x_had_errors_p (dpy);
   x_uncatch_errors_after_check ();
-
-  if (!had_errors_p)
-    ret = build_string (name);
-
-  if (atom && name) xfree (name);
-  if (NILP (ret)) ret = empty_unibyte_string;
-
+  Lisp_Object ret = empty_unibyte_string;
+  if (name)
+    {
+      if (!had_errors_p)
+       ret = build_string (name);
+      xfree (name);
+    }
   unblock_input ();
 
   return ret;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]