aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim/reclaim_attribute.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/reclaim/reclaim_attribute.c')
-rw-r--r--src/reclaim/reclaim_attribute.c51
1 files changed, 27 insertions, 24 deletions
diff --git a/src/reclaim/reclaim_attribute.c b/src/reclaim/reclaim_attribute.c
index 05bdc1ac6..971bfce23 100644
--- a/src/reclaim/reclaim_attribute.c
+++ b/src/reclaim/reclaim_attribute.c
@@ -306,7 +306,6 @@ GNUNET_RECLAIM_attribute_list_serialize_get_size (
306 { 306 {
307 GNUNET_assert (NULL != ale->attribute); 307 GNUNET_assert (NULL != ale->attribute);
308 len += GNUNET_RECLAIM_attribute_serialize_get_size (ale->attribute); 308 len += GNUNET_RECLAIM_attribute_serialize_get_size (ale->attribute);
309 len += sizeof(struct GNUNET_RECLAIM_AttributeListEntry);
310 } 309 }
311 return len; 310 return len;
312} 311}
@@ -355,27 +354,28 @@ GNUNET_RECLAIM_attribute_list_deserialize (const char *data, size_t data_size)
355 struct GNUNET_RECLAIM_AttributeListEntry *ale; 354 struct GNUNET_RECLAIM_AttributeListEntry *ale;
356 size_t attr_len; 355 size_t attr_len;
357 const char *read_ptr; 356 const char *read_ptr;
357 size_t left = data_size;
358 358
359 al = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); 359 al = GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
360 if (data_size < sizeof(struct Attribute) + sizeof(struct 360 if (data_size < sizeof(struct Attribute))
361 GNUNET_RECLAIM_AttributeListEntry))
362 return al; 361 return al;
363 read_ptr = data; 362 read_ptr = data;
364 while (((data + data_size) - read_ptr) >= sizeof(struct Attribute)) 363 while (left >= sizeof(struct Attribute))
365 { 364 {
366 ale = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry); 365 ale = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry);
367 ale->attribute = 366 attr_len =
368 GNUNET_RECLAIM_attribute_deserialize (read_ptr, 367 GNUNET_RECLAIM_attribute_deserialize (read_ptr,
369 data_size - (read_ptr - data)); 368 left,
370 if (NULL == ale->attribute) 369 &ale->attribute);
370 if (-1 == attr_len)
371 { 371 {
372 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 372 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
373 "Failed to deserialize malformed attribute.\n"); 373 "Failed to deserialize malformed attribute.\n");
374 GNUNET_free (ale); 374 GNUNET_free (ale);
375 return al; 375 return al;
376 } 376 }
377 left -= attr_len;
377 GNUNET_CONTAINER_DLL_insert (al->list_head, al->list_tail, ale); 378 GNUNET_CONTAINER_DLL_insert (al->list_head, al->list_tail, ale);
378 attr_len = GNUNET_RECLAIM_attribute_serialize_get_size (ale->attribute);
379 read_ptr += attr_len; 379 read_ptr += attr_len;
380 } 380 }
381 return al; 381 return al;
@@ -503,17 +503,18 @@ GNUNET_RECLAIM_attribute_serialize (
503 * 503 *
504 * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller 504 * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller
505 */ 505 */
506struct GNUNET_RECLAIM_Attribute * 506ssize_t
507GNUNET_RECLAIM_attribute_deserialize (const char *data, size_t data_size) 507GNUNET_RECLAIM_attribute_deserialize (const char *data, size_t data_size,
508 struct GNUNET_RECLAIM_Attribute **attr)
508{ 509{
509 struct GNUNET_RECLAIM_Attribute *attr;
510 struct Attribute *attr_ser; 510 struct Attribute *attr_ser;
511 struct GNUNET_RECLAIM_Attribute *attribute;
511 size_t data_len; 512 size_t data_len;
512 size_t name_len; 513 size_t name_len;
513 char *write_ptr; 514 char *write_ptr;
514 515
515 if (data_size < sizeof(struct Attribute)) 516 if (data_size < sizeof(struct Attribute))
516 return NULL; 517 return -1;
517 518
518 attr_ser = (struct Attribute *) data; 519 attr_ser = (struct Attribute *) data;
519 data_len = ntohs (attr_ser->data_size); 520 data_len = ntohs (attr_ser->data_size);
@@ -522,25 +523,27 @@ GNUNET_RECLAIM_attribute_deserialize (const char *data, size_t data_size)
522 { 523 {
523 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 524 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
524 "Buffer too small to deserialize\n"); 525 "Buffer too small to deserialize\n");
525 return NULL; 526 return -1;
526 } 527 }
527 attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_Attribute) 528 attribute = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_Attribute)
528 + data_len + name_len + 1); 529 + data_len + name_len + 1);
529 attr->type = ntohs (attr_ser->attribute_type); 530 attribute->type = ntohs (attr_ser->attribute_type);
530 attr->flag = ntohl (attr_ser->attribute_flag); 531 attribute->flag = ntohl (attr_ser->attribute_flag);
531 attr->id = attr_ser->attribute_id; 532 attribute->id = attr_ser->attribute_id;
532 attr->attestation = attr_ser->attestation_id; 533 attribute->attestation = attr_ser->attestation_id;
533 attr->data_size = data_len; 534 attribute->data_size = data_len;
534 535
535 write_ptr = (char *) &attr[1]; 536 write_ptr = (char *) &attribute[1];
536 GNUNET_memcpy (write_ptr, &attr_ser[1], name_len); 537 GNUNET_memcpy (write_ptr, &attr_ser[1], name_len);
537 write_ptr[name_len] = '\0'; 538 write_ptr[name_len] = '\0';
538 attr->name = write_ptr; 539 attribute->name = write_ptr;
539 540
540 write_ptr += name_len + 1; 541 write_ptr += name_len + 1;
541 GNUNET_memcpy (write_ptr, (char *) &attr_ser[1] + name_len, attr->data_size); 542 GNUNET_memcpy (write_ptr, (char *) &attr_ser[1] + name_len,
542 attr->data = write_ptr; 543 attribute->data_size);
543 return attr; 544 *attr = attribute;
545 attribute->data = write_ptr;
546 return sizeof(struct Attribute) + data_len + name_len;
544} 547}
545 548
546 549