diff options
author | LRN <lrn1986@gmail.com> | 2014-01-17 06:39:51 +0000 |
---|---|---|
committer | LRN <lrn1986@gmail.com> | 2014-01-17 06:39:51 +0000 |
commit | c7b19febcf921f90b7eacf234b13049f56f38677 (patch) | |
tree | 29f192e4590c15d7c16d41d3979380577475f84a /src/scalarproduct/gnunet-scalarproduct.c | |
parent | 60032ac44d9c2baf6d26e4c8d337d5541ddfda30 (diff) | |
download | gnunet-c7b19febcf921f90b7eacf234b13049f56f38677.tar.gz gnunet-c7b19febcf921f90b7eacf234b13049f56f38677.zip |
Fix scalarproduct argument parsing (don't scan past 0-terminator)
Diffstat (limited to 'src/scalarproduct/gnunet-scalarproduct.c')
-rw-r--r-- | src/scalarproduct/gnunet-scalarproduct.c | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/src/scalarproduct/gnunet-scalarproduct.c b/src/scalarproduct/gnunet-scalarproduct.c index 486bca395..a93902640 100644 --- a/src/scalarproduct/gnunet-scalarproduct.c +++ b/src/scalarproduct/gnunet-scalarproduct.c | |||
@@ -257,18 +257,20 @@ run (void *cls, | |||
257 | /* Count input_elements_peer1, and put in elements_peer1 array */ | 257 | /* Count input_elements_peer1, and put in elements_peer1 array */ |
258 | do | 258 | do |
259 | { | 259 | { |
260 | // get the length of the current element and replace , with null | 260 | // get the length of the current element |
261 | for (end = begin; *end && *end != ','; end++); | 261 | for (end = begin; *end && *end != ','; end++); |
262 | 262 | ||
263 | if (1 == sscanf (begin, "%" SCNd32 ",", &element)) | 263 | if (0 == *begin) |
264 | { | 264 | { |
265 | //element in the middle | 265 | break; |
266 | element_count++; | ||
267 | begin = end + 1; | ||
268 | } | 266 | } |
269 | else if (0 == *begin) | 267 | else if (1 == sscanf (begin, "%" SCNd32 ",", &element)) |
270 | { | 268 | { |
271 | break; | 269 | //element in the middle |
270 | element_count++; | ||
271 | begin = end; | ||
272 | if (',' == *end) | ||
273 | begin += 1; | ||
272 | } | 274 | } |
273 | else | 275 | else |
274 | { | 276 | { |
@@ -291,18 +293,26 @@ run (void *cls, | |||
291 | /* Read input_elements_peer1, and put in elements_peer1 array */ | 293 | /* Read input_elements_peer1, and put in elements_peer1 array */ |
292 | do | 294 | do |
293 | { | 295 | { |
294 | // get the length of the current element and replace , with null | 296 | // get the length of the current element |
295 | for (end = begin; *end && *end != ','; end++); | 297 | for (end = begin; *end && *end != ','; end++); |
296 | 298 | ||
297 | if (1 == sscanf (begin, "%" SCNd32 ",", &elements[element_count])) | 299 | if (0 == *begin) |
300 | { | ||
301 | break; | ||
302 | } | ||
303 | else if (1 == sscanf (begin, "%" SCNd32 ",", &elements[element_count])) | ||
298 | { | 304 | { |
299 | //element in the middle | 305 | //element in the middle |
300 | element_count++; | 306 | element_count++; |
301 | begin = end + 1; | 307 | begin = end; |
308 | if (',' == *end) | ||
309 | begin += 1; | ||
302 | } | 310 | } |
303 | else if (0 == *begin) | 311 | else |
304 | { | 312 | { |
305 | break; | 313 | LOG (GNUNET_ERROR_TYPE_ERROR, |
314 | _ ("Could not convert `%s' to int32_t.\n"), begin); | ||
315 | return; | ||
306 | } | 316 | } |
307 | } | 317 | } |
308 | while (1); | 318 | while (1); |