Skip to content

Commit 2981f65

Browse files
authored
Merge pull request shadowsocks#3023 from shadowsocks/fix/aead-decrypt-chunk-compaction
Fix unbounded buffer growth in aead_decrypt chunk reassembly
2 parents 31731ba + ff44361 commit 2981f65

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/aead.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,9 +650,12 @@ aead_decrypt(buffer_t *ciphertext, cipher_ctx_t *cipher_ctx, size_t capacity)
650650
chunk->idx = 0;
651651
ciphertext->len = 0;
652652
} else {
653-
brealloc(chunk,
654-
chunk->idx + chunk->len + ciphertext->len, capacity);
655-
memcpy(chunk->data + chunk->idx + chunk->len,
653+
if (chunk->idx > 0) {
654+
memmove(chunk->data, chunk->data + chunk->idx, chunk->len);
655+
chunk->idx = 0;
656+
}
657+
brealloc(chunk, chunk->len + ciphertext->len, capacity);
658+
memcpy(chunk->data + chunk->len,
656659
ciphertext->data, ciphertext->len);
657660
chunk->len += ciphertext->len;
658661
}

0 commit comments

Comments
 (0)