diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-09-11 22:45:32 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-09-11 22:45:32 +0000 |
commit | e0bf5085a192fe5e9ba401ea7bc62f304c370c4d (patch) | |
tree | d34f094aa2b645b0e2989977565e77a71a3e85b8 /src/util/container_meta_data.c | |
parent | 5e11dc84e665f1de925336dec1eaf9d4071352dd (diff) | |
download | gnunet-e0bf5085a192fe5e9ba401ea7bc62f304c370c4d.tar.gz gnunet-e0bf5085a192fe5e9ba401ea7bc62f304c370c4d.zip |
-cosmetics, trying to narrow down deserialization error
Diffstat (limited to 'src/util/container_meta_data.c')
-rw-r--r-- | src/util/container_meta_data.c | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/src/util/container_meta_data.c b/src/util/container_meta_data.c index 34c06b162..780ee612d 100644 --- a/src/util/container_meta_data.c +++ b/src/util/container_meta_data.c | |||
@@ -123,7 +123,7 @@ struct GNUNET_CONTAINER_MetaData | |||
123 | struct GNUNET_CONTAINER_MetaData * | 123 | struct GNUNET_CONTAINER_MetaData * |
124 | GNUNET_CONTAINER_meta_data_create () | 124 | GNUNET_CONTAINER_meta_data_create () |
125 | { | 125 | { |
126 | return GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_MetaData)); | 126 | return GNUNET_new (struct GNUNET_CONTAINER_MetaData); |
127 | } | 127 | } |
128 | 128 | ||
129 | 129 | ||
@@ -263,8 +263,8 @@ GNUNET_CONTAINER_meta_data_test_equal (const struct GNUNET_CONTAINER_MetaData | |||
263 | * @param data_mime_type mime-type of data (not of the original file); | 263 | * @param data_mime_type mime-type of data (not of the original file); |
264 | * can be NULL (if mime-type is not known) | 264 | * can be NULL (if mime-type is not known) |
265 | * @param data actual meta-data found | 265 | * @param data actual meta-data found |
266 | * @param data_size number of bytes in data | 266 | * @param data_size number of bytes in @a data |
267 | * @return GNUNET_OK on success, GNUNET_SYSERR if this entry already exists | 267 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if this entry already exists |
268 | * data_mime_type and plugin_name are not considered for "exists" checks | 268 | * data_mime_type and plugin_name are not considered for "exists" checks |
269 | */ | 269 | */ |
270 | int | 270 | int |
@@ -279,6 +279,10 @@ GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md, | |||
279 | struct MetaItem *mi; | 279 | struct MetaItem *mi; |
280 | char *p; | 280 | char *p; |
281 | 281 | ||
282 | if ((EXTRACTOR_METAFORMAT_UTF8 == format) || | ||
283 | (EXTRACTOR_METAFORMAT_C_STRING == format)) | ||
284 | GNUNET_break ('\0' == data[data_size - 1]); | ||
285 | |||
282 | for (pos = md->items_head; NULL != pos; pos = pos->next) | 286 | for (pos = md->items_head; NULL != pos; pos = pos->next) |
283 | { | 287 | { |
284 | if (pos->data_size < data_size) | 288 | if (pos->data_size < data_size) |
@@ -301,7 +305,7 @@ GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md, | |||
301 | } | 305 | } |
302 | } | 306 | } |
303 | md->item_count++; | 307 | md->item_count++; |
304 | mi = GNUNET_malloc (sizeof (struct MetaItem)); | 308 | mi = GNUNET_new (struct MetaItem); |
305 | mi->type = type; | 309 | mi->type = type; |
306 | mi->format = format; | 310 | mi->format = format; |
307 | mi->data_size = data_size; | 311 | mi->data_size = data_size; |
@@ -349,7 +353,7 @@ GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md, | |||
349 | * @param data_mime_type mime-type of data (not of the original file); | 353 | * @param data_mime_type mime-type of data (not of the original file); |
350 | * can be NULL (if mime-type is not known) | 354 | * can be NULL (if mime-type is not known) |
351 | * @param data actual meta-data found | 355 | * @param data actual meta-data found |
352 | * @param data_size number of bytes in data | 356 | * @param data_size number of bytes in @a data |
353 | * @return 0 (to continue) | 357 | * @return 0 (to continue) |
354 | */ | 358 | */ |
355 | static int | 359 | static int |
@@ -387,8 +391,8 @@ GNUNET_CONTAINER_meta_data_merge (struct GNUNET_CONTAINER_MetaData *md, | |||
387 | * @param type type of the item to remove | 391 | * @param type type of the item to remove |
388 | * @param data specific value to remove, NULL to remove all | 392 | * @param data specific value to remove, NULL to remove all |
389 | * entries of the given type | 393 | * entries of the given type |
390 | * @param data_size number of bytes in data | 394 | * @param data_size number of bytes in @a data |
391 | * @return GNUNET_OK on success, GNUNET_SYSERR if the item does not exist in md | 395 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the item does not exist in md |
392 | */ | 396 | */ |
393 | int | 397 | int |
394 | GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md, | 398 | GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md, |
@@ -573,7 +577,7 @@ GNUNET_CONTAINER_meta_data_get_thumbnail (const struct GNUNET_CONTAINER_MetaData | |||
573 | 577 | ||
574 | 578 | ||
575 | /** | 579 | /** |
576 | * Duplicate struct GNUNET_CONTAINER_MetaData. | 580 | * Duplicate a `struct GNUNET_CONTAINER_MetaData`. |
577 | * | 581 | * |
578 | * @param md what to duplicate | 582 | * @param md what to duplicate |
579 | * @return duplicate meta-data container | 583 | * @return duplicate meta-data container |
@@ -607,8 +611,8 @@ GNUNET_CONTAINER_meta_data_duplicate (const struct GNUNET_CONTAINER_MetaData | |||
607 | * @param oldSize number of bytes in data | 611 | * @param oldSize number of bytes in data |
608 | * @param result set to the compressed data | 612 | * @param result set to the compressed data |
609 | * @param newSize set to size of result | 613 | * @param newSize set to size of result |
610 | * @return GNUNET_YES if compression reduce the size, | 614 | * @return #GNUNET_YES if compression reduce the size, |
611 | * GNUNET_NO if compression did not help | 615 | * #GNUNET_NO if compression did not help |
612 | */ | 616 | */ |
613 | static int | 617 | static int |
614 | try_compression (const char *data, size_t oldSize, char **result, | 618 | try_compression (const char *data, size_t oldSize, char **result, |
@@ -730,7 +734,7 @@ struct MetaDataEntry | |||
730 | * meta-data to match the size constraint, | 734 | * meta-data to match the size constraint, |
731 | * possibly discarding some data? | 735 | * possibly discarding some data? |
732 | * @return number of bytes written on success, | 736 | * @return number of bytes written on success, |
733 | * GNUNET_SYSERR on error (typically: not enough | 737 | * #GNUNET_SYSERR on error (typically: not enough |
734 | * space) | 738 | * space) |
735 | */ | 739 | */ |
736 | ssize_t | 740 | ssize_t |
@@ -809,23 +813,26 @@ GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData | |||
809 | ent[i].type = htonl ((uint32_t) pos->type); | 813 | ent[i].type = htonl ((uint32_t) pos->type); |
810 | ent[i].format = htonl ((uint32_t) pos->format); | 814 | ent[i].format = htonl ((uint32_t) pos->format); |
811 | ent[i].data_size = htonl ((uint32_t) pos->data_size); | 815 | ent[i].data_size = htonl ((uint32_t) pos->data_size); |
812 | if (pos->plugin_name == NULL) | 816 | if (NULL == pos->plugin_name) |
813 | plen = 0; | 817 | plen = 0; |
814 | else | 818 | else |
815 | plen = strlen (pos->plugin_name) + 1; | 819 | plen = strlen (pos->plugin_name) + 1; |
816 | ent[i].plugin_name_len = htonl ((uint32_t) plen); | 820 | ent[i].plugin_name_len = htonl ((uint32_t) plen); |
817 | if (pos->mime_type == NULL) | 821 | if (NULL == pos->mime_type) |
818 | mlen = 0; | 822 | mlen = 0; |
819 | else | 823 | else |
820 | mlen = strlen (pos->mime_type) + 1; | 824 | mlen = strlen (pos->mime_type) + 1; |
821 | ent[i].mime_type_len = htonl ((uint32_t) mlen); | 825 | ent[i].mime_type_len = htonl ((uint32_t) mlen); |
822 | off -= pos->data_size; | 826 | off -= pos->data_size; |
827 | if ((EXTRACTOR_METAFORMAT_UTF8 == pos->format) || | ||
828 | (EXTRACTOR_METAFORMAT_C_STRING == pos->format)) | ||
829 | GNUNET_break ('\0' == pos->data[pos->data_size - 1]); | ||
823 | memcpy (&mdata[off], pos->data, pos->data_size); | 830 | memcpy (&mdata[off], pos->data, pos->data_size); |
824 | off -= plen; | 831 | off -= plen; |
825 | if (pos->plugin_name != NULL) | 832 | if (NULL != pos->plugin_name) |
826 | memcpy (&mdata[off], pos->plugin_name, plen); | 833 | memcpy (&mdata[off], pos->plugin_name, plen); |
827 | off -= mlen; | 834 | off -= mlen; |
828 | if (pos->mime_type != NULL) | 835 | if (NULL != pos->mime_type) |
829 | memcpy (&mdata[off], pos->mime_type, mlen); | 836 | memcpy (&mdata[off], pos->mime_type, mlen); |
830 | i++; | 837 | i++; |
831 | } | 838 | } |
@@ -939,7 +946,7 @@ GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData | |||
939 | ihdr.entries = htonl (0); | 946 | ihdr.entries = htonl (0); |
940 | ihdr.size = htonl (0); | 947 | ihdr.size = htonl (0); |
941 | if (NULL == *target) | 948 | if (NULL == *target) |
942 | *target = GNUNET_malloc (sizeof (struct MetaDataHeader)); | 949 | *target = (char *) GNUNET_new (struct MetaDataHeader); |
943 | memcpy (*target, &ihdr, sizeof (struct MetaDataHeader)); | 950 | memcpy (*target, &ihdr, sizeof (struct MetaDataHeader)); |
944 | return sizeof (struct MetaDataHeader); | 951 | return sizeof (struct MetaDataHeader); |
945 | } | 952 | } |
@@ -1107,7 +1114,12 @@ GNUNET_CONTAINER_meta_data_deserialize (const char *input, size_t size) | |||
1107 | if ((EXTRACTOR_METAFORMAT_UTF8 == format) || | 1114 | if ((EXTRACTOR_METAFORMAT_UTF8 == format) || |
1108 | (EXTRACTOR_METAFORMAT_C_STRING == format)) | 1115 | (EXTRACTOR_METAFORMAT_C_STRING == format)) |
1109 | { | 1116 | { |
1110 | if ((0 == dlen) || ('\0' != mdata[left + dlen - 1])) | 1117 | if (0 == dlen) |
1118 | { | ||
1119 | GNUNET_break_op (0); | ||
1120 | break; | ||
1121 | } | ||
1122 | if ('\0' != meta_data[dlen - 1]) | ||
1111 | { | 1123 | { |
1112 | GNUNET_break_op (0); | 1124 | GNUNET_break_op (0); |
1113 | break; | 1125 | break; |