Skip to content

Commit

Permalink
fix: Fix a stack overflow triggered by small DHT packets.
Browse files Browse the repository at this point in the history
This isn't in production yet. It's in the new announce store code. The
problem was that a negative plain_len was converted to unsigned, which
made it a very large number.
  • Loading branch information
iphydf committed Apr 4, 2022
1 parent 6baabee commit fd54b46
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion toxcore/DHT.c
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ static int handle_data_search_response(void *object, const IP_Port *source,

const int32_t plain_len = (int32_t)length - (1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE);

if (plain_len < CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint64_t)) {
if (plain_len < (int32_t)(CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint64_t))) {
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion toxcore/announce.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ static int create_reply(Announcements *announce, const IP_Port *source,
{
const int plain_len = (int)length - (1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE);

if (plain_len < sizeof(uint64_t)) {
if (plain_len < (int)sizeof(uint64_t)) {
return -1;
}

Expand Down

0 comments on commit fd54b46

Please sign in to comment.