aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/gnunet_mq_lib.h5
-rw-r--r--src/util/mq.c14
2 files changed, 7 insertions, 12 deletions
diff --git a/src/include/gnunet_mq_lib.h b/src/include/gnunet_mq_lib.h
index 674077628..8da51d198 100644
--- a/src/include/gnunet_mq_lib.h
+++ b/src/include/gnunet_mq_lib.h
@@ -105,8 +105,9 @@
105 * @param base_size size of the message before the nested message's header appears 105 * @param base_size size of the message before the nested message's header appears
106 * @return pointer to the nested message, does not copy the message 106 * @return pointer to the nested message, does not copy the message
107 */ 107 */
108struct GNUNET_MessageHeader * 108const struct GNUNET_MessageHeader *
109GNUNET_MQ_extract_nested_mh_ (const struct GNUNET_MessageHeader *mh, uint16_t base_size); 109GNUNET_MQ_extract_nested_mh_ (const struct GNUNET_MessageHeader *mh,
110 uint16_t base_size);
110 111
111 112
112/** 113/**
diff --git a/src/util/mq.c b/src/util/mq.c
index 8098daac2..0d769b150 100644
--- a/src/util/mq.c
+++ b/src/util/mq.c
@@ -809,36 +809,30 @@ GNUNET_MQ_destroy (struct GNUNET_MQ_Handle *mq)
809} 809}
810 810
811 811
812struct GNUNET_MessageHeader * 812const struct GNUNET_MessageHeader *
813GNUNET_MQ_extract_nested_mh_ (const struct GNUNET_MessageHeader *mh, 813GNUNET_MQ_extract_nested_mh_ (const struct GNUNET_MessageHeader *mh,
814 uint16_t base_size) 814 uint16_t base_size)
815{ 815{
816 uint16_t whole_size; 816 uint16_t whole_size;
817 uint16_t nested_size; 817 uint16_t nested_size;
818 struct GNUNET_MessageHeader *nested_msg; 818 const struct GNUNET_MessageHeader *nested_msg;
819 819
820 whole_size = ntohs (mh->size); 820 whole_size = ntohs (mh->size);
821 GNUNET_assert (whole_size >= base_size); 821 GNUNET_assert (whole_size >= base_size);
822
823 nested_size = whole_size - base_size; 822 nested_size = whole_size - base_size;
824
825 if (0 == nested_size) 823 if (0 == nested_size)
826 return NULL; 824 return NULL;
827
828 if (nested_size < sizeof (struct GNUNET_MessageHeader)) 825 if (nested_size < sizeof (struct GNUNET_MessageHeader))
829 { 826 {
830 GNUNET_break_op (0); 827 GNUNET_break_op (0);
831 return NULL; 828 return NULL;
832 } 829 }
833 830 nested_msg = (const struct GNUNET_MessageHeader *) ((char *) mh + base_size);
834 nested_msg = (struct GNUNET_MessageHeader *) ((char *) mh + base_size);
835
836 if (ntohs (nested_msg->size) != nested_size) 831 if (ntohs (nested_msg->size) != nested_size)
837 { 832 {
838 GNUNET_break_op (0); 833 GNUNET_break_op (0);
839 nested_msg->size = htons (nested_size); 834 return NULL;
840 } 835 }
841
842 return nested_msg; 836 return nested_msg;
843} 837}
844 838