Skip to content

Commit

Permalink
Add asserts to check if packed nodes are correct size
Browse files Browse the repository at this point in the history
  • Loading branch information
JFreegman committed Sep 7, 2016
1 parent 334918f commit ea74d83
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions toxcore/DHT.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
#include "config.h"
#endif

#ifdef TOX_DEBUG
#include <assert.h>
#endif

#include "logger.h"

Expand Down Expand Up @@ -375,6 +373,9 @@ int pack_nodes(uint8_t *data, uint16_t length, const Node_format *nodes, uint16_

memcpy(data + packed_length, nodes[i].public_key, crypto_box_PUBLICKEYBYTES);
packed_length += crypto_box_PUBLICKEYBYTES;

uint32_t increment = ipp_size + crypto_box_PUBLICKEYBYTES;
assert(increment == PACKED_NODE_SIZE_IP4 || increment == PACKED_NODE_SIZE_IP6);
}

return packed_length;
Expand Down Expand Up @@ -408,6 +409,9 @@ int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed
memcpy(nodes[num].public_key, data + len_processed, crypto_box_PUBLICKEYBYTES);
len_processed += crypto_box_PUBLICKEYBYTES;
++num;

uint32_t increment = ipp_size + crypto_box_PUBLICKEYBYTES;
assert(increment == PACKED_NODE_SIZE_IP4 || increment == PACKED_NODE_SIZE_IP6);
}

if (processed_data_len) {
Expand Down

0 comments on commit ea74d83

Please sign in to comment.