From 5913c2cbe9f83d4fe163bf779b72a875bb20e271 Mon Sep 17 00:00:00 2001 From: Alexei Sorokin Date: Thu, 2 Feb 2017 18:52:49 +0300 Subject: mate-bg: Avoid possible X11 data leaks --- libmate-desktop/mate-bg.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/libmate-desktop/mate-bg.c b/libmate-desktop/mate-bg.c index e8c198a..c213354 100644 --- a/libmate-desktop/mate-bg.c +++ b/libmate-desktop/mate-bg.c @@ -1651,7 +1651,7 @@ mate_bg_set_root_pixmap_id (GdkScreen *screen, Atom atoms[G_N_ELEMENTS(atom_names)] = {0}; Atom type; - int format; + int format, result; unsigned long nitems, after; unsigned char *data_root, *data_esetroot; @@ -1659,20 +1659,24 @@ mate_bg_set_root_pixmap_id (GdkScreen *screen, * This method is to avoid multiple round-trips to Xserver */ if (XInternAtoms (display, atom_names, G_N_ELEMENTS(atom_names), True, atoms) && - atoms[0] != None && atoms[1] != None) - { - XGetWindowProperty (display, xroot, atoms[0], 0L, 1L, False, AnyPropertyType, - &type, &format, &nitems, &after, &data_root); - if (data_root && type == XA_PIXMAP && format == 32 && nitems == 1) - { - XGetWindowProperty (display, xroot, atoms[1], 0L, 1L, False, AnyPropertyType, - &type, &format, &nitems, &after, &data_esetroot); - if (data_esetroot && type == XA_PIXMAP && format == 32 && nitems == 1) - { + atoms[0] != None && atoms[1] != None) { + result = XGetWindowProperty (display, xroot, atoms[0], 0L, 1L, + False, AnyPropertyType, + &type, &format, &nitems, &after, + &data_root); + + if (data_root != NULL && result == Success && + type == XA_PIXMAP && format == 32 && nitems == 1) { + result = XGetWindowProperty (display, xroot, atoms[1], + 0L, 1L, False, + AnyPropertyType, + &type, &format, &nitems, + &after, &data_esetroot); + + if (data_esetroot != NULL && result == Success && + type == XA_PIXMAP && format == 32 && nitems == 1) { Pixmap xrootpmap = *((Pixmap *) data_root); Pixmap esetrootpmap = *((Pixmap *) data_esetroot); - XFree (data_root); - XFree (data_esetroot); gdk_error_trap_push (); if (xrootpmap && xrootpmap == esetrootpmap) { @@ -1686,6 +1690,12 @@ mate_bg_set_root_pixmap_id (GdkScreen *screen, # endif gdk_error_trap_pop_ignored (); } + if (data_esetroot != NULL) { + XFree (data_esetroot); + } + } + if (data_root != NULL) { + XFree (data_root); } } -- cgit v1.2.1