Skip to content

Commit b7c3bbf

Browse files
committed
Fixes to size checking
In `quic_record_transfer()`, the unsigned subtraction `qr->end - qr->start` could wrap around if `end < start`, and the subsequent `len <= 0` check was ineffective on a `word32`. Move the comparison before the subtraction so the function returns `0` safely. In `GetEchConfig()`, `XSTRLEN(config->publicName)` was assigned to a single byte, silently truncating names longer than 255 characters while `XMEMCPY` still copied the full string. Add a 255-byte length validation in both `wolfSSL_CTX_GenerateEchConfig()` and `GetEchConfig()`, and cache the length in a local variable to avoid redundant `XSTRLEN` calls.
1 parent add60da commit b7c3bbf

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

src/quic.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,14 @@ static word32 add_rec_header(byte* output, word32 length, byte type)
184184

185185
static sword32 quic_record_transfer(QuicRecord* qr, byte* buf, word32 sz)
186186
{
187-
word32 len = qr->end - qr->start;
187+
word32 len;
188188
word32 offset = 0;
189189
word32 rlen;
190190

191-
if (len <= 0) {
191+
if (qr->end <= qr->start) {
192192
return 0;
193193
}
194+
len = qr->end - qr->start;
194195

195196
/* We check if the buf is at least RECORD_HEADER_SZ */
196197
if (sz < RECORD_HEADER_SZ) {

src/ssl_ech.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ int wolfSSL_CTX_GenerateEchConfig(WOLFSSL_CTX* ctx, const char* publicName,
4848
if (ctx == NULL || publicName == NULL)
4949
return BAD_FUNC_ARG;
5050

51+
/* ECH spec limits public_name to 255 bytes (1-byte length prefix) */
52+
if (XSTRLEN(publicName) > 255)
53+
return BAD_FUNC_ARG;
54+
5155
WC_ALLOC_VAR_EX(rng, WC_RNG, 1, ctx->heap, DYNAMIC_TYPE_RNG,
5256
return MEMORY_E);
5357
ret = wc_InitRng(rng);
@@ -313,10 +317,16 @@ int GetEchConfig(WOLFSSL_EchConfig* config, byte* output, word32* outputLen)
313317
{
314318
int i;
315319
word16 totalLen = 0;
320+
word16 publicNameLen;
316321

317322
if (config == NULL || (output == NULL && outputLen == NULL))
318323
return BAD_FUNC_ARG;
319324

325+
/* ECH spec limits public_name to 255 bytes (1-byte length prefix) */
326+
if (config->publicName == NULL || XSTRLEN(config->publicName) > 255)
327+
return BAD_FUNC_ARG;
328+
publicNameLen = (word16)XSTRLEN(config->publicName);
329+
320330
/* 2 for version */
321331
totalLen += 2;
322332
/* 2 for length */
@@ -355,7 +365,7 @@ int GetEchConfig(WOLFSSL_EchConfig* config, byte* output, word32* outputLen)
355365
totalLen += 2;
356366

357367
/* public name */
358-
totalLen += XSTRLEN(config->publicName);
368+
totalLen += publicNameLen;
359369
/* trailing zeros */
360370
totalLen += 2;
361371

@@ -435,13 +445,12 @@ int GetEchConfig(WOLFSSL_EchConfig* config, byte* output, word32* outputLen)
435445
output++;
436446

437447
/* publicName len */
438-
*output = XSTRLEN(config->publicName);
448+
*output = (byte)publicNameLen;
439449
output++;
440450

441451
/* publicName */
442-
XMEMCPY(output, config->publicName,
443-
XSTRLEN(config->publicName));
444-
output += XSTRLEN(config->publicName);
452+
XMEMCPY(output, config->publicName, publicNameLen);
453+
output += publicNameLen;
445454

446455
/* terminating zeros */
447456
c16toa(0, output);

0 commit comments

Comments
 (0)