After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 172406 - gconvert.c, function open_converter
gconvert.c, function open_converter
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
2.6.x
Other All
: Normal major
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2005-04-02 02:00 UTC by Morten Welinder
Modified: 2011-02-18 16:14 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Use malloc directly and do not use sprintf to concatenate strings (1.89 KB, patch)
2005-07-28 19:40 UTC, Morten Welinder
none Details | Review
Updated patch (2.33 KB, patch)
2005-07-29 20:39 UTC, Morten Welinder
none Details | Review

Description Morten Welinder 2005-04-02 02:00:20 UTC
This function allocates strings that might very well be under Dr. Evil's control
on the stack.  That doesn't feel safe.  (And if it is for speed, then using an
sprintf type function on it is plain silly.)

This function should probably use malloc right away.
Comment 1 Matthias Clasen 2005-04-05 02:42:12 UTC
Or use a hash table whose keys are pairs of strings
Comment 2 Morten Welinder 2005-07-28 17:47:56 UTC
This is a performance problem also.

Doing a lot of g_utf8_collate calls shows that about 40% of the time for
g_utf8_collate is spent in open_converter, the vast majority in the
_g_sprintf call.  (_g_sprintf ends up doing lots of memory allocation
due to the way it is implemented; it is simply not the right tool for
string concatenation.)
Comment 3 Morten Welinder 2005-07-28 19:40:51 UTC
Created attachment 49896 [details] [review]
Use malloc directly and do not use sprintf to concatenate strings

This cuts around 30% of the time for gnumeric to load the test case in
bug 311816.  That load time is dominated by g_str_collate.

At the same time it resolves the security issue with the stack management.
Comment 4 Morten Welinder 2005-07-29 20:39:51 UTC
Created attachment 49955 [details] [review]
Updated patch

Updated patch that avoids malloc for small keys that are in the cache.
Comment 5 Matthias Clasen 2006-12-15 04:36:20 UTC
2006-12-14  Matthias Clasen  <mclasen@redhat.com>

	* glib/gconvert.c (open_converter): Don't use alloca
	and avoid allocating memory for small keys that are 
	already cached.  (#172406, Morten Welinder)