Avoid crashes in Mew due to corrupted tool-bar label

* src/gtkutil.c (update_frame_tool_bar): Don't keep around a
'char *' pointer to a Lisp string's contents when calling Lisp,
because that could relocate string data; keep the Lisp string
itself instead.  This avoids crashes in Mew.  (Bug#46791)
This commit is contained in:
Eli Zaretskii 2021-02-27 09:26:55 +02:00
parent 7a23915618
commit 2c5f215419

View file

@ -5019,11 +5019,10 @@ update_frame_tool_bar (struct frame *f)
GtkWidget *wbutton = NULL; GtkWidget *wbutton = NULL;
Lisp_Object specified_file; Lisp_Object specified_file;
bool vert_only = ! NILP (PROP (TOOL_BAR_ITEM_VERT_ONLY)); bool vert_only = ! NILP (PROP (TOOL_BAR_ITEM_VERT_ONLY));
const char *label Lisp_Object label
= (EQ (style, Qimage) || (vert_only && horiz)) ? NULL = (EQ (style, Qimage) || (vert_only && horiz))
: STRINGP (PROP (TOOL_BAR_ITEM_LABEL)) ? Qnil
? SSDATA (PROP (TOOL_BAR_ITEM_LABEL)) : PROP (TOOL_BAR_ITEM_LABEL);
: "";
ti = gtk_toolbar_get_nth_item (GTK_TOOLBAR (wtoolbar), j); ti = gtk_toolbar_get_nth_item (GTK_TOOLBAR (wtoolbar), j);
@ -5136,8 +5135,11 @@ update_frame_tool_bar (struct frame *f)
/* If there is an existing widget, check if it's stale; if so, /* If there is an existing widget, check if it's stale; if so,
remove it and make a new tool item from scratch. */ remove it and make a new tool item from scratch. */
if (ti && xg_tool_item_stale_p (wbutton, stock_name, icon_name, if (ti && xg_tool_item_stale_p (wbutton, stock_name, icon_name, img,
img, label, horiz)) NILP (label)
? NULL
: STRINGP (label) ? SSDATA (label) : "",
horiz))
{ {
gtk_container_remove (GTK_CONTAINER (wtoolbar), gtk_container_remove (GTK_CONTAINER (wtoolbar),
GTK_WIDGET (ti)); GTK_WIDGET (ti));
@ -5194,7 +5196,11 @@ update_frame_tool_bar (struct frame *f)
#else #else
if (w) gtk_misc_set_padding (GTK_MISC (w), hmargin, vmargin); if (w) gtk_misc_set_padding (GTK_MISC (w), hmargin, vmargin);
#endif #endif
ti = xg_make_tool_item (f, w, &wbutton, label, i, horiz, text_image); ti = xg_make_tool_item (f, w, &wbutton,
NILP (label)
? NULL
: STRINGP (label) ? SSDATA (label) : "",
i, horiz, text_image);
gtk_toolbar_insert (GTK_TOOLBAR (wtoolbar), ti, j); gtk_toolbar_insert (GTK_TOOLBAR (wtoolbar), ti, j);
} }