]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - filter/image-pnm.c
Import CUPS 1.4svn-r7226.
[thirdparty/cups.git] / filter / image-pnm.c
index 1f87829d3e3fbf57b5b5f158a63aa89e616a3782..86615d917ddcfbed32c06e7daf8692d6d2067646 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   Portable Any Map file routines for the Common UNIX Printing System (CUPS).
  *
- *   Copyright 2007 by Apple Inc.
+ *   Copyright 2007-2008 by Apple Inc.
  *   Copyright 1993-2007 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
@@ -67,7 +67,13 @@ _cupsImageReadPNM(
   *   max sample
   */
 
-  lineptr = fgets(line, sizeof(line), fp);
+  if ((lineptr = fgets(line, sizeof(line), fp)) == NULL)
+  {
+    fputs("DEBUG: Bad PNM header!\n", stderr);
+    fclose(fp);
+    return (1);
+  }
+
   lineptr ++;
 
   format = atoi(lineptr);
@@ -147,8 +153,21 @@ _cupsImageReadPNM(
   cupsImageSetMaxTiles(img, 0);
 
   bpp = cupsImageGetDepth(img);
-  in  = malloc(img->xsize * 3);
-  out = malloc(img->xsize * bpp);
+
+  if ((in = malloc(img->xsize * 3)) == NULL)
+  {
+    fputs("DEBUG: Unable to allocate memory!\n", stderr);
+    fclose(fp);
+    return (1);
+  }
+
+  if ((out = malloc(img->xsize * bpp)) == NULL)
+  {
+    fputs("DEBUG: Unable to allocate memory!\n", stderr);
+    fclose(fp);
+    free(in);
+    return (1);
+  }
 
  /*
   * Read the image file...