From e0044dfeb0de0d0cafdef04b433b14afa27d3518 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Sat, 14 May 2022 20:07:27 +0800 Subject: [PATCH] Avoid unsafe alloca when looking up toplevels * src/xterm.c (x_dnd_compute_toplevels): Use SAFE_ALLOCA, since alloca isn't safe when there are lots of toplevels or the window manager is broken. --- src/xterm.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/xterm.c b/src/xterm.c index 64c4f91a184..c0d2ee40b0f 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -2106,27 +2106,29 @@ x_dnd_compute_toplevels (struct x_display_info *dpyinfo) toplevels = (Window *) data; #ifdef USE_XCB + USE_SAFE_ALLOCA; + window_attribute_cookies - = alloca (sizeof *window_attribute_cookies * nitems); + = SAFE_ALLOCA (sizeof *window_attribute_cookies * nitems); translate_coordinate_cookies - = alloca (sizeof *translate_coordinate_cookies * nitems); + = SAFE_ALLOCA (sizeof *translate_coordinate_cookies * nitems); get_property_cookies - = alloca (sizeof *get_property_cookies * nitems); + = SAFE_ALLOCA (sizeof *get_property_cookies * nitems); xm_property_cookies - = alloca (sizeof *xm_property_cookies * nitems); + = SAFE_ALLOCA (sizeof *xm_property_cookies * nitems); extent_property_cookies - = alloca (sizeof *extent_property_cookies * nitems); + = SAFE_ALLOCA (sizeof *extent_property_cookies * nitems); get_geometry_cookies - = alloca (sizeof *get_geometry_cookies * nitems); + = SAFE_ALLOCA (sizeof *get_geometry_cookies * nitems); #ifdef HAVE_XCB_SHAPE bounding_rect_cookies - = alloca (sizeof *bounding_rect_cookies * nitems); + = SAFE_ALLOCA (sizeof *bounding_rect_cookies * nitems); #endif #ifdef HAVE_XCB_SHAPE_INPUT_RECTS input_rect_cookies - = alloca (sizeof *input_rect_cookies * nitems); + = SAFE_ALLOCA (sizeof *input_rect_cookies * nitems); #endif for (i = 0; i < nitems; ++i) @@ -2606,6 +2608,10 @@ x_dnd_compute_toplevels (struct x_display_info *dpyinfo) #endif } +#ifdef USE_XCB + SAFE_FREE (); +#endif + return 0; } -- 2.39.2