From 09f3e41c2523f597ecc7d3afdd0aaa8f9659ad06 Mon Sep 17 00:00:00 2001 From: suzuki toshiya Date: Sun, 15 Jan 2012 02:48:47 +0900 Subject: [PATCH] [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. --- ChangeLog | 9 +++++++++ src/base/ftglyph.c | 24 ++++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index bbb205b34..0fe07bd87 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2012-01-14 suzuki toshiya + + [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 [base] Insert explict cast for GCC 4.6 in PIC mode. diff --git a/src/base/ftglyph.c b/src/base/ftglyph.c index b22050800..3d7cf3626 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;