mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
Calculate size correctly, avoid use-after-free.
2008-08-20 Colin Walters <walters@verbum.org> * girepository/girmodule.c (g_ir_module_build_typelib): Calculate size correctly, avoid use-after-free. svn path=/trunk/; revision=427
This commit is contained in:
parent
61ae81c9c8
commit
ae74722007
19
girmodule.c
19
girmodule.c
@ -64,7 +64,7 @@ GTypelib *
|
||||
g_ir_module_build_typelib (GIrModule *module,
|
||||
GList *modules)
|
||||
{
|
||||
guchar *typelib;
|
||||
GTypelib *typelib;
|
||||
gsize length;
|
||||
gint i;
|
||||
GList *e;
|
||||
@ -102,6 +102,11 @@ g_ir_module_build_typelib (GIrModule *module,
|
||||
size += g_ir_node_get_full_size (node);
|
||||
}
|
||||
|
||||
/* Adjust size for strings allocated in header below specially */
|
||||
size += strlen (module->name);
|
||||
if (module->shared_library)
|
||||
size += strlen (module->shared_library);
|
||||
|
||||
g_message ("allocating %d bytes (%d header, %d directory, %d entries)\n",
|
||||
size, header_size, dir_size, size - header_size - dir_size);
|
||||
|
||||
@ -201,15 +206,19 @@ g_ir_module_build_typelib (GIrModule *module,
|
||||
}
|
||||
|
||||
dump_stats ();
|
||||
g_hash_table_destroy (strings);
|
||||
g_hash_table_destroy (types);
|
||||
|
||||
header->annotations = offset2;
|
||||
|
||||
g_message ("reallocating to %d bytes", offset2);
|
||||
|
||||
typelib = g_realloc (data, offset2);
|
||||
data = g_realloc (data, offset2);
|
||||
header = (Header*) data;
|
||||
length = header->size = offset2;
|
||||
return g_typelib_new_from_memory (typelib, length);
|
||||
typelib = g_typelib_new_from_memory (data, length);
|
||||
|
||||
g_hash_table_destroy (strings);
|
||||
g_hash_table_destroy (types);
|
||||
|
||||
return typelib;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user