Limit the max payload length to 0x3FFF

This commit is contained in:
Max Lv
2017-01-30 19:03:41 +08:00
parent 9c7add71dd
commit c89f5f3f3f
+5 -1
View File
@@ -54,6 +54,7 @@
#endif
#define CHUNK_SIZE_LEN 2
#define CHUNK_SIZE_MASK 0X3FFF
/*
* This is SIP004 proposed by @Mygod, the design of TCP chunk is from @breakwa11 and
@@ -499,10 +500,12 @@ static int
aead_chunk_encrypt(cipher_ctx_t *ctx, uint8_t *p, uint8_t *c, uint8_t *n,
uint16_t plen, size_t nlen, size_t tlen)
{
assert(plen + tlen < CHUNK_SIZE_MASK);
int err;
size_t clen;
uint8_t len_buf[CHUNK_SIZE_LEN];
uint16_t t = ntohs(plen + tlen);
uint16_t t = ntohs((plen + tlen) & CHUNK_SIZE_MASK);
memcpy(len_buf, &t, CHUNK_SIZE_LEN);
clen = CHUNK_SIZE_LEN + tlen;
@@ -597,6 +600,7 @@ aead_chunk_decrypt(cipher_ctx_t *ctx, uint8_t *p, uint8_t *c, uint8_t *n,
assert(*plen == CHUNK_SIZE_LEN);
mlen = htons(*(uint16_t *)len_buf);
mlen = mlen & CHUNK_SIZE_MASK;
size_t chunk_len = tlen + CHUNK_SIZE_LEN + mlen;