summaryrefslogtreecommitdiff
path: root/MagickCore/delegate.c
diff options
context:
space:
mode:
Diffstat (limited to 'MagickCore/delegate.c')
-rw-r--r--MagickCore/delegate.c153
1 files changed, 81 insertions, 72 deletions
diff --git a/MagickCore/delegate.c b/MagickCore/delegate.c
index c3fab73f6..bef9abcd3 100644
--- a/MagickCore/delegate.c
+++ b/MagickCore/delegate.c
@@ -393,52 +393,89 @@ MagickExport int ExternalDelegateCommand(const MagickBooleanType asynchronous,
if (message != (char *) NULL)
*message='\0';
#if defined(MAGICKCORE_POSIX_SUPPORT)
-#if !defined(MAGICKCORE_HAVE_EXECVP)
- status=system(sanitize_command);
-#else
- if ((asynchronous != MagickFalse) ||
- (strpbrk(sanitize_command,"&;<>|") != (char *) NULL))
- status=system(sanitize_command);
- else
+#if defined(MAGICKCORE_HAVE_POPEN)
+ if ((asynchronous == MagickFalse) && (message != (char *) NULL))
{
- pid_t
- child_pid;
+ char
+ buffer[MagickPathExtent];
- /*
- Call application directly rather than from a shell.
- */
- child_pid=(pid_t) fork();
- if (child_pid == (pid_t) -1)
+ FILE
+ *file;
+
+ size_t
+ offset;
+
+ offset=0;
+ file=popen_utf8(sanitize_command,"r");
+ if (file == (FILE *) NULL)
status=system(sanitize_command);
else
- if (child_pid == 0)
- {
- status=execvp(arguments[1],arguments+1);
- _exit(1);
- }
- else
+ {
+ while (fgets(buffer,(int) sizeof(buffer),file) != NULL)
{
- int
- child_status;
+ size_t
+ length;
- pid_t
- pid;
-
- child_status=0;
- pid=(pid_t) waitpid(child_pid,&child_status,0);
- if (pid == -1)
- status=(-1);
- else
+ length=MagickMin(MagickPathExtent-offset,strlen(buffer)+1);
+ if (length > 0)
{
- if (WIFEXITED(child_status) != 0)
- status=WEXITSTATUS(child_status);
- else
- if (WIFSIGNALED(child_status))
- status=(-1);
+ (void) CopyMagickString(message+offset,buffer,length);
+ offset+=length-1;
}
}
+ status=pclose(file);
+ }
}
+ else
#endif
+ {
+#if !defined(MAGICKCORE_HAVE_EXECVP)
+ status=system(sanitize_command);
+#else
+ if ((asynchronous != MagickFalse) ||
+ (strpbrk(sanitize_command,"&;<>|") != (char *) NULL))
+ status=system(sanitize_command);
+ else
+ {
+ pid_t
+ child_pid;
+
+ /*
+ Call application directly rather than from a shell.
+ */
+ child_pid=(pid_t) fork();
+ if (child_pid == (pid_t) -1)
+ status=system(sanitize_command);
+ else
+ if (child_pid == 0)
+ {
+ status=execvp(arguments[1],arguments+1);
+ _exit(1);
+ }
+ else
+ {
+ int
+ child_status;
+
+ pid_t
+ pid;
+
+ child_status=0;
+ pid=(pid_t) waitpid(child_pid,&child_status,0);
+ if (pid == -1)
+ status=(-1);
+ else
+ {
+ if (WIFEXITED(child_status) != 0)
+ status=WEXITSTATUS(child_status);
+ else
+ if (WIFSIGNALED(child_status))
+ status=(-1);
+ }
+ }
+ }
+#endif
+ }
#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
{
char
@@ -462,8 +499,6 @@ MagickExport int ExternalDelegateCommand(const MagickBooleanType asynchronous,
}
}
status=NTSystemCommand(sanitize_command,message);
-#elif defined(macintosh)
- status=MACSystemCommand(sanitize_command);
#elif defined(vms)
status=system(sanitize_command);
#else
@@ -523,36 +558,6 @@ MagickExport int ExternalDelegateCommand(const MagickBooleanType asynchronous,
%
*/
-static char *SanitizeDelegateString(const char *source)
-{
- char
- *sanitize_source;
-
- const char
- *q;
-
- char
- *p;
-
- static char
-#if defined(MAGICKCORE_WINDOWS_SUPPORT)
- allowlist[] =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 "
- "$-_.+!;*(),{}|^~[]`\'><#%/?:@&=";
-#else
- allowlist[] =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 "
- "$-_.+!;*(),{}|\\^~[]`\"><#%/?:@&=";
-#endif
-
- sanitize_source=AcquireString(source);
- p=sanitize_source;
- q=sanitize_source+strlen(sanitize_source);
- for (p+=strspn(p,allowlist); p != q; p+=strspn(p,allowlist))
- *p='_';
- return(sanitize_source);
-}
-
static char *GetMagickPropertyLetter(ImageInfo *image_info,Image *image,
const char letter,ExceptionInfo *exception)
{
@@ -724,14 +729,18 @@ static char *GetMagickPropertyLetter(ImageInfo *image_info,Image *image,
{
WarnNoImageReturn("\"%%%c\"",letter);
(void) FormatLocaleString(value,MagickPathExtent,"%.20g",
- fabs(image->resolution.x) > MagickEpsilon ? image->resolution.x : 72.0);
+ fabs(image->resolution.x) > MagickEpsilon ? image->resolution.x :
+ image->units == PixelsPerCentimeterResolution ? DefaultResolution/2.54 :
+ DefaultResolution);
break;
}
case 'y': /* Image vertical resolution (with units) */
{
WarnNoImageReturn("\"%%%c\"",letter);
(void) FormatLocaleString(value,MagickPathExtent,"%.20g",
- fabs(image->resolution.y) > MagickEpsilon ? image->resolution.y : 72.0);
+ fabs(image->resolution.y) > MagickEpsilon ? image->resolution.y :
+ image->units == PixelsPerCentimeterResolution ? DefaultResolution/2.54 :
+ DefaultResolution);
break;
}
case 'z': /* Image depth as read in */
@@ -910,7 +919,7 @@ static char *InterpretDelegateProperties(ImageInfo *image_info,
{ \
extent+=length; \
interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
- MaxTextExtent,sizeof(*interpret_text)); \
+ MagickPathExtent,sizeof(*interpret_text)); \
if (interpret_text == (char *) NULL) \
return((char *) NULL); \
q=interpret_text+strlen(interpret_text); \
@@ -924,7 +933,7 @@ static char *InterpretDelegateProperties(ImageInfo *image_info,
{ \
extent+=length; \
interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
- MaxTextExtent,sizeof(*interpret_text)); \
+ MagickPathExtent,sizeof(*interpret_text)); \
if (interpret_text == (char *) NULL) \
return((char *) NULL); \
q=interpret_text+strlen(interpret_text); \
@@ -939,7 +948,7 @@ static char *InterpretDelegateProperties(ImageInfo *image_info,
{ \
extent+=length; \
interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
- MaxTextExtent,sizeof(*interpret_text)); \
+ MagickPathExtent,sizeof(*interpret_text)); \
if (interpret_text == (char *) NULL) \
return((char *) NULL); \
q=interpret_text+strlen(interpret_text); \