From 0284b144340a455a4b5b5011d81ac5a610372291 Mon Sep 17 00:00:00 2001 From: David Baron Date: Fri, 30 Mar 2007 17:07:46 +0200 Subject: Bug #7703: Fixed XSetSizeHints() et al wrt use of uninitialized data. Now only those fields of the respective hint struct are set that are actually valid in the input data. The changed functions are: XSetSizeHints(), XSetWMHints() and XSetWMSizeHints(). --- src/SetHints.c | 68 +++++++++++++++++++++++++++++++++++++------------------- src/SetNrmHint.c | 53 ++++++++++++++++++++++++++++--------------- 2 files changed, 80 insertions(+), 41 deletions(-) diff --git a/src/SetHints.c b/src/SetHints.c index 5ee3443..a918e4e 100644 --- a/src/SetHints.c +++ b/src/SetHints.c @@ -66,22 +66,35 @@ XSetSizeHints(dpy, w, hints, property) /* old routine */ XSizeHints *hints; Atom property; { - xPropSizeHints prop; + xPropSizeHints prop; + memset(&prop, 0, sizeof(prop)); prop.flags = (hints->flags & (USPosition|USSize|PAllHints)); - prop.x = hints->x; - prop.y = hints->y; - prop.width = hints->width; - prop.height = hints->height; - prop.minWidth = hints->min_width; - prop.minHeight = hints->min_height; - prop.maxWidth = hints->max_width; - prop.maxHeight = hints->max_height; - prop.widthInc = hints->width_inc; - prop.heightInc = hints->height_inc; - prop.minAspectX = hints->min_aspect.x; - prop.minAspectY = hints->min_aspect.y; - prop.maxAspectX = hints->max_aspect.x; - prop.maxAspectY = hints->max_aspect.y; + if (hints->flags & (USPosition|PPosition)) { + prop.x = hints->x; + prop.y = hints->y; + } + if (hints->flags & (USSize|PSize)) { + prop.width = hints->width; + prop.height = hints->height; + } + if (hints->flags & PMinSize) { + prop.minWidth = hints->min_width; + prop.minHeight = hints->min_height; + } + if (hints->flags & PMaxSize) { + prop.maxWidth = hints->max_width; + prop.maxHeight = hints->max_height; + } + if (hints->flags & PResizeInc) { + prop.widthInc = hints->width_inc; + prop.heightInc = hints->height_inc; + } + if (hints->flags & PAspect) { + prop.minAspectX = hints->min_aspect.x; + prop.minAspectY = hints->min_aspect.y; + prop.maxAspectX = hints->max_aspect.x; + prop.maxAspectY = hints->max_aspect.y; + } return XChangeProperty (dpy, w, property, XA_WM_SIZE_HINTS, 32, PropModeReplace, (unsigned char *) &prop, OldNumPropSizeElements); @@ -99,15 +112,24 @@ XSetWMHints (dpy, w, wmhints) XWMHints *wmhints; { xPropWMHints prop; + memset(&prop, 0, sizeof(prop)); prop.flags = wmhints->flags; - prop.input = (wmhints->input == True ? 1 : 0); - prop.initialState = wmhints->initial_state; - prop.iconPixmap = wmhints->icon_pixmap; - prop.iconWindow = wmhints->icon_window; - prop.iconX = wmhints->icon_x; - prop.iconY = wmhints->icon_y; - prop.iconMask = wmhints->icon_mask; - prop.windowGroup = wmhints->window_group; + if (wmhints->flags & InputHint) + prop.input = (wmhints->input == True ? 1 : 0); + if (wmhints->flags & StateHint) + prop.initialState = wmhints->initial_state; + if (wmhints->flags & IconPixmapHint) + prop.iconPixmap = wmhints->icon_pixmap; + if (wmhints->flags & IconWindowHint) + prop.iconWindow = wmhints->icon_window; + if (wmhints->flags & IconPositionHint) { + prop.iconX = wmhints->icon_x; + prop.iconY = wmhints->icon_y; + } + if (wmhints->flags & IconMaskHint) + prop.iconMask = wmhints->icon_mask; + if (wmhints->flags & WindowGroupHint) + prop.windowGroup = wmhints->window_group; return XChangeProperty (dpy, w, XA_WM_HINTS, XA_WM_HINTS, 32, PropModeReplace, (unsigned char *) &prop, NumPropWMHintsElements); diff --git a/src/SetNrmHint.c b/src/SetNrmHint.c index 64b0ef7..9e659bb 100644 --- a/src/SetNrmHint.c +++ b/src/SetNrmHint.c @@ -68,6 +68,7 @@ void XSetWMSizeHints (dpy, w, hints, prop) { xPropSizeHints data; + memset(&data, 0, sizeof(data)); data.flags = (hints->flags & (USPosition|USSize|PPosition|PSize|PMinSize|PMaxSize| PResizeInc|PAspect|PBaseSize|PWinGravity)); @@ -76,24 +77,40 @@ void XSetWMSizeHints (dpy, w, hints, prop) * The x, y, width, and height fields are obsolete; but, applications * that want to work with old window managers might set them. */ - data.x = hints->x; - data.y = hints->y; - data.width = hints->width; - data.height = hints->height; - - data.minWidth = hints->min_width; - data.minHeight = hints->min_height; - data.maxWidth = hints->max_width; - data.maxHeight = hints->max_height; - data.widthInc = hints->width_inc; - data.heightInc = hints->height_inc; - data.minAspectX = hints->min_aspect.x; - data.minAspectY = hints->min_aspect.y; - data.maxAspectX = hints->max_aspect.x; - data.maxAspectY = hints->max_aspect.y; - data.baseWidth = hints->base_width; - data.baseHeight = hints->base_height; - data.winGravity = hints->win_gravity; + if (hints->flags & (USPosition|PPosition)) { + data.x = hints->x; + data.y = hints->y; + } + if (hints->flags & (USSize|PSize)) { + data.width = hints->width; + data.height = hints->height; + } + + if (hints->flags & PMinSize) { + data.minWidth = hints->min_width; + data.minHeight = hints->min_height; + } + if (hints->flags & PMaxSize) { + data.maxWidth = hints->max_width; + data.maxHeight = hints->max_height; + } + if (hints->flags & PResizeInc) { + data.widthInc = hints->width_inc; + data.heightInc = hints->height_inc; + } + if (hints->flags & PAspect) { + data.minAspectX = hints->min_aspect.x; + data.minAspectY = hints->min_aspect.y; + data.maxAspectX = hints->max_aspect.x; + data.maxAspectY = hints->max_aspect.y; + } + if (hints->flags & PBaseSize) { + data.baseWidth = hints->base_width; + data.baseHeight = hints->base_height; + } + if (hints->flags & PWinGravity) { + data.winGravity = hints->win_gravity; + } XChangeProperty (dpy, w, prop, XA_WM_SIZE_HINTS, 32, PropModeReplace, (unsigned char *) &data, -- cgit v1.2.3