[gobject-introspection] typelib compiler: properly initialise memory



commit fe7fd5dc0e61b9b546a65a0d14f498f6514b072f
Author: Ryan Lortie <desrt desrt ca>
Date:   Sat Dec 28 19:37:18 2013 -0500

    typelib compiler: properly initialise memory
    
    The typelib compiler was writing uninitialised memory to the output file.
    
    There were two sources of this uninitialised memory: the hash writer included
    some uninitialised memory in its output, and the bytes added after the hash
    output for padding were also not being initialised.
    
    Fix this by passing the padded size to the hash code writer function and
    having that function initialise the entire memory region to zero before
    writing.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=721177

 girepository/girmodule.c |    3 ++-
 girepository/gthash.c    |    2 ++
 2 files changed, 4 insertions(+), 1 deletions(-)
---
diff --git a/girepository/girmodule.c b/girepository/girmodule.c
index 05c8987..e3897c3 100644
--- a/girepository/girmodule.c
+++ b/girepository/girmodule.c
@@ -279,8 +279,9 @@ add_directory_index_section (guint8 *data, GIrModule *module, guint32 *offset2)
   alloc_section (data, GI_SECTION_DIRECTORY_INDEX, *offset2);
 
   required_size = _gi_typelib_hash_builder_get_buffer_size (dirindex_builder);
+  required_size = ALIGN_VALUE (required_size, 4);
 
-  new_offset = *offset2 + ALIGN_VALUE (required_size, 4);
+  new_offset = *offset2 + required_size;
 
   data = g_realloc (data, new_offset);
 
diff --git a/girepository/gthash.c b/girepository/gthash.c
index ecc3b10..831c87e 100644
--- a/girepository/gthash.c
+++ b/girepository/gthash.c
@@ -158,6 +158,8 @@ _gi_typelib_hash_builder_pack (GITypelibHashBuilder *builder, guint8* mem, guint
   g_assert (len >= builder->packed_size);
   g_assert ((((unsigned long)mem) & 0x3) == 0);
 
+  memset (mem, 0, len);
+
   *((guint32*) mem) = builder->dirmap_offset;
   packed_mem = (guint8*)(mem + sizeof(guint32));
   cmph_pack (builder->c, packed_mem);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]