diff options
author | Jim Rees <rees@umich.edu> | 2020-06-22 19:19:30 -0500 |
---|---|---|
committer | Jim Rees <rees@umich.edu> | 2020-06-22 19:21:41 -0500 |
commit | ae07bdd696b8e6ba8af4dbeb96c96e378166eede (patch) | |
tree | eedc93a937493df23797a3c3bc61d6b32147099b | |
parent | aeabe09fdf0750933fdbd970780bd50c8dfda5fd (diff) |
Zero out uninitialized memory so as not to write stack garbage to dump file
Also check return from XFetchName()
Signed-off-by: Jim Rees <rees@umich.edu>
-rw-r--r-- | multiVis.c | 14 | ||||
-rw-r--r-- | xwd.c | 5 |
2 files changed, 11 insertions, 8 deletions
@@ -34,11 +34,12 @@ from The Open Group. ------------------------------------------------------------------------ **/ +#include <stdio.h> #include <stdlib.h> +#include <string.h> #include <X11/Xlib.h> #include <X11/Xutil.h> #include <X11/X.h> -#include <stdio.h> #include "list.h" #include "wsutils.h" #include "multiVis.h" @@ -354,7 +355,7 @@ ReadRegionsInList(Display *disp, Visual *fakeVis, int depth, int format, { image_region_type *reg; int dst_x, dst_y; /* where in pixmap to write (UL) */ - int diff; + int datalen, diff; XImage *reg_image, *ximage; int srcRect_x, srcRect_y, srcRect_width, srcRect_height; @@ -364,10 +365,11 @@ ReadRegionsInList(Display *disp, Visual *fakeVis, int depth, int format, 8, 0); bytes_per_line = ximage->bytes_per_line; - if (format == ZPixmap) - ximage->data = malloc(height * bytes_per_line); - else - ximage->data = malloc(height * bytes_per_line * depth); + datalen = height * bytes_per_line; + if (format != ZPixmap) + datalen *= depth; + ximage->data = malloc(datalen); + memset(ximage->data, 0, datalen); ximage->bits_per_pixel = depth; /** Valid only if format is ZPixmap ***/ @@ -241,6 +241,7 @@ Get24bitDirectColors(XColor **colors) for (i = 0; i < ncolors; i++) { tcol[i].pixel = i << 16 | i << 8 | i; tcol[i].red = tcol[i].green = tcol[i].blue = i << 8 | i; + tcol[i].flags = 0; } return ncolors; @@ -336,8 +337,7 @@ Window_Dump(Window window, FILE *out) if (absy + height > dheight) height = dheight - absy; - XFetchName(dpy, window, &win_name); - if (!win_name || !win_name[0]) { + if (!XFetchName(dpy, window, &win_name) || !win_name || !win_name[0]) { win_name = default_win_name; got_win_name = False; } @@ -430,6 +430,7 @@ Window_Dump(Window window, FILE *out) */ if (debug) outl("xwd: Constructing and dumping file header.\n"); + memset(&header, 0, SIZEOF(XWDheader)); header.header_size = (CARD32) header_size; header.file_version = (CARD32) XWD_FILE_VERSION; header.pixmap_format = (CARD32) format; |