Commit 09f3e41c2523f597ecc7d3afdd0aaa8f9659ad06

suzuki toshiya 2012-01-15T02:48:47

[base] Fix a dereference of uninitialized variable in PIC mode. * src/base/ftglyph.c (FT_Glyph_To_Bitmap): `glyph' must be set before derefering to obtain `library'. The initialization of `clazz', `glyph', `library' and NULL pointer check are reordered to minimize PIC conditonals.

diff --git a/ChangeLog b/ChangeLog
index bbb205b..0fe07bd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2012-01-14  suzuki toshiya  <mpsuzuki@hiroshima-u.ac.jp>
 
+	[base] Fix a dereference of uninitialized variable in PIC mode.
+
+	* src/base/ftglyph.c (FT_Glyph_To_Bitmap): `glyph' must be
+	set before derefering to obtain `library'.  The initialization
+	of `clazz', `glyph', `library' and NULL pointer check are
+	reordered to minimize PIC conditonals.
+
+2012-01-14  suzuki toshiya  <mpsuzuki@hiroshima-u.ac.jp>
+
 	[base] Insert explict cast for GCC 4.6 in PIC mode.
 
 	* src/base/ftinit.c (FT_Add_Default_Modules): Under PIC
diff --git a/src/base/ftglyph.c b/src/base/ftglyph.c
index b220508..3d7cf36 100644
--- a/src/base/ftglyph.c
+++ b/src/base/ftglyph.c
@@ -512,42 +512,42 @@
     FT_Error                  error = FT_Err_Ok;
     FT_Glyph                  glyph;
     FT_BitmapGlyph            bitmap = NULL;
-
     const FT_Glyph_Class*     clazz;
 
-#ifdef FT_CONFIG_OPTION_PIC
-    FT_Library                library = FT_GLYPH( glyph )->library;
-#endif
+    /* FT_BITMAP_GLYPH_CLASS_GET derefers `library' in PIC mode */
+    FT_Library                library;
 
 
     /* check argument */
     if ( !the_glyph )
       goto Bad;
-
-    /* we render the glyph into a glyph bitmap using a `dummy' glyph slot */
-    /* then calling FT_Render_Glyph_Internal()                            */
-
     glyph = *the_glyph;
     if ( !glyph )
       goto Bad;
 
-    clazz = glyph->clazz;
+    clazz   = glyph->clazz;
+    library = glyph->library;
+    if ( !library || !clazz )
+      goto Bad;
 
     /* when called with a bitmap glyph, do nothing and return successfully */
     if ( clazz == FT_BITMAP_GLYPH_CLASS_GET )
       goto Exit;
 
-    if ( !clazz || !clazz->glyph_prepare )
+    if ( !clazz->glyph_prepare )
       goto Bad;
 
+    /* we render the glyph into a glyph bitmap using a `dummy' glyph slot */
+    /* then calling FT_Render_Glyph_Internal()                            */
+
     FT_MEM_ZERO( &dummy, sizeof ( dummy ) );
     FT_MEM_ZERO( &dummy_internal, sizeof ( dummy_internal ) );
     dummy.internal = &dummy_internal;
-    dummy.library  = glyph->library;
+    dummy.library  = library;
     dummy.format   = clazz->glyph_format;
 
     /* create result bitmap glyph */
-    error = ft_new_glyph( glyph->library, FT_BITMAP_GLYPH_CLASS_GET,
+    error = ft_new_glyph( library, FT_BITMAP_GLYPH_CLASS_GET,
                           (FT_Glyph*)(void*)&bitmap );
     if ( error )
       goto Exit;