]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
libcupsfilters: Double free in imagetoraster() filter function fixed
authorsuraj kulriya <45878143+surajkulriya@users.noreply.github.com>
Mon, 12 Jul 2021 09:36:50 +0000 (15:06 +0530)
committerGitHub <noreply@github.com>
Mon, 12 Jul 2021 09:36:50 +0000 (11:36 +0200)
cupsfilters/imagetoraster.c

index 531047573ac5b8e3d8651ad821b315eb3b1307b1..824e1f959001b07a3bb8fdba8767fe5f1ec8afa4 100644 (file)
@@ -211,8 +211,8 @@ imagetoraster(int inputfd,         /* I - File descriptor input stream */
                        xc1, yc1;
   ppd_file_t           *ppd;           /* PPD file */
   ppd_choice_t         *choice;        /* PPD option choice */
-  char                 *resolution = "",       /* Output resolution */
-                       *media_type   /* Media type */
+  char                 *resolution = strdup("300dpi") ,        /* Output resolution */
+                       *media_type ;   /* Media type */
   ppd_profile_t                *profile;       /* Color profile */
   ppd_profile_t                userprofile;    /* User-specified profile */
   cups_raster_t                *ras;           /* Raster stream */
@@ -420,6 +420,7 @@ imagetoraster(int inputfd,         /* I - File descriptor input stream */
       header.cupsPageSize[1] :
       (float)header.PageSize[1];
   }
+if(log) log(ld, FILTER_LOGLEVEL_DEBUG, "doc.color = %d", doc.Color);
   if ((val = cupsGetOption("multiple-document-handling",
                           num_options, options)) != NULL)
   {
@@ -560,7 +561,7 @@ imagetoraster(int inputfd,         /* I - File descriptor input stream */
  /*
   * Set the needed options in the page header...
   */
-
+  if(ppd!=NULL)
   if (ppdRasterInterpretPPD(&header, ppd, num_options, options, raster_cb))
   {
     if (log) {
@@ -635,7 +636,8 @@ imagetoraster(int inputfd,         /* I - File descriptor input stream */
     }
   }
   else
-    resolution = strdup("");
+    resolution = strdup("300dpi");
+  if(log) log(ld, FILTER_LOGLEVEL_DEBUG, "Resolution = %s", resolution);
 
   /* support the "cm-calibration" option */
   cm_calibrate = cmGetCupsColorCalibrateMode(options, num_options);
@@ -1919,19 +1921,29 @@ imagetoraster(int inputfd,         /* I - File descriptor input stream */
          /*
          * Free memory used for the "zoom" engine...
          */
-         free(resolution);
-         free(media_type);
           _cupsImageZoomDelete(z);
         }
       }
-
+       if(resolution){
+               free(resolution);
+               resolution = NULL;
+       }
+       if(media_type){
+               free(media_type);
+               media_type = NULL;
+       }
  /*
   * Close files...
   */
 
  canceled:
-  free(resolution);
-  free(media_type);
+  if(resolution){
+    free(resolution);
+    resolution = NULL;}
+  if(media_type){
+    free(media_type);
+    media_type = NULL;
+   }
   free(row);
   cupsRasterClose(ras);
   cupsImageClose(img);