MinGW
[oweals/gnunet.git] / src / util / container_meta_data.c
index a614f3c4fb62b6b5c1f00a21cbe6e8ee273ba425..fadb0dede2feef8e3418a9c044237f72791d8f65 100644 (file)
@@ -227,7 +227,7 @@ GNUNET_CONTAINER_meta_data_test_equal (const struct GNUNET_CONTAINER_MetaData
  *
  * @param md metadata to extend
  * @param plugin_name name of the plugin that produced this value;
- *        special values can be used (i.e. '<zlib>' for zlib being
+ *        special values can be used (i.e. '&lt;zlib&gt;' for zlib being
  *        used in the main libextractor library and yielding
  *        meta data).
  * @param type libextractor-type describing the meta data
@@ -519,7 +519,8 @@ GNUNET_CONTAINER_meta_data_get_thumbnail (const struct
        }
       pos = pos->next;
     }
-  if (match == NULL)
+  if ( (match == NULL) ||
+       (match->data_size == 0) )
     return 0;
   *thumb = GNUNET_malloc (match->data_size);
   memcpy (*thumb, match->data, match->data_size);
@@ -565,7 +566,7 @@ GNUNET_CONTAINER_meta_data_duplicate (const struct GNUNET_CONTAINER_MetaData
  *
  * @param cls closure, our meta data container
  * @param plugin_name name of the plugin that produced this value;
- *        special values can be used (i.e. '<zlib>' for zlib being
+ *        special values can be used (i.e. '&lt;zlib&gt;' for zlib being
  *        used in the main libextractor library and yielding
  *        meta data).
  * @param type libextractor-type describing the meta data
@@ -855,15 +856,20 @@ GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData
       off -= pos->data_size;
       memcpy (&mdata[off], pos->data, pos->data_size);
       off -= plen;
-      memcpy (&mdata[off], pos->plugin_name, plen);
+      if (pos->plugin_name != NULL)
+       memcpy (&mdata[off], pos->plugin_name, plen);
       off -= mlen;
-      memcpy (&mdata[off], pos->mime_type, mlen);      
+      if (pos->mime_type != NULL)
+       memcpy (&mdata[off], pos->mime_type, mlen);      
       i++;
       pos = pos->next;
     }  
   GNUNET_assert (off == 0);
 
+  clen = 0;
+  cdata = NULL;
   left = size;
+  pos = md->items;
   for (i=0;i<md->item_count;i++)
     {           
       comp = GNUNET_NO;
@@ -885,6 +891,7 @@ GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData
          hdr->entries = htonl (md->item_count);
          if (GNUNET_YES == comp)
            {
+             GNUNET_assert (clen < left);
              hdr->version = htonl (2 | HEADER_COMPRESSED);
              memcpy (&hdr[1],
                      cdata, 
@@ -958,7 +965,8 @@ GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData
       if (pos->plugin_name != NULL)
        left -= strlen (pos->plugin_name) + 1;
       if (pos->mime_type != NULL)
-       left -= strlen (pos->mime_type) + 1;      
+       left -= strlen (pos->mime_type) + 1;
+      pos = pos->next;
     }
   GNUNET_free (ent);