* Re: master eb37e4814e 3/3: Fix unlikely null pointer dereference
[not found] ` <20220527184637.984F7C01683@vcs2.savannah.gnu.org>
@ 2022-05-28 0:46 ` Po Lu
2022-05-28 17:14 ` Paul Eggert
0 siblings, 1 reply; 3+ messages in thread
From: Po Lu @ 2022-05-28 0:46 UTC (permalink / raw)
To: emacs-devel; +Cc: Paul Eggert
Paul Eggert <eggert@cs.ucla.edu> writes:
> 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;
How can name be NULL if had_errors_p is false? x_get_atom_name always
returns something if need_sync is false, and XGetAtomName always returns
a string unless an error occured.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: master eb37e4814e 3/3: Fix unlikely null pointer dereference
2022-05-28 0:46 ` master eb37e4814e 3/3: Fix unlikely null pointer dereference Po Lu
@ 2022-05-28 17:14 ` Paul Eggert
2022-05-29 0:30 ` Po Lu
0 siblings, 1 reply; 3+ messages in thread
From: Paul Eggert @ 2022-05-28 17:14 UTC (permalink / raw)
To: Po Lu, emacs-devel
On 5/27/22 17:46, Po Lu wrote:
> How can name be NULL if had_errors_p is false? x_get_atom_name always
> returns something if need_sync is false, and XGetAtomName always returns
> a string unless an error occured.
Oh, you're right - I hadn't noticed that. So my recent patch didn't fix
any runtime bugs, though it did pacify GCC and I hope made the confusing
code a bit easier to follow for humans too.
I see you made further improvements in the area; thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: master eb37e4814e 3/3: Fix unlikely null pointer dereference
2022-05-28 17:14 ` Paul Eggert
@ 2022-05-29 0:30 ` Po Lu
0 siblings, 0 replies; 3+ messages in thread
From: Po Lu @ 2022-05-29 0:30 UTC (permalink / raw)
To: Paul Eggert; +Cc: emacs-devel
Paul Eggert <eggert@cs.ucla.edu> writes:
> Oh, you're right - I hadn't noticed that. So my recent patch didn't
> fix any runtime bugs, though it did pacify GCC and I hope made the
> confusing code a bit easier to follow for humans too.
Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-05-29 0:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <165367719442.14912.2771599004379547518@vcs2.savannah.gnu.org>
[not found] ` <20220527184637.984F7C01683@vcs2.savannah.gnu.org>
2022-05-28 0:46 ` master eb37e4814e 3/3: Fix unlikely null pointer dereference Po Lu
2022-05-28 17:14 ` Paul Eggert
2022-05-29 0:30 ` Po Lu
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).