Merge pull request #2817 from cesanta/chachachan

fix stack trashing
This commit is contained in:
Sergey Lyubka 2024-07-04 05:57:06 +01:00 committed by GitHub
commit 1c3b6ad59b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View File

@ -9892,9 +9892,14 @@ static int mg_tls_recv_record(struct mg_connection *c) {
nonce[10] ^= (uint8_t) ((seq >> 8) & 255U);
nonce[11] ^= (uint8_t) ((seq) & 255U);
#if CHACHA20
uint8_t dec[8192];
uint8_t *dec = (uint8_t *) malloc(msgsz);
if (dec == NULL) {
mg_error(c, "TLS OOM");
return -1;
}
size_t n = mg_chacha20_poly1305_decrypt(dec, key, nonce, msg, msgsz);
memmove(msg, dec, n);
free(dec);
#else
mg_aes_gcm_decrypt(msg, msg, msgsz - 16, key, 16, nonce, sizeof(nonce));
#endif

View File

@ -456,9 +456,14 @@ static int mg_tls_recv_record(struct mg_connection *c) {
nonce[10] ^= (uint8_t) ((seq >> 8) & 255U);
nonce[11] ^= (uint8_t) ((seq) & 255U);
#if CHACHA20
uint8_t dec[8192];
uint8_t *dec = (uint8_t *) malloc(msgsz);
if (dec == NULL) {
mg_error(c, "TLS OOM");
return -1;
}
size_t n = mg_chacha20_poly1305_decrypt(dec, key, nonce, msg, msgsz);
memmove(msg, dec, n);
free(dec);
#else
mg_aes_gcm_decrypt(msg, msg, msgsz - 16, key, 16, nonce, sizeof(nonce));
#endif