Blame SOURCES/freetype-2.4.11-ft-strncmp.patch

43e195
commit 9a56764037dfc01a89fe61f5c67971bf50343d00
43e195
Author: Werner Lemberg <wl@gnu.org>
43e195
Date:   Wed Feb 26 13:08:07 2014 +0100
43e195
43e195
    [bdf] Fix Savannah bug #41692.
43e195
    
43e195
    bdflib puts data from the input stream into a buffer in chunks of
43e195
    1024 bytes.  The data itself gets then parsed line by line, simply
43e195
    increasing the current pointer into the buffer; if the search for
43e195
    the final newline character exceeds the buffer size, more data gets
43e195
    read.
43e195
    
43e195
    However, in case the current line's end is very near to the buffer
43e195
    end, and the keyword to compare with is longer than the current
43e195
    line's length, an out-of-bounds read might happen since `memcmp'
43e195
    doesn't stop properly at the string end.
43e195
    
43e195
    * src/bdf/bdflib.c: s/ft_memcmp/ft_strncmp/ to make comparisons
43e195
    stop at string ends.
43e195
43e195
diff --git a/src/bdf/bdflib.c b/src/bdf/bdflib.c
43e195
index c9e231e..b0ec292 100644
43e195
--- a/src/bdf/bdflib.c
43e195
+++ b/src/bdf/bdflib.c
43e195
@@ -1402,7 +1402,7 @@
43e195
 
43e195
     /* If the property happens to be a comment, then it doesn't need */
43e195
     /* to be added to the internal hash table.                       */
43e195
-    if ( ft_memcmp( name, "COMMENT", 7 ) != 0 )
43e195
+    if ( ft_strncmp( name, "COMMENT", 7 ) != 0 )
43e195
     {
43e195
       /* Add the property to the font property table. */
43e195
       error = hash_insert( fp->name,
43e195
@@ -1420,13 +1420,13 @@
43e195
     /* FONT_ASCENT and FONT_DESCENT need to be assigned if they are        */
43e195
     /* present, and the SPACING property should override the default       */
43e195
     /* spacing.                                                            */
43e195
-    if ( ft_memcmp( name, "DEFAULT_CHAR", 12 ) == 0 )
43e195
+    if ( ft_strncmp( name, "DEFAULT_CHAR", 12 ) == 0 )
43e195
       font->default_char = fp->value.l;
43e195
-    else if ( ft_memcmp( name, "FONT_ASCENT", 11 ) == 0 )
43e195
+    else if ( ft_strncmp( name, "FONT_ASCENT", 11 ) == 0 )
43e195
       font->font_ascent = fp->value.l;
43e195
-    else if ( ft_memcmp( name, "FONT_DESCENT", 12 ) == 0 )
43e195
+    else if ( ft_strncmp( name, "FONT_DESCENT", 12 ) == 0 )
43e195
       font->font_descent = fp->value.l;
43e195
-    else if ( ft_memcmp( name, "SPACING", 7 ) == 0 )
43e195
+    else if ( ft_strncmp( name, "SPACING", 7 ) == 0 )
43e195
     {
43e195
       if ( !fp->value.atom )
43e195
       {
43e195
@@ -1484,7 +1484,7 @@
43e195
     memory = font->memory;
43e195
 
43e195
     /* Check for a comment. */
43e195
-    if ( ft_memcmp( line, "COMMENT", 7 ) == 0 )
43e195
+    if ( ft_strncmp( line, "COMMENT", 7 ) == 0 )
43e195
     {
43e195
       linelen -= 7;
43e195
 
43e195
@@ -1501,7 +1501,7 @@
43e195
     /* The very first thing expected is the number of glyphs. */
43e195
     if ( !( p->flags & _BDF_GLYPHS ) )
43e195
     {
43e195
-      if ( ft_memcmp( line, "CHARS", 5 ) != 0 )
43e195
+      if ( ft_strncmp( line, "CHARS", 5 ) != 0 )
43e195
       {
43e195
         FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "CHARS" ));
43e195
         error = BDF_Err_Missing_Chars_Field;
43e195
@@ -1535,7 +1535,7 @@
43e195
     }
43e195
 
43e195
     /* Check for the ENDFONT field. */
43e195
-    if ( ft_memcmp( line, "ENDFONT", 7 ) == 0 )
43e195
+    if ( ft_strncmp( line, "ENDFONT", 7 ) == 0 )
43e195
     {
43e195
       /* Sort the glyphs by encoding. */
43e195
       ft_qsort( (char *)font->glyphs,
43e195
@@ -1549,7 +1549,7 @@
43e195
     }
43e195
 
43e195
     /* Check for the ENDCHAR field. */
43e195
-    if ( ft_memcmp( line, "ENDCHAR", 7 ) == 0 )
43e195
+    if ( ft_strncmp( line, "ENDCHAR", 7 ) == 0 )
43e195
     {
43e195
       p->glyph_enc = 0;
43e195
       p->flags    &= ~_BDF_GLYPH_BITS;
43e195
@@ -1565,7 +1565,7 @@
43e195
       goto Exit;
43e195
 
43e195
     /* Check for the STARTCHAR field. */
43e195
-    if ( ft_memcmp( line, "STARTCHAR", 9 ) == 0 )
43e195
+    if ( ft_strncmp( line, "STARTCHAR", 9 ) == 0 )
43e195
     {
43e195
       /* Set the character name in the parse info first until the */
43e195
       /* encoding can be checked for an unencoded character.      */
43e195
@@ -1599,7 +1599,7 @@
43e195
     }
43e195
 
43e195
     /* Check for the ENCODING field. */
43e195
-    if ( ft_memcmp( line, "ENCODING", 8 ) == 0 )
43e195
+    if ( ft_strncmp( line, "ENCODING", 8 ) == 0 )
43e195
     {
43e195
       if ( !( p->flags & _BDF_GLYPH ) )
43e195
       {
43e195
@@ -1785,7 +1785,7 @@
43e195
     }
43e195
 
43e195
     /* Expect the SWIDTH (scalable width) field next. */
43e195
-    if ( ft_memcmp( line, "SWIDTH", 6 ) == 0 )
43e195
+    if ( ft_strncmp( line, "SWIDTH", 6 ) == 0 )
43e195
     {
43e195
       if ( !( p->flags & _BDF_ENCODING ) )
43e195
         goto Missing_Encoding;
43e195
@@ -1801,7 +1801,7 @@
43e195
     }
43e195
 
43e195
     /* Expect the DWIDTH (scalable width) field next. */
43e195
-    if ( ft_memcmp( line, "DWIDTH", 6 ) == 0 )
43e195
+    if ( ft_strncmp( line, "DWIDTH", 6 ) == 0 )
43e195
     {
43e195
       if ( !( p->flags & _BDF_ENCODING ) )
43e195
         goto Missing_Encoding;
43e195
@@ -1829,7 +1829,7 @@
43e195
     }
43e195
 
43e195
     /* Expect the BBX field next. */
43e195
-    if ( ft_memcmp( line, "BBX", 3 ) == 0 )
43e195
+    if ( ft_strncmp( line, "BBX", 3 ) == 0 )
43e195
     {
43e195
       if ( !( p->flags & _BDF_ENCODING ) )
43e195
         goto Missing_Encoding;
43e195
@@ -1897,7 +1897,7 @@
43e195
     }
43e195
 
43e195
     /* And finally, gather up the bitmap. */
43e195
-    if ( ft_memcmp( line, "BITMAP", 6 ) == 0 )
43e195
+    if ( ft_strncmp( line, "BITMAP", 6 ) == 0 )
43e195
     {
43e195
       unsigned long  bitmap_size;
43e195
 
43e195
@@ -1972,7 +1972,7 @@
43e195
     p    = (_bdf_parse_t *)    client_data;
43e195
 
43e195
     /* Check for the end of the properties. */
43e195
-    if ( ft_memcmp( line, "ENDPROPERTIES", 13 ) == 0 )
43e195
+    if ( ft_strncmp( line, "ENDPROPERTIES", 13 ) == 0 )
43e195
     {
43e195
       /* If the FONT_ASCENT or FONT_DESCENT properties have not been      */
43e195
       /* encountered yet, then make sure they are added as properties and */
43e195
@@ -2013,12 +2013,12 @@
43e195
     }
43e195
 
43e195
     /* Ignore the _XFREE86_GLYPH_RANGES properties. */
43e195
-    if ( ft_memcmp( line, "_XFREE86_GLYPH_RANGES", 21 ) == 0 )
43e195
+    if ( ft_strncmp( line, "_XFREE86_GLYPH_RANGES", 21 ) == 0 )
43e195
       goto Exit;
43e195
 
43e195
     /* Handle COMMENT fields and properties in a special way to preserve */
43e195
     /* the spacing.                                                      */
43e195
-    if ( ft_memcmp( line, "COMMENT", 7 ) == 0 )
43e195
+    if ( ft_strncmp( line, "COMMENT", 7 ) == 0 )
43e195
     {
43e195
       name = value = line;
43e195
       value += 7;
43e195
@@ -2082,7 +2082,7 @@
43e195
 
43e195
     /* Check for a comment.  This is done to handle those fonts that have */
43e195
     /* comments before the STARTFONT line for some reason.                */
43e195
-    if ( ft_memcmp( line, "COMMENT", 7 ) == 0 )
43e195
+    if ( ft_strncmp( line, "COMMENT", 7 ) == 0 )
43e195
     {
43e195
       if ( p->opts->keep_comments != 0 && p->font != 0 )
43e195
       {
43e195
@@ -2108,7 +2108,7 @@
43e195
     {
43e195
       memory = p->memory;
43e195
 
43e195
-      if ( ft_memcmp( line, "STARTFONT", 9 ) != 0 )
43e195
+      if ( ft_strncmp( line, "STARTFONT", 9 ) != 0 )
43e195
       {
43e195
         /* we don't emit an error message since this code gets */
43e195
         /* explicitly caught one level higher                  */
43e195
@@ -2156,7 +2156,7 @@
43e195
     }
43e195
 
43e195
     /* Check for the start of the properties. */
43e195
-    if ( ft_memcmp( line, "STARTPROPERTIES", 15 ) == 0 )
43e195
+    if ( ft_strncmp( line, "STARTPROPERTIES", 15 ) == 0 )
43e195
     {
43e195
       if ( !( p->flags & _BDF_FONT_BBX ) )
43e195
       {
43e195
@@ -2185,7 +2185,7 @@
43e195
     }
43e195
 
43e195
     /* Check for the FONTBOUNDINGBOX field. */
43e195
-    if ( ft_memcmp( line, "FONTBOUNDINGBOX", 15 ) == 0 )
43e195
+    if ( ft_strncmp( line, "FONTBOUNDINGBOX", 15 ) == 0 )
43e195
     {
43e195
       if ( !( p->flags & _BDF_SIZE ) )
43e195
       {
43e195
@@ -2216,7 +2216,7 @@
43e195
     }
43e195
 
43e195
     /* The next thing to check for is the FONT field. */
43e195
-    if ( ft_memcmp( line, "FONT", 4 ) == 0 )
43e195
+    if ( ft_strncmp( line, "FONT", 4 ) == 0 )
43e195
     {
43e195
       error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
43e195
       if ( error )
43e195
@@ -2251,7 +2251,7 @@
43e195
     }
43e195
 
43e195
     /* Check for the SIZE field. */
43e195
-    if ( ft_memcmp( line, "SIZE", 4 ) == 0 )
43e195
+    if ( ft_strncmp( line, "SIZE", 4 ) == 0 )
43e195
     {
43e195
       if ( !( p->flags & _BDF_FONT_NAME ) )
43e195
       {
43e195
@@ -2305,7 +2305,7 @@
43e195
     }
43e195
 
43e195
     /* Check for the CHARS field -- font properties are optional */
43e195
-    if ( ft_memcmp( line, "CHARS", 5 ) == 0 )
43e195
+    if ( ft_strncmp( line, "CHARS", 5 ) == 0 )
43e195
     {
43e195
       char  nbuf[128];
43e195