From: Po Lu Date: Fri, 20 May 2022 12:03:05 +0000 (+0800) Subject: Check for allocation errors when setting XdndActionDescription X-Git-Tag: emacs-29.0.90~1910^2~557 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=8db0acb0f06ca35c366d896341147f616c048c25;p=emacs.git Check for allocation errors when setting XdndActionDescription * src/xterm.c (x_dnd_begin_drag_and_drop): Check for BadAlloc when setting action descriptions. --- diff --git a/src/xterm.c b/src/xterm.c index a3b7c4ac257..46f55cb9947 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -10101,7 +10101,7 @@ x_dnd_begin_drag_and_drop (struct frame *f, Time time, Atom xaction, struct frame *any; char *atom_name, *ask_actions; Lisp_Object action, ltimestamp; - specpdl_ref ref; + specpdl_ref ref, count; ptrdiff_t i, end, fill; XTextProperty prop; xm_drop_start_message dmsg; @@ -10228,6 +10228,7 @@ x_dnd_begin_drag_and_drop (struct frame *f, Time time, Atom xaction, { ask_actions = NULL; end = 0; + count = SPECPDL_INDEX (); for (i = 0; i < n_ask_actions; ++i) { @@ -10249,16 +10250,25 @@ x_dnd_begin_drag_and_drop (struct frame *f, Time time, Atom xaction, prop.format = 8; prop.nitems = end; + record_unwind_protect_ptr (xfree, ask_actions); + + /* This can potentially store a lot of data in window + properties, so check for allocation errors. */ block_input (); + x_catch_errors (FRAME_X_DISPLAY (f)); XSetTextProperty (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &prop, FRAME_DISPLAY_INFO (f)->Xatom_XdndActionDescription); - xfree (ask_actions); XChangeProperty (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), FRAME_DISPLAY_INFO (f)->Xatom_XdndActionList, XA_ATOM, 32, PropModeReplace, (unsigned char *) ask_action_list, n_ask_actions); + x_check_errors (FRAME_X_DISPLAY (f), + "Can't set action descriptions: %s"); + x_uncatch_errors_after_check (); unblock_input (); + + unbind_to (count, Qnil); } else {