diff options
author | Markus Teich <markus.teich@stusta.mhn.de> | 2016-11-22 00:29:27 +0100 |
---|---|---|
committer | Markus Teich <markus.teich@stusta.mhn.de> | 2016-11-22 00:29:27 +0100 |
commit | e9d1c7ba005dda68148651119234b0ab076302d1 (patch) | |
tree | 9b709be51ec7d80a85735ba6e1ac0a516378192e | |
parent | 1e83436746c87ae2671a5541a5e020ae61b49555 (diff) | |
download | libbrandt-e9d1c7ba005dda68148651119234b0ab076302d1.tar.gz libbrandt-e9d1c7ba005dda68148651119234b0ab076302d1.zip |
BRANDT_new() returns NULL on parameter failure
-rw-r--r-- | brandt.c | 12 | ||||
-rw-r--r-- | brandt.h | 3 |
2 files changed, 11 insertions, 4 deletions
@@ -181,17 +181,22 @@ BRANDT_new (BRANDT_CbResult result, | |||
181 | uint16_t m, | 181 | uint16_t m, |
182 | int outcome_public) | 182 | int outcome_public) |
183 | { | 183 | { |
184 | struct BRANDT_Auction *ret = GNUNET_new (struct BRANDT_Auction); | 184 | struct BRANDT_Auction *ret; |
185 | struct BRANDT_DescrP *desc = GNUNET_new (struct BRANDT_DescrP); | 185 | struct BRANDT_DescrP *desc; |
186 | struct GNUNET_HashContext *hc = GNUNET_CRYPTO_hash_context_start (); | 186 | struct GNUNET_HashContext *hc; |
187 | struct GNUNET_TIME_Relative until_start; | 187 | struct GNUNET_TIME_Relative until_start; |
188 | 188 | ||
189 | if (0 == num_prices) | ||
190 | return NULL; | ||
191 | |||
192 | desc = GNUNET_new (struct BRANDT_DescrP); | ||
189 | desc->time_start = GNUNET_TIME_absolute_hton (time_start); | 193 | desc->time_start = GNUNET_TIME_absolute_hton (time_start); |
190 | desc->time_round = GNUNET_TIME_relative_hton (time_round); | 194 | desc->time_round = GNUNET_TIME_relative_hton (time_round); |
191 | desc->description_len = htonl (description_len); | 195 | desc->description_len = htonl (description_len); |
192 | desc->k = htons (num_prices); | 196 | desc->k = htons (num_prices); |
193 | desc->m = htons (m); | 197 | desc->m = htons (m); |
194 | desc->outcome_public = htons (outcome_public); | 198 | desc->outcome_public = htons (outcome_public); |
199 | hc = GNUNET_CRYPTO_hash_context_start (); | ||
195 | GNUNET_CRYPTO_hash_context_read (hc, | 200 | GNUNET_CRYPTO_hash_context_read (hc, |
196 | &desc->time_start, | 201 | &desc->time_start, |
197 | sizeof (*desc) - sizeof (desc->hash)); | 202 | sizeof (*desc) - sizeof (desc->hash)); |
@@ -200,6 +205,7 @@ BRANDT_new (BRANDT_CbResult result, | |||
200 | description_len); | 205 | description_len); |
201 | GNUNET_CRYPTO_hash_context_finish (hc, &desc->hash); | 206 | GNUNET_CRYPTO_hash_context_finish (hc, &desc->hash); |
202 | 207 | ||
208 | ret = GNUNET_new (struct BRANDT_Auction); | ||
203 | ret->time_start = time_start; | 209 | ret->time_start = time_start; |
204 | ret->time_round = time_round; | 210 | ret->time_round = time_round; |
205 | ret->k = num_prices; | 211 | ret->k = num_prices; |
@@ -211,7 +211,8 @@ BRANDT_join (BRANDT_CbResult result, | |||
211 | * @param[in] outcome_public If 1, the auction winner and price will be public | 211 | * @param[in] outcome_public If 1, the auction winner and price will be public |
212 | * to all participants, if 0, this information will only be revealed to the | 212 | * to all participants, if 0, this information will only be revealed to the |
213 | * winner and the seller. | 213 | * winner and the seller. |
214 | * @return A pointer, which should only be remembered and passed to | 214 | * @return If invalid parameters are passed, NULL is returned. Else the return |
215 | * value is a pointer, which should only be remembered and passed to | ||
215 | * libbrandt functions when the client needs to refer to this auction. This is a | 216 | * libbrandt functions when the client needs to refer to this auction. This is a |
216 | * black-box pointer, do NOT dereference/change it or the data it points to! | 217 | * black-box pointer, do NOT dereference/change it or the data it points to! |
217 | */ | 218 | */ |