Skip to content

Commit

Permalink
Fix two bugs with our speck API usage
Browse files Browse the repository at this point in the history
The speck_init() function will always allocate its own buffer, so dont
allocate one as that leads to memory leaks.

In some configuations, the speck_init will not use the standard malloc()
and this may cause issues when trying to use free() on the returned ctx.

This issue definitely occurs with the Windows builds and lead to the
supernode aborting with "exception code 0xc0000374 (Heap Corruption)"

(Ref n42n#30)
  • Loading branch information
hamishcoleman committed May 15, 2024
1 parent ea26e1f commit 51eb3d7
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ int calculate_dynamic_key (uint8_t out_key[N2N_AUTH_CHALLENGE_SIZE],

memxor(key, tmp, N2N_AUTH_CHALLENGE_SIZE);

ctx = (speck_context_t*)calloc(1, sizeof(speck_context_t));
speck_init((speck_context_t**)&ctx, key, 128);

pearson_hash_128(tmp, (uint8_t*)&key_time, sizeof(key_time));
Expand All @@ -181,7 +180,7 @@ int calculate_dynamic_key (uint8_t out_key[N2N_AUTH_CHALLENGE_SIZE],

speck_128_encrypt(out_key, ctx);

free(ctx);
speck_deinit(ctx);

return 0;
}

0 comments on commit 51eb3d7

Please sign in to comment.