aboutsummaryrefslogtreecommitdiff
path: root/src/gnsrecord/gnsrecord_serialization.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-05-20 23:40:20 +0200
committerChristian Grothoff <christian@grothoff.org>2018-05-20 23:40:20 +0200
commitd080cb1ed80a0e528b2b755ee48ca18cb670175e (patch)
treed8c0edab6035e4d38138b303566e972fbf8b8c5f /src/gnsrecord/gnsrecord_serialization.c
parent0a8c135eedab5213b31c21b3d4b800e5f0f6041f (diff)
downloadgnunet-d080cb1ed80a0e528b2b755ee48ca18cb670175e.tar.gz
gnunet-d080cb1ed80a0e528b2b755ee48ca18cb670175e.zip
check return values from GNSRECORD_record_serialize/size always
Diffstat (limited to 'src/gnsrecord/gnsrecord_serialization.c')
-rw-r--r--src/gnsrecord/gnsrecord_serialization.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/gnsrecord/gnsrecord_serialization.c b/src/gnsrecord/gnsrecord_serialization.c
index 6164fa3db..5a862f82f 100644
--- a/src/gnsrecord/gnsrecord_serialization.c
+++ b/src/gnsrecord/gnsrecord_serialization.c
@@ -78,9 +78,9 @@ GNUNET_NETWORK_STRUCT_END
78 * 78 *
79 * @param rd_count number of records in the rd array 79 * @param rd_count number of records in the rd array
80 * @param rd array of #GNUNET_GNSRECORD_Data with @a rd_count elements 80 * @param rd array of #GNUNET_GNSRECORD_Data with @a rd_count elements
81 * @return the required size to serialize 81 * @return the required size to serialize, -1 on error
82 */ 82 */
83size_t 83ssize_t
84GNUNET_GNSRECORD_records_get_size (unsigned int rd_count, 84GNUNET_GNSRECORD_records_get_size (unsigned int rd_count,
85 const struct GNUNET_GNSRECORD_Data *rd) 85 const struct GNUNET_GNSRECORD_Data *rd)
86{ 86{
@@ -89,10 +89,34 @@ GNUNET_GNSRECORD_records_get_size (unsigned int rd_count,
89 ret = sizeof (struct NetworkRecord) * rd_count; 89 ret = sizeof (struct NetworkRecord) * rd_count;
90 for (unsigned int i=0;i<rd_count;i++) 90 for (unsigned int i=0;i<rd_count;i++)
91 { 91 {
92 GNUNET_assert ((ret + rd[i].data_size) >= ret); 92 if ((ret + rd[i].data_size) < ret)
93 {
94 GNUNET_break (0);
95 return -1;
96 }
93 ret += rd[i].data_size; 97 ret += rd[i].data_size;
98#if GNUNET_EXTRA_LOGGING
99 {
100 char *str;
101
102 str = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
103 rd[i].data,
104 rd[i].data_size);
105 if (NULL == str)
106 {
107 GNUNET_break_op (0);
108 return -1;
109 }
110 GNUNET_free (str);
111 }
112#endif
94 } 113 }
95 return ret; 114 if (ret > SSIZE_MAX)
115 {
116 GNUNET_break (0);
117 return -1;
118 }
119 return (ssize_t) ret;
96} 120}
97 121
98 122
@@ -156,7 +180,7 @@ GNUNET_GNSRECORD_records_serialize (unsigned int rd_count,
156 if (NULL == str) 180 if (NULL == str)
157 { 181 {
158 GNUNET_break_op (0); 182 GNUNET_break_op (0);
159 return GNUNET_SYSERR; 183 return -1;
160 } 184 }
161 GNUNET_free (str); 185 GNUNET_free (str);
162 } 186 }