CVE-2016-10060 (published 2017-03-02T21:59Z)

The ConcatenateImages function in MagickWand/magick-cli.c in ImageMagick before 7.0.1-10 does not check the return value of the fputc function, which allows remote attackers to cause a denial of service (application crash) via a crafted file.

Severity: MEDIUM
CVSS v2 base score: 4.3 (AV:N/AC:M/Au:N/C:N/I:N/A:P)
CVSS v3 base score: 6.5, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H)

Weakness information:
cwe_id: CWE-252
cwe_name: Unchecked Return Value
description: The product does not check the return value from a method or function, which can prevent it from detecting unexpected states and conditions.
extended_description: Two common programmer assumptions are "this function call can never fail" and "it doesn't matter if this function call fails". If an attacker can force the function to fail or otherwise return a value that is not expected, then the subsequent program logic could lead to a vulnerability, because the product is not in a state that the programmer assumes. For example, if the program calls a function to drop privileges but does not check the return code to ensure that privileges were successfully dropped, then the program will continue to operate with the higher privileges.
         

Fix information:
repo_url: https://github.com/ImageMagick/ImageMagick
commit_details: repo_url: https://github.com/ImageMagick/ImageMagick
author: Cristy
author_date: 2016-06-03 20:10:45-04:00
msg: https://github.com/ImageMagick/ImageMagick/issues/196
repository: repo_url: https://github.com/ImageMagick/ImageMagick
repo_name: ImageMagick/ImageMagick
description: 🧙‍♂️ ImageMagick 7
repo_language: C
owner: ImageMagick
file_changes: filename: magick-cli.c
change_type: ModificationType.MODIFY
diff: @@ -636,12 +636,15 @@ static void MagickUsage(MagickBooleanType verbose)
    however the last argument provides the output filename.
 */
 static MagickBooleanType ConcatenateImages(int argc,char **argv,
-     ExceptionInfo *exception )
+  ExceptionInfo *exception )
 {
   FILE
     *input,
     *output;
 
+  MagickBooleanType
+    status;
+
   int
     c;
 
@@ -650,29 +653,31 @@ static MagickBooleanType ConcatenateImages(int argc,char **argv,
 
   if (ExpandFilenames(&argc,&argv) == MagickFalse)
     ThrowFileException(exception,ResourceLimitError,"MemoryAllocationFailed",
-         GetExceptionMessage(errno));
-
+      GetExceptionMessage(errno));
   output=fopen_utf8(argv[argc-1],"wb");
-  if (output == (FILE *) NULL) {
-    ThrowFileException(exception,FileOpenError,"UnableToOpenFile",argv[argc-1]);
-    return(MagickFalse);
-  }
-  for (i=2; i < (ssize_t) (argc-1); i++) {
-#if 0
-    fprintf(stderr, "DEBUG: Concatenate Image: \"%s\"\n", argv[i]);
-#endif
+  if (output == (FILE *) NULL)
+    {
+      ThrowFileException(exception,FileOpenError,"UnableToOpenFile",
+        argv[argc-1]);
+      return(MagickFalse);
+    }
+  status=MagickTrue;
+  for (i=2; i < (ssize_t) (argc-1); i++)
+  {
     input=fopen_utf8(argv[i],"rb");
-    if (input == (FILE *) NULL) {
+    if (input == (FILE *) NULL)
+      {
         ThrowFileException(exception,FileOpenError,"UnableToOpenFile",argv[i]);
         continue;
       }
     for (c=fgetc(input); c != EOF; c=fgetc(input))
-      (void) fputc((char) c,output);
+      if (fputc((char) c,output) != c)
+        status=MagickFalse;
     (void) fclose(input);
     (void) remove_utf8(argv[i]);
   }
   (void) fclose(output);
-  return(MagickTrue);
+  return(status);
 }
 
 WandExport MagickBooleanType MagickImageCommand(ImageInfo *image_info,int argc,

programming_language: Objective-C