|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
[Bug] [Patch] PrefsUI_GetPrefs() does not use preference getters (-> segfault)Hello,
I found a bug in FontForge 20090923 on Linux (it may be present in earlier versions, too; it is not yet fixed in CVS HEAD): PrefsUI_GetPrefs() does not use preference getters for string values but always tries to dereference the "val" field of the "prefs_list" structure (and thus segfaults e. g. for the "AutotraceArgs" pref, since "val" is set to NULL in this case). How to reproduce: fontforge -lang=ff -c 'Print( "[", GetPref( "AutotraceArgs" ), "]" );' Expected result: The string "[]". What happens instead: FontForge causes a segmentation fault. The fix is easy, but I wrote a patch for it anyway. I also made PrefsUI_GetPrefs() correctly return an empty string if the setting is set to NULL. (see attachment for the patch, I do not know if my mail client will leave it intact if I simply paste it) Cheers! Tilman Blumenbach a.k.a. Tblue / tblue246 on SF diff -ruNa fontforge-20090923.orig/fontforge/prefs.c fontforge-20090923/fontforge/prefs.c --- fontforge-20090923.orig/fontforge/prefs.c 2009-09-10 00:46:55.000000000 +0200 +++ fontforge-20090923/fontforge/prefs.c 2009-10-28 17:17:13.000000000 +0100 @@ -599,7 +599,9 @@ val->u.ival = *((int *) (pf->val)); } else if ( pf->type == pr_string || pf->type == pr_file ) { val->type = v_str; - val->u.sval = copy( *((char **) (pf->val))); + + char *tmpstr = pf->val ? *((char **) (pf->val)) : (char *) (pf->get)(); + val->u.sval = copy( tmpstr ? tmpstr : "" ); } else if ( pf->type == pr_encoding ) { val->type = v_str; if ( *((NameList **) (pf->val))==NULL ) ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Fontforge-devel mailing list Fontforge-devel@... https://lists.sourceforge.net/lists/listinfo/fontforge-devel |
|
|
Re: [Bug] [Patch] PrefsUI_GetPrefs() does not use preference getters (-> segfault)Oops, I missed a few things in my original patch... Here's the correct one.
Tilman Blumenbach schrieb: > Hello, > > I found a bug in FontForge 20090923 on Linux (it may be present in > earlier versions, too; it is not yet fixed in CVS HEAD): > PrefsUI_GetPrefs() does not use preference getters for string values but > always tries to dereference the "val" field of the "prefs_list" > structure (and thus segfaults e. g. for the "AutotraceArgs" pref, since > "val" is set to NULL in this case). > > How to reproduce: > fontforge -lang=ff -c 'Print( "[", GetPref( "AutotraceArgs" ), "]" );' > > Expected result: > The string "[]". > > What happens instead: > FontForge causes a segmentation fault. > > The fix is easy, but I wrote a patch for it anyway. I also made > PrefsUI_GetPrefs() correctly return an empty string if the setting is > set to NULL. > > (see attachment for the patch, I do not know if my mail client will > leave it intact if I simply paste it) > > Cheers! > > Tilman Blumenbach a.k.a. Tblue / tblue246 on SF diff -ruNa fontforge-20090923.orig/fontforge/noprefs.c fontforge-20090923/fontforge/noprefs.c --- fontforge-20090923.orig/fontforge/noprefs.c 2009-09-01 05:24:26.000000000 +0200 +++ fontforge-20090923/fontforge/noprefs.c 2009-10-29 14:26:46.000000000 +0100 @@ -345,7 +345,12 @@ val->u.ival = *((int *) (pf->val)); } else if ( pf->type == pr_string || pf->type == pr_file ) { val->type = v_str; - val->u.sval = copy( *((char **) (pf->val))); + + char *tmpstr = pf->val ? *((char **) (pf->val)) : (char *) (pf->get)(); + val->u.sval = copy( tmpstr ? tmpstr : "" ); + + if( ! pf->val ) + free( tmpstr ); } else if ( pf->type == pr_encoding ) { val->type = v_str; if ( *((NameList **) (pf->val))==NULL ) diff -ruNa fontforge-20090923.orig/fontforge/prefs.c fontforge-20090923/fontforge/prefs.c --- fontforge-20090923.orig/fontforge/prefs.c 2009-09-10 00:46:55.000000000 +0200 +++ fontforge-20090923/fontforge/prefs.c 2009-10-29 14:21:13.000000000 +0100 @@ -599,7 +599,12 @@ val->u.ival = *((int *) (pf->val)); } else if ( pf->type == pr_string || pf->type == pr_file ) { val->type = v_str; - val->u.sval = copy( *((char **) (pf->val))); + + char *tmpstr = pf->val ? *((char **) (pf->val)) : (char *) (pf->get)(); + val->u.sval = copy( tmpstr ? tmpstr : "" ); + + if( ! pf->val ) + free( tmpstr ); } else if ( pf->type == pr_encoding ) { val->type = v_str; if ( *((NameList **) (pf->val))==NULL ) ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Fontforge-devel mailing list Fontforge-devel@... https://lists.sourceforge.net/lists/listinfo/fontforge-devel |
| Free embeddable forum powered by Nabble | Forum Help |