Module Name:    xsrc
Committed By:   snj
Date:           Tue Mar 17 18:49:51 UTC 2015

Modified Files:
        xsrc/xfree/xc/lib/font/bitmap [netbsd-7]: bdfread.c

Log Message:
Pull up following revision(s) (requested by mrg in ticket #620):
        xfree/xc/lib/font/bitmap/bdfread.c: revision 1.5
pull across bfdread.c fixes from libXfont 1.5.1, which fixes:
- CVE-2015-1802: bdfReadProperties: property count needs range check
    The bdf parser reads a count for the number of properties defined in
    a font from the font file, and allocates arrays with entries for each
    property based on that count.  It never checked to see if that count
    was negative, or large enough to overflow when multiplied by the size
    of the structures being allocated, and could thus allocate the wrong
    buffer size, leading to out of bounds writes.
- CVE-2015-1803: bdfReadCharacters: bailout if a char's bitmap cannot be read
    If the bdf parser failed to parse the data for the bitmap for any
    character, it would proceed with an invalid pointer to the bitmap
    data and later crash when trying to read the bitmap from that pointer.
- CVE-2015-1804: bdfReadCharacters: ensure metrics fit into xCharInfo struct
    The bdf parser read metrics values as 32-bit integers, but stored
    them into 16-bit integers.  Overflows could occur in various operations
    leading to out-of-bounds memory access.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.4.4.1 xsrc/xfree/xc/lib/font/bitmap/bdfread.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: xsrc/xfree/xc/lib/font/bitmap/bdfread.c
diff -u xsrc/xfree/xc/lib/font/bitmap/bdfread.c:1.4 xsrc/xfree/xc/lib/font/bitmap/bdfread.c:1.4.4.1
--- xsrc/xfree/xc/lib/font/bitmap/bdfread.c:1.4	Tue Jan  7 07:43:47 2014
+++ xsrc/xfree/xc/lib/font/bitmap/bdfread.c	Tue Mar 17 18:49:51 2015
@@ -63,8 +63,16 @@ from The Open Group.
 
 #if HAVE_STDINT_H
 #include <stdint.h>
-#elif !defined(INT32_MAX)
-#define INT32_MAX 0x7fffffff
+#else
+# ifndef INT32_MAX
+#  define INT32_MAX 0x7fffffff
+# endif
+# ifndef INT16_MAX
+#  define INT16_MAX 0x7fff
+# endif
+# ifndef INT16_MIN
+#  define INT16_MIN (0 - 0x8000)
+# endif
 #endif
 
 #define INDICES 256
@@ -420,6 +428,12 @@ bdfReadCharacters(FontFilePtr file, Font
 	    bdfError("DWIDTH y value must be zero\n");
 	    goto BAILOUT;
 	}
+	/* xCharInfo metrics are stored as INT16 */
+	if ((wx < 0) || (wx > INT16_MAX)) {
+	    bdfError("character '%s' has out of range width, %d\n",
+		     charName, wx);
+	    goto BAILOUT;
+	}
 	line = bdfGetLine(file, lineBuf, BDFLINELEN);
 	if ((!line) || (sscanf((char *) line, "BBX %d %d %d %d", &bw, &bh, &bl, &bb) != 4)) {
 	    bdfError("bad 'BBX'\n");
@@ -430,6 +444,14 @@ bdfReadCharacters(FontFilePtr file, Font
 		     charName, bw, bh);
 	    goto BAILOUT;
 	}
+	/* xCharInfo metrics are read as int, but stored as INT16 */
+	if ((bl > INT16_MAX) || (bl < INT16_MIN) ||
+	    (bb > INT16_MAX) || (bb < INT16_MIN) ||
+	    (bw > (INT16_MAX - bl)) || (bh > (INT16_MAX - bb))) {
+	    bdfError("character '%s' has out of range metrics, %d %d %d %d\n",
+		     charName, bl, (bl+bw), (bh+bb), -bb);
+	    goto BAILOUT;
+	}
 	line = bdfGetLine(file, lineBuf, BDFLINELEN);
 	if ((line) && (bdfIsPrefix(line, "ATTRIBUTES"))) {
 	    for (p = line + strlen("ATTRIBUTES ");
@@ -461,7 +483,10 @@ bdfReadCharacters(FontFilePtr file, Font
 	    ci->metrics.descent = -bb;
 	    ci->metrics.characterWidth = wx;
 	    ci->bits = NULL;
-	    bdfReadBitmap(ci, file, bit, byte, glyph, scan, bitmapsSizes);
+	    if (!bdfReadBitmap(ci, file, bit, byte, glyph, scan, bitmapsSizes)) {
+		bdfError("could not read bitmap for character '%s'\n", charName);
+		goto BAILOUT;
+	    }
 	    ci++;
 	    ndx++;
 	} else
@@ -609,7 +634,9 @@ bdfReadProperties(FontFilePtr file, Font
 	bdfError("missing 'STARTPROPERTIES'\n");
 	return (FALSE);
     }
-    if (sscanf((char *) line, "STARTPROPERTIES %d", &nProps) != 1) {
+    if ((sscanf((char *) line, "STARTPROPERTIES %d", &nProps) != 1) ||
+	(nProps <= 0) ||
+	(nProps > ((INT32_MAX / sizeof(FontPropRec)) - BDF_GENPROPS))) {
 	bdfError("bad 'STARTPROPERTIES'\n");
 	return (FALSE);
     }

Reply via email to