Patch for use of uninitialized memory in GetPathAttributes
Posted: 2015-02-09T09:46:08-07:00
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
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);
}