Patch for use of uninitialized memory in GetPathAttributes

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
Danack
Posts: 73
Joined: 2013-10-14T10:00:25-07:00
Authentication code: 6789

Patch for use of uninitialized memory in GetPathAttributes

Post by Danack »

It seems on Centos 6.4 the `stat` system call does not set every element in the `stat` structure. This leads to use of unitialized memory warnings.

This can be fixed by setting the memory to 0 inside GetPathAttributes.

in utility.h line 48:

-GetPathAttributes(const char *,void *),
+GetPathAttributes(const char *,struct stat * )

In utility.c line 1152:

MagickExport MagickBooleanType GetPathAttributes(const char *path,
- void *attributes)
+ struct stat *attributes)
{
MagickBooleanType
status;
+ memset(attributes, 0, sizeof(stat));

btw I'm really not sure why GetPathAttributes took a void* before, it only seems to take a stat structure.

cheers
Dan


Valgrind report
------------------
==32386== Conditional jump or move depends on uninitialised value(s)
==32386== at 0x91FAF70: __printf_fp (in /lib64/libc-2.12.so)
==32386== by 0x91F6B1F: vfprintf (in /lib64/libc-2.12.so)
==32386== by 0x92209D1: vsnprintf (in /lib64/libc-2.12.so)
==32386== by 0x12D82649: FormatLocaleStringList (locale.c:461)
==32386== by 0x12D82742: FormatLocaleString (locale.c:486)
==32386== by 0x12DE11AE: ThumbnailImage (resize.c:3801)
==32386== by 0x129B60E2: MagickThumbnailImage (magick-image.c:12370)



Test program

Code: Select all


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wand/MagickWand.h>


PixelWand *makePixelWand(char *string) {
	PixelWand *pixel_wand;
	pixel_wand = NewPixelWand();

	if (PixelSetColor (pixel_wand, string) == MagickFalse) {
		printf("Failed to set color");
		exit(-1);
	}

	return pixel_wand;
}
  
int main(int argc,char **argv) { 
  
    MagickWand *magick_wand;
    char *filename = "./output/memTest.png";
    PixelWand *stroke_color_wand;
    MagickWandGenesis();
    stroke_color_wand = makePixelWand("red");
    magick_wand = NewMagickWand();
    
    MagickNewImage(magick_wand, 400, 200, stroke_color_wand);
    MagickSetImageFormat(magick_wand, "png");
    MagickThumbnailImage(magick_wand, 50, 25);
    MagickWriteImages(magick_wand, filename, MagickTrue);

    MagickWandTerminus();
    return (0);
}

User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Patch for use of uninitialized memory in GetPathAttributes

Post by magick »

Thanks for the problem report and patch. We applied your patch to the ImageMagick Subversion trunk.
Post Reply