diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-09-21 15:42:32 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-09-21 15:42:32 +0000 |
commit | c49bdc2e3f448a02d1031ab296ecc0805f4d8c61 (patch) | |
tree | 59721e3b978e310ac66dd45df11074f1fb4c3dca /src/mesh/mesh_tunnel_tree.c | |
parent | 7ed59b4939c09f65ce21f77fca3abcdd8061c570 (diff) | |
download | gnunet-c49bdc2e3f448a02d1031ab296ecc0805f4d8c61.tar.gz gnunet-c49bdc2e3f448a02d1031ab296ecc0805f4d8c61.zip |
Fixed use of uninitialized memory from realloc leading to segfaults and bus errors
Diffstat (limited to 'src/mesh/mesh_tunnel_tree.c')
-rw-r--r-- | src/mesh/mesh_tunnel_tree.c | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/src/mesh/mesh_tunnel_tree.c b/src/mesh/mesh_tunnel_tree.c index 30aaeadb3..185620125 100644 --- a/src/mesh/mesh_tunnel_tree.c +++ b/src/mesh/mesh_tunnel_tree.c | |||
@@ -293,8 +293,13 @@ tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p, | |||
293 | unsigned int i; | 293 | unsigned int i; |
294 | unsigned int j; | 294 | unsigned int j; |
295 | 295 | ||
296 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
297 | "test: Adding path [%u] towards peer %u to peer %u.\n", | ||
298 | p->length, | ||
299 | p->peers[p->length - 1], | ||
300 | t->me->peer); | ||
296 | GNUNET_assert(0 != p->length); | 301 | GNUNET_assert(0 != p->length); |
297 | n = t->root; | 302 | parent = n = t->root; |
298 | if (n->peer != p->peers[0]) | 303 | if (n->peer != p->peers[0]) |
299 | { | 304 | { |
300 | GNUNET_break (0); | 305 | GNUNET_break (0); |
@@ -309,13 +314,21 @@ tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p, | |||
309 | * - Length of the path is expected to be log N (size of whole network). | 314 | * - Length of the path is expected to be log N (size of whole network). |
310 | * - Each level of the tree is expected to have log n children (size of tree). | 315 | * - Each level of the tree is expected to have log n children (size of tree). |
311 | */ | 316 | */ |
312 | for (i = 0, me = -1; i < p->length; i++) | 317 | me = t->root->peer == myid ? 0 : -1; |
318 | for (i = 1; i < p->length; i++) | ||
313 | { | 319 | { |
320 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
321 | "test: Looking for peer %u.\n", | ||
322 | p->peers[i]); | ||
314 | parent = n; | 323 | parent = n; |
315 | if (p->peers[i] == myid) | 324 | if (p->peers[i] == myid) |
316 | me = i; | 325 | me = i; |
317 | for (j = 0; j < n->nchildren; j++) | 326 | for (j = 0; j < n->nchildren; j++) |
318 | { | 327 | { |
328 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
329 | "test: Child %u. is %u\n", | ||
330 | j, | ||
331 | n->children[j].peer); | ||
319 | if (n->children[j].peer == p->peers[i]) | 332 | if (n->children[j].peer == p->peers[i]) |
320 | { | 333 | { |
321 | n = &n->children[j]; | 334 | n = &n->children[j]; |
@@ -327,6 +340,8 @@ tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p, | |||
327 | if (parent == n) | 340 | if (parent == n) |
328 | break; | 341 | break; |
329 | } | 342 | } |
343 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
344 | "test: All childen visited.\n"); | ||
330 | if (-1 == me) | 345 | if (-1 == me) |
331 | { | 346 | { |
332 | /* New path deviates from tree before reaching us. What happened? */ | 347 | /* New path deviates from tree before reaching us. What happened? */ |
@@ -336,22 +351,38 @@ tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p, | |||
336 | /* Add the rest of the path as a branch from parent. */ | 351 | /* Add the rest of the path as a branch from parent. */ |
337 | while (i < p->length) | 352 | while (i < p->length) |
338 | { | 353 | { |
354 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
355 | "test: Adding peer %u, to %u.\n", | ||
356 | p->peers[i], | ||
357 | parent->peer); | ||
339 | parent->nchildren++; | 358 | parent->nchildren++; |
359 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
360 | "test: realloc %p, %u\n", parent->children, | ||
361 | parent->nchildren * | ||
362 | sizeof(struct MeshTunnelTreeNode)); | ||
340 | parent->children = GNUNET_realloc (parent->children, | 363 | parent->children = GNUNET_realloc (parent->children, |
341 | parent->nchildren * | 364 | parent->nchildren * |
342 | sizeof(struct MeshTunnelTreeNode)); | 365 | sizeof(struct MeshTunnelTreeNode)); |
366 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
367 | "test: done: %p\n", parent->children); | ||
343 | n = &parent->children[parent->nchildren - 1]; | 368 | n = &parent->children[parent->nchildren - 1]; |
344 | if (i == p->length - 1 && NULL != oldnode) | 369 | if (i == p->length - 1 && NULL != oldnode) |
345 | { | 370 | { |
371 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
372 | "test: Putting old note into place.\n"); | ||
346 | /* Assignation and free can be misleading, using explicit mempcy */ | 373 | /* Assignation and free can be misleading, using explicit mempcy */ |
347 | memcpy (n, oldnode, sizeof (struct MeshTunnelTreeNode)); | 374 | memcpy (n, oldnode, sizeof (struct MeshTunnelTreeNode)); |
348 | GNUNET_free (oldnode); | 375 | tree_node_destroy(oldnode); |
349 | } | 376 | } |
350 | else | 377 | else |
351 | { | 378 | { |
379 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
380 | "test: Creating new node.\n"); | ||
352 | n->t = t->t; | 381 | n->t = t->t; |
353 | n->status = MESH_PEER_RELAY; | 382 | n->status = MESH_PEER_RELAY; |
354 | n->peer = p->peers[i]; | 383 | n->peer = p->peers[i]; |
384 | n->nchildren = 0; | ||
385 | n->children = NULL; | ||
355 | } | 386 | } |
356 | n->parent = parent; | 387 | n->parent = parent; |
357 | i++; | 388 | i++; |
@@ -421,5 +452,4 @@ tree_destroy (struct MeshTunnelTree *t) | |||
421 | GNUNET_free(t->root); | 452 | GNUNET_free(t->root); |
422 | GNUNET_CONTAINER_multihashmap_iterate(t->first_hops, &iterate_free, NULL); | 453 | GNUNET_CONTAINER_multihashmap_iterate(t->first_hops, &iterate_free, NULL); |
423 | GNUNET_CONTAINER_multihashmap_destroy(t->first_hops); | 454 | GNUNET_CONTAINER_multihashmap_destroy(t->first_hops); |
424 | |||
425 | } \ No newline at end of file | 455 | } \ No newline at end of file |