Commit e3e69118c for imagemagick.org
commit e3e69118c29064e2716ca89aab635ea95a15dd49
Author: Cristy <urban-warrior@imagemagick.org>
Date: Fri Jul 3 07:40:58 2026 -0400
https://github.com/ImageMagick/ImageMagick/security/advisories/GHSA-cvhv-g4rq-3hmw
diff --git a/MagickCore/property.c b/MagickCore/property.c
index b3752d012..ff68acf13 100644
--- a/MagickCore/property.c
+++ b/MagickCore/property.c
@@ -3712,11 +3712,8 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info,Image *image,
MagickPathExtent,sizeof(*interpret_text)); \
if (interpret_text == (char *) NULL) \
{ \
- if (property_image != image) \
- property_image=DestroyImage(property_image); \
- if (property_info != image_info) \
- property_info=DestroyImageInfo(property_info); \
- return((char *) NULL); \
+ status=MagickFalse; \
+ goto cleanup; \
} \
q=interpret_text+strlen(interpret_text); \
} \
@@ -3732,11 +3729,8 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info,Image *image,
MagickPathExtent,sizeof(*interpret_text)); \
if (interpret_text == (char *) NULL) \
{ \
- if (property_image != image) \
- property_image=DestroyImage(property_image); \
- if (property_info != image_info) \
- property_info=DestroyImageInfo(property_info); \
- return((char *) NULL); \
+ status=MagickFalse; \
+ goto cleanup; \
} \
q=interpret_text+strlen(interpret_text); \
} \
@@ -3753,11 +3747,8 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info,Image *image,
MagickPathExtent,sizeof(*interpret_text)); \
if (interpret_text == (char *) NULL) \
{ \
- if (property_image != image) \
- property_image=DestroyImage(property_image); \
- if (property_info != image_info) \
- property_info=DestroyImageInfo(property_info); \
- return((char *) NULL); \
+ status=MagickFalse; \
+ goto cleanup; \
} \
q=interpret_text+strlen(interpret_text); \
} \
@@ -3766,20 +3757,21 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info,Image *image,
}
char
- *interpret_text,
+ *interpret_text = (char *) NULL,
*q; /* current position in interpret_text */
const char
*p; /* position in embed_text string being expanded */
Image
- *property_image;
+ *property_image = (Image *) NULL;
ImageInfo
- *property_info;
+ *property_info = (ImageInfo *) NULL;
MagickBooleanType
- number;
+ number,
+ status = MagickTrue;
size_t
extent; /* allocated length of interpret_text */
@@ -3821,10 +3813,20 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info,Image *image,
else
{
property_image=AcquireImage(image_info,exception);
+ if (property_image == (Image *) NULL)
+ {
+ status=MagickFalse;
+ goto cleanup;
+ }
(void) SetImageExtent(property_image,1,1,exception);
(void) SetImageBackgroundColor(property_image,exception);
}
interpret_text=AcquireString(embed_text); /* new string with extra space */
+ if (interpret_text == (char *) NULL)
+ {
+ status=MagickFalse;
+ goto cleanup;
+ }
extent=MagickPathExtent; /* allocated space in string */
number=MagickFalse; /* is last char a number? */
for (q=interpret_text; *p!='\0'; number=isdigit((int) ((unsigned char) *p)) ? MagickTrue : MagickFalse,p++)
@@ -3954,10 +3956,8 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info,Image *image,
*string;
ssize_t
- len;
-
- ssize_t
- depth;
+ depth,
+ offset;
/*
Braced Percent Escape %[...].
@@ -3968,17 +3968,18 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info,Image *image,
{
(void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
"UnknownImageProperty","\"%%[]\"");
- break;
+ status=MagickFalse;
+ goto cleanup;
}
- for (len=0; len < (MagickPathExtent-1L) && (*p != '\0'); )
+ for (offset=0; offset < (MagickPathExtent-1L) && (*p != '\0'); )
{
if ((*p == '\\') && (*(p+1) != '\0'))
{
/*
Skip escaped braces within braced pattern.
*/
- pattern[len++]=(*p++);
- pattern[len++]=(*p++);
+ pattern[offset++]=(*p++);
+ pattern[offset++]=(*p++);
continue;
}
if (*p == '[')
@@ -3987,29 +3988,25 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info,Image *image,
depth--;
if (depth <= 0)
break;
- pattern[len++]=(*p++);
+ pattern[offset++]=(*p++);
}
- pattern[len]='\0';
+ pattern[offset]='\0';
if (depth != 0)
{
/*
Check for unmatched final ']' for "%[...]".
*/
- if (len >= 64)
+ if (offset >= 64)
{
- pattern[61] = '.'; /* truncate string for error message */
- pattern[62] = '.';
- pattern[63] = '.';
- pattern[64] = '\0';
+ pattern[61]='.'; /* truncate string for error message */
+ pattern[62]='.';
+ pattern[63]='.';
+ pattern[64]='\0';
}
(void) ThrowMagickException(exception,GetMagickModule(),OptionError,
"UnbalancedBraces","\"%%[%s\"",pattern);
- interpret_text=DestroyString(interpret_text);
- if (property_image != image)
- property_image=DestroyImage(property_image);
- if (property_info != image_info)
- property_info=DestroyImageInfo(property_info);
- return((char *) NULL);
+ status=MagickFalse;
+ goto cleanup;
}
/*
Special Lookup Prefixes %[prefix:...].
@@ -4023,7 +4020,7 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info,Image *image,
*fx_info;
MagickBooleanType
- status;
+ fx_status;
/*
FX - value calculator.
@@ -4031,10 +4028,10 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info,Image *image,
fx_info=AcquireFxInfo(property_image,pattern+3,exception);
if (fx_info == (FxInfo *) NULL)
continue;
- status=FxEvaluateChannelExpression(fx_info,CompositePixelChannel,0,0,
- &value,exception);
+ fx_status=FxEvaluateChannelExpression(fx_info,CompositePixelChannel,
+ 0,0,&value,exception);
fx_info=DestroyFxInfo(fx_info);
- if (status != MagickFalse)
+ if (fx_status != MagickFalse)
{
char
result[MagickPathExtent];
@@ -4054,7 +4051,7 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info,Image *image,
*fx_info;
MagickStatusType
- status;
+ fx_status;
PixelInfo
pixel;
@@ -4066,26 +4063,26 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info,Image *image,
fx_info=AcquireFxInfo(property_image,pattern+4,exception);
if (fx_info == (FxInfo *) NULL)
continue;
- status=FxEvaluateChannelExpression(fx_info,RedPixelChannel,0,0,
+ fx_status=FxEvaluateChannelExpression(fx_info,RedPixelChannel,0,0,
&value,exception);
pixel.red=(double) QuantumRange*value;
- status&=(MagickStatusType) FxEvaluateChannelExpression(fx_info,
+ fx_status&=(MagickStatusType) FxEvaluateChannelExpression(fx_info,
GreenPixelChannel,0,0,&value,exception);
pixel.green=(double) QuantumRange*value;
- status&=(MagickStatusType) FxEvaluateChannelExpression(fx_info,
+ fx_status&=(MagickStatusType) FxEvaluateChannelExpression(fx_info,
BluePixelChannel,0,0,&value,exception);
pixel.blue=(double) QuantumRange*value;
if (property_image->colorspace == CMYKColorspace)
{
- status&=(MagickStatusType) FxEvaluateChannelExpression(fx_info,
+ fx_status&=(MagickStatusType) FxEvaluateChannelExpression(fx_info,
BlackPixelChannel,0,0,&value,exception);
pixel.black=(double) QuantumRange*value;
}
- status&=(MagickStatusType) FxEvaluateChannelExpression(fx_info,
+ fx_status&=(MagickStatusType) FxEvaluateChannelExpression(fx_info,
AlphaPixelChannel,0,0,&value,exception);
pixel.alpha=(double) QuantumRange*value;
fx_info=DestroyFxInfo(fx_info);
- if (status != MagickFalse)
+ if (fx_status != MagickFalse)
{
char
hex[MagickPathExtent];
@@ -4104,7 +4101,7 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info,Image *image,
*fx_info;
MagickStatusType
- status;
+ fx_status;
PixelInfo
pixel;
@@ -4116,26 +4113,26 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info,Image *image,
fx_info=AcquireFxInfo(property_image,pattern+6,exception);
if (fx_info == (FxInfo *) NULL)
continue;
- status=FxEvaluateChannelExpression(fx_info,RedPixelChannel,0,0,
+ fx_status=FxEvaluateChannelExpression(fx_info,RedPixelChannel,0,0,
&value,exception);
pixel.red=(double) QuantumRange*value;
- status&=(MagickStatusType) FxEvaluateChannelExpression(fx_info,
+ fx_status&=(MagickStatusType) FxEvaluateChannelExpression(fx_info,
GreenPixelChannel,0,0,&value,exception);
pixel.green=(double) QuantumRange*value;
- status&=(MagickStatusType) FxEvaluateChannelExpression(fx_info,
+ fx_status&=(MagickStatusType) FxEvaluateChannelExpression(fx_info,
BluePixelChannel,0,0,&value,exception);
pixel.blue=(double) QuantumRange*value;
if (property_image->colorspace == CMYKColorspace)
{
- status&=(MagickStatusType) FxEvaluateChannelExpression(fx_info,
+ fx_status&=(MagickStatusType) FxEvaluateChannelExpression(fx_info,
BlackPixelChannel,0,0,&value,exception);
pixel.black=(double) QuantumRange*value;
}
- status&=(MagickStatusType) FxEvaluateChannelExpression(fx_info,
+ fx_status&=(MagickStatusType) FxEvaluateChannelExpression(fx_info,
AlphaPixelChannel,0,0,&value,exception);
pixel.alpha=(double) QuantumRange*value;
fx_info=DestroyFxInfo(fx_info);
- if (status != MagickFalse)
+ if (fx_status != MagickFalse)
{
char
name[MagickPathExtent];
@@ -4167,13 +4164,12 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info,Image *image,
string=GetImageOption(property_info,key);
if (string != (const char *) NULL)
AppendKeyValue2Text(key,string);
- /* else - assertion failure? key found but no string value! */
}
continue;
}
string=GetImageOption(property_info,pattern+7);
if (string == (char *) NULL)
- goto PropertyLookupFailure; /* no artifact of this specific name */
+ goto PropertyLookupFailure;
AppendString2Text(string);
continue;
}
@@ -4186,18 +4182,17 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info,Image *image,
{
ResetImageArtifactIterator(property_image);
while ((key=GetNextImageArtifact(property_image)) != (const char *) NULL)
- if (GlobExpression(key,pattern+9,MagickTrue) != MagickFalse)
- {
- string=GetImageArtifact(property_image,key);
- if (string != (const char *) NULL)
- AppendKeyValue2Text(key,string);
- /* else - assertion failure? key found but no string value! */
- }
+ if (GlobExpression(key,pattern+9,MagickTrue) != MagickFalse)
+ {
+ string=GetImageArtifact(property_image,key);
+ if (string != (const char *) NULL)
+ AppendKeyValue2Text(key,string);
+ }
continue;
}
string=GetImageArtifact(property_image,pattern+9);
if (string == (char *) NULL)
- goto PropertyLookupFailure; /* no artifact of this specific name */
+ goto PropertyLookupFailure;
AppendString2Text(string);
continue;
}
@@ -4215,20 +4210,17 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info,Image *image,
string=GetImageProperty(property_image,key,exception);
if (string != (const char *) NULL)
AppendKeyValue2Text(key,string);
- /* else - assertion failure? */
}
continue;
}
string=GetImageProperty(property_image,pattern+9,exception);
if (string == (char *) NULL)
- goto PropertyLookupFailure; /* no artifact of this specific name */
+ goto PropertyLookupFailure;
AppendString2Text(string);
continue;
}
/*
- Properties without special prefix. This handles attributes,
- properties, and profiles such as %[exif:...]. Note the profile
- properties may also include a glob expansion pattern.
+ Properties without special prefix.
*/
string=GetImageProperty(property_image,pattern,exception);
if (string != (const char *) NULL)
@@ -4240,10 +4232,6 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info,Image *image,
}
if (IsGlob(pattern) != MagickFalse)
{
- /*
- Handle property 'glob' patterns such as:
- %[*] %[user:array_??] %[filename:e*]>
- */
ResetImagePropertyIterator(property_image);
while ((key=GetNextImageProperty(property_image)) != (const char *) NULL)
if (GlobExpression(key,pattern,MagickTrue) != MagickFalse)
@@ -4251,14 +4239,11 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info,Image *image,
string=GetImageProperty(property_image,key,exception);
if (string != (const char *) NULL)
AppendKeyValue2Text(key,string);
- /* else - assertion failure? */
}
continue;
}
/*
- Look for a known property or image attribute such as
- %[basename] %[density] %[delay]. Also handles a braced single
- letter: %[b] %[G] %[g].
+ Known property or attribute.
*/
string=GetMagickProperty(property_info,property_image,pattern,exception);
if (string != (const char *) NULL)
@@ -4267,8 +4252,7 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info,Image *image,
continue;
}
/*
- Look for a per-image artifact. This includes option lookup
- (FUTURE: interpreted according to image).
+ Per-image artifact.
*/
string=GetImageArtifact(property_image,pattern);
if (string != (char *) NULL)
@@ -4277,7 +4261,7 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info,Image *image,
continue;
}
/*
- No image, so direct 'option' lookup (no delayed percent escapes).
+ Direct option lookup.
*/
string=GetImageOption(property_info,pattern);
if (string != (char *) NULL)
@@ -4285,26 +4269,32 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info,Image *image,
AppendString2Text(string);
continue;
}
+
PropertyLookupFailure:
- /*
- Failed to find any match anywhere!
- */
- if (len >= 64)
+ if (offset >= 64)
{
- pattern[61] = '.'; /* truncate string for error message */
- pattern[62] = '.';
- pattern[63] = '.';
- pattern[64] = '\0';
+ pattern[61]='.'; /* truncate string for error message */
+ pattern[62]='.';
+ pattern[63]='.';
+ pattern[64]='\0';
}
(void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
"UnknownImageProperty","\"%%[%s]\"",pattern);
}
}
*q='\0';
- if (property_image != image)
+
+cleanup:
+ if ((property_image != image) && (property_image != (Image *) NULL))
property_image=DestroyImage(property_image);
- if (property_info != image_info)
+ if ((property_info != image_info) && (property_info != (ImageInfo *) NULL))
property_info=DestroyImageInfo(property_info);
+ if (status == MagickFalse)
+ {
+ if (interpret_text != (char *) NULL)
+ interpret_text=DestroyString(interpret_text);
+ return((char *) NULL);
+ }
return(interpret_text);
}
diff --git a/MagickWand/magick-cli.c b/MagickWand/magick-cli.c
index 7e1cce906..349ade10f 100644
--- a/MagickWand/magick-cli.c
+++ b/MagickWand/magick-cli.c
@@ -1310,7 +1310,6 @@ WandExport MagickBooleanType MagickImageCommand(ImageInfo *image_info,int argc,
(void) CLILogEvent(cli_wand,CommandEvent,GetMagickModule(),
"\"%s\"",argv[0]);
-
GetPathComponent(argv[0],TailPath,cli_wand->wand.name);
(void) SetClientName(cli_wand->wand.name);
(void) ConcatenateMagickString(cli_wand->wand.name,"-CLI",MagickPathExtent);
@@ -1420,7 +1419,7 @@ Magick_Command_Exit:
{
CLIStack
*node;
-
+
/*
Pop image_info settings from stack.
*/
@@ -1439,7 +1438,7 @@ Magick_Command_Exit:
char
*text;
-
+
format="%w,%h,%m"; /* Get this from image_info Option splaytree */
text=InterpretImageProperties(image_info,cli_wand->wand.images,format,
exception);
@@ -1463,6 +1462,16 @@ Magick_Command_Exit:
(void) CLILogEvent(cli_wand,CommandEvent,GetMagickModule(),
"\"%s\"",argv[0]);
+ /* FIX: free ImageInfo cloned inside DrawInfo by AcquireMagickCLI/GetDrawInfo */
+ if (cli_wand->draw_info != (DrawInfo *) NULL &&
+ cli_wand->draw_info->image_info != (ImageInfo *) NULL)
+ cli_wand->draw_info->image_info =
+ DestroyImageInfo(cli_wand->draw_info->image_info);
+
+ /* optional: now free the DrawInfo itself */
+ if (cli_wand->draw_info != (DrawInfo *) NULL)
+ cli_wand->draw_info = DestroyDrawInfo(cli_wand->draw_info);
+
/* Destroy the special CLI Wand */
cli_wand->wand.image_info = (ImageInfo *) NULL; /* not these */
cli_wand->wand.exception = (ExceptionInfo *) NULL;
diff --git a/MagickWand/operation.c b/MagickWand/operation.c
index 1ba586b6e..22892bcd1 100644
--- a/MagickWand/operation.c
+++ b/MagickWand/operation.c
@@ -4847,12 +4847,12 @@ static MagickBooleanType CLIListOperatorImages(MagickCLI *cli_wand,
% Currently arg2 is not used.
%
*/
-static void CLINoImageOperator(MagickCLI *cli_wand,
- const char *option,const char *arg1n,const char *arg2n)
+static void CLINoImageOperator(MagickCLI *cli_wand,const char *option,
+ const char *arg1n,const char *arg2n)
{
const char /* percent escaped versions of the args */
- *arg1,
- *arg2;
+ *arg1 = arg1n,
+ *arg2 = arg2n;
#define _image_info (cli_wand->wand.image_info)
#define _images (cli_wand->wand.images)
@@ -4872,9 +4872,6 @@ static void CLINoImageOperator(MagickCLI *cli_wand,
arg1n != (char *) NULL ? arg1n : "",
arg2n != (char *) NULL ? arg2n : "");
- arg1 = arg1n;
- arg2 = arg2n;
-
/* Interpret Percent Escapes in Arguments - using first image */
if ( (((_process_flags & ProcessInterpretProperties) != 0 )
|| ((_option_type & AlwaysInterpretArgsFlag) != 0)
@@ -4917,23 +4914,6 @@ static void CLINoImageOperator(MagickCLI *cli_wand,
*/
if ( ( LocaleCompare("read",option+1) == 0 ) ||
( LocaleCompare("--",option) == 0 ) ) {
- /* Do Glob filename Expansion for 'arg1' then read all images.
- *
- * Expansion handles '@', '~', '*', and '?' meta-characters while ignoring
- * (but attaching to the filenames in the generated argument list) any
- * [...] read modifiers that may be present.
- *
- * For example: It will expand '*.gif[20x20]' into a list such as
- * 'abc.gif[20x20]', 'foobar.gif[20x20]', 'xyzzy.gif[20x20]'
- *
- * NOTE: In IMv6 this was done globally across all images. This
- * meant you could include IM options in '@filename' lists, but you
- * could not include comments. Doing it only for image read makes
- * it far more secure.
- *
- * Note: arguments do not have percent escapes expanded for security
- * reasons.
- */
int argc;
char **argv;
ssize_t i;
@@ -4941,18 +4921,12 @@ static void CLINoImageOperator(MagickCLI *cli_wand,
argc = 1;
argv = (char **) &arg1;
- /* Expand 'glob' expressions in the given filename.
- Expansion handles any 'coder:' prefix, or read modifiers attached
- to the filename, including them in the resulting expanded list.
- */
if (ExpandFilenames(&argc,&argv) == MagickFalse)
CLIWandExceptArgBreak(ResourceLimitError,"MemoryAllocationFailed",
option,(char *) NULL);
- /* loop over expanded filename list, and read then all in */
for (i=0; i < (ssize_t) argc; i++) {
- Image *
- new_images;
+ Image *new_images;
if (_image_info->ping != MagickFalse)
new_images=PingImages(_image_info,argv[i],_exception);
else
@@ -4968,17 +4942,10 @@ static void CLINoImageOperator(MagickCLI *cli_wand,
Note: Writing a empty image list is valid in specific cases
*/
if (LocaleCompare("write",option+1) == 0) {
- /* Note: arguments do not have percent escapes expanded */
- char
- key[MagickPathExtent];
-
- Image
- *write_images;
+ char key[MagickPathExtent];
+ Image *write_images;
+ ImageInfo *write_info;
- ImageInfo
- *write_info;
-
- /* Need images, unless a "null:" output coder is used */
if ( _images == (Image *) NULL ) {
if ( LocaleCompare(arg1,"null:") == 0 )
break;
@@ -4999,12 +4966,8 @@ static void CLINoImageOperator(MagickCLI *cli_wand,
Parenthesis and Brace operations
*/
if (LocaleCompare("(",option) == 0) {
- /* stack 'push' images */
- CLIStack
- *node;
-
- size_t
- size;
+ CLIStack *node;
+ size_t size;
size=0;
node=cli_wand->image_list_stack;
@@ -5021,7 +4984,6 @@ static void CLINoImageOperator(MagickCLI *cli_wand,
cli_wand->image_list_stack = node;
cli_wand->wand.images = NewImageList();
- /* handle respect-parentheses */
if (IsStringTrue(GetImageOption(cli_wand->wand.image_info,
"respect-parentheses")) != MagickFalse)
option="{"; /* fall-thru so as to push image settings too */
@@ -5030,12 +4992,8 @@ static void CLINoImageOperator(MagickCLI *cli_wand,
/* fall thru to operation */
}
if (LocaleCompare("{",option) == 0) {
- /* stack 'push' of image_info settings */
- CLIStack
- *node;
-
- size_t
- size;
+ CLIStack *node;
+ size_t size;
size=0;
node=cli_wand->image_info_stack;
@@ -5064,9 +5022,7 @@ static void CLINoImageOperator(MagickCLI *cli_wand,
break;
}
if (LocaleCompare(")",option) == 0) {
- /* pop images from stack */
- CLIStack
- *node;
+ CLIStack *node;
node = (CLIStack *)cli_wand->image_list_stack;
if ( node == (CLIStack *) NULL)
@@ -5077,12 +5033,10 @@ static void CLINoImageOperator(MagickCLI *cli_wand,
cli_wand->wand.images= (Image *)node->data;
node = (CLIStack *)RelinquishMagickMemory(node);
- /* handle respect-parentheses - of the previous 'pushed' settings */
node = cli_wand->image_info_stack;
if ( node != (CLIStack *) NULL)
{
- if (IsStringTrue(GetImageOption(
- cli_wand->wand.image_info,"respect-parentheses")) != MagickFalse)
+ if (IsStringTrue(GetImageOption(cli_wand->wand.image_info,"respect-parentheses")) != MagickFalse)
option="}"; /* fall-thru so as to pop image settings too */
else
break;
@@ -5092,9 +5046,7 @@ static void CLINoImageOperator(MagickCLI *cli_wand,
/* fall thru to next if */
}
if (LocaleCompare("}",option) == 0) {
- /* pop image_info settings from stack */
- CLIStack
- *node;
+ CLIStack *node;
node = (CLIStack *)cli_wand->image_info_stack;
if ( node == (CLIStack *) NULL)
@@ -5111,11 +5063,11 @@ static void CLINoImageOperator(MagickCLI *cli_wand,
break;
}
- if (LocaleCompare("print",option+1) == 0)
- {
- (void) FormatLocaleFile(stdout,"%s",arg1);
- break;
- }
+ if (LocaleCompare("print",option+1) == 0)
+ {
+ (void) FormatLocaleFile(stdout,"%s",arg1);
+ break;
+ }
if (LocaleCompare("set",option+1) == 0)
{
/* Settings are applied to each image in memory in turn (if any).
@@ -5124,12 +5076,17 @@ static void CLINoImageOperator(MagickCLI *cli_wand,
NOTE: Arguments have not been automatically percent expanded
*/
- /* escape the 'key' once only, using first image. */
StringInfo *profile = (StringInfo *) NULL;
+
+ /* FIX: avoid leaking previously interpreted arg1 from header */
+ if (arg1 != arg1n)
+ arg1 = DestroyString((char *) arg1);
+
+ /* escape the 'key' once only, using first image. */
arg1=InterpretImageProperties(_image_info,_images,arg1n,_exception);
if (arg1 == (char *) NULL)
CLIWandExceptionBreak(OptionWarning,"InterpretPropertyFailure",
- option);
+ option);
if (LocaleNCompare(arg1,"registry:",9) == 0)
{
@@ -5139,6 +5096,11 @@ static void CLINoImageOperator(MagickCLI *cli_wand,
arg1=DestroyString((char *)arg1);
break;
}
+
+ /* FIX: avoid leaking previously interpreted arg2 from header */
+ if (arg2 != arg2n)
+ arg2 = DestroyString((char *) arg2);
+
arg2=InterpretImageProperties(_image_info,_images,arg2n,_exception);
if (arg2 == (char *) NULL) {
arg1=DestroyString((char *)arg1);
@@ -5165,7 +5127,12 @@ static void CLINoImageOperator(MagickCLI *cli_wand,
arg2=(char *) NULL;
if (IfNormalOp)
{
- arg2=InterpretImageProperties(_image_info,_images,arg2n,_exception);
+ /* FIX: avoid leaking previously interpreted arg2 from header */
+ if (arg2 != arg2n)
+ arg2 = DestroyString((char *) arg2);
+
+ arg2=InterpretImageProperties(_image_info,_images,arg2n,
+ _exception);
if (arg2 == (char *) NULL)
CLIWandExceptionBreak(OptionWarning,
"InterpretPropertyFailure",option);
@@ -5194,7 +5161,12 @@ static void CLINoImageOperator(MagickCLI *cli_wand,
arg2=(char *) NULL;
if (IfNormalOp)
{
- arg2=InterpretImageProperties(_image_info,_images,arg2n,_exception);
+ /* FIX: avoid leaking previously interpreted arg2 from header */
+ if (arg2 != arg2n)
+ arg2 = DestroyString((char *) arg2);
+
+ arg2=InterpretImageProperties(_image_info,_images,arg2n,
+ _exception);
if (arg2 == (char *) NULL)
CLIWandExceptionBreak(OptionWarning,
"InterpretPropertyFailure",option);
@@ -5206,21 +5178,25 @@ static void CLINoImageOperator(MagickCLI *cli_wand,
else
(void) SetImageProperty(_images,arg1,arg2,_exception);
if (profile != (StringInfo *) NULL)
- (void) SetImageProfile(_images,_image_info->magick,profile,_exception);
+ (void) SetImageProfile(_images,_image_info->magick,profile,
+ _exception);
arg2=DestroyString((char *)arg2);
}
if (profile != (StringInfo *) NULL)
- profile=DestroyStringInfo(profile);
+ profile=DestroyStringInfo(profile);
MagickResetIterator(&cli_wand->wand);
arg1=DestroyString((char *)arg1);
break;
}
if (LocaleCompare("clone",option+1) == 0) {
- Image
- *new_images;
+ Image *new_images;
- if (*option == '+')
+ if (*option == '+') {
+ /* FIX: avoid leaking previously interpreted arg1 from header */
+ if (arg1 != arg1n)
+ arg1 = DestroyString((char *)arg1);
arg1=AcquireString("-1");
+ }
if (IsSceneGeometry(arg1,MagickFalse) == MagickFalse)
CLIWandExceptionBreak(OptionError,"InvalidArgument",option);
new_images=cli_wand->wand.images;
@@ -5247,8 +5223,7 @@ static void CLINoImageOperator(MagickCLI *cli_wand,
}
if (LocaleCompare("list",option+1) == 0)
{
- ssize_t
- list;
+ ssize_t list;
/*
FUTURE: This 'switch' should really be part of MagickCore
diff --git a/MagickWand/wandcli.c b/MagickWand/wandcli.c
index 06f112d69..5c18afb0c 100644
--- a/MagickWand/wandcli.c
+++ b/MagickWand/wandcli.c
@@ -71,7 +71,7 @@
%
*/
WandExport MagickCLI *AcquireMagickCLI(ImageInfo *image_info,
- ExceptionInfo *exception)
+ ExceptionInfo *exception)
{
MagickCLI
*cli_wand;
@@ -80,7 +80,7 @@ WandExport MagickCLI *AcquireMagickCLI(ImageInfo *image_info,
cli_wand=(MagickCLI *) AcquireCriticalMemory(sizeof(*cli_wand));
cli_wand->wand.id=AcquireWandId();
(void) FormatLocaleString(cli_wand->wand.name,MagickPathExtent,
- "%s-%.20g","MagickWandCLI", (double) cli_wand->wand.id);
+ "%s-%.20g","MagickWandCLI", (double) cli_wand->wand.id);
cli_wand->wand.images=NewImageList();
if ( image_info == (ImageInfo *) NULL)
cli_wand->wand.image_info=AcquireImageInfo();
@@ -92,15 +92,17 @@ WandExport MagickCLI *AcquireMagickCLI(ImageInfo *image_info,
cli_wand->wand.exception=exception;
cli_wand->wand.debug=IsEventLogging();
cli_wand->wand.signature=MagickWandSignature;
-
/* Initialize CLI Part of MagickCLI */
- cli_wand->draw_info=CloneDrawInfo(cli_wand->wand.image_info,(DrawInfo *) NULL);
+ cli_wand->draw_info=CloneDrawInfo(cli_wand->wand.image_info,
+ (DrawInfo *) NULL);
+ if (cli_wand->draw_info->image_info != (ImageInfo *) NULL)
+ cli_wand->draw_info->image_info =
+ DestroyImageInfo(cli_wand->draw_info->image_info);
cli_wand->quantize_info=AcquireQuantizeInfo(cli_wand->wand.image_info);
cli_wand->process_flags=MagickCommandOptionFlags; /* assume "magick" CLI */
cli_wand->command=(const OptionInfo *) NULL; /* no option at this time */
cli_wand->image_list_stack=(CLIStack *) NULL;
cli_wand->image_info_stack=(CLIStack *) NULL;
-
/* default exception location...
EG: sprintf(location, filename, line, column);
*/
@@ -109,7 +111,6 @@ WandExport MagickCLI *AcquireMagickCLI(ImageInfo *image_info,
cli_wand->filename="unknown"; /* script filename, unknown source */
cli_wand->line=0; /* line from script OR CLI argument */
cli_wand->column=0; /* column from script */
-
cli_wand->signature=MagickWandSignature;
if (cli_wand->wand.debug != MagickFalse)
(void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",cli_wand->wand.name);