Skip to content

Commit 6fb7cb3

Browse files
authored
Merge pull request #10277 from kareem-wolfssl/zd21664_5
Add some missing length checks and fix length calculation.
2 parents a629ef1 + 768525c commit 6fb7cb3

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/internal.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33943,7 +33943,8 @@ int SendClientKeyExchange(WOLFSSL* ssl)
3394333943
/* Ensure the buffer is null-terminated. */
3394433944
ssl->arrays->client_identity[MAX_PSK_ID_LEN] = '\0';
3394533945
args->encSz = (word32)XSTRLEN(ssl->arrays->client_identity);
33946-
if (args->encSz > MAX_PSK_ID_LEN) {
33946+
if (args->encSz > MAX_PSK_ID_LEN ||
33947+
args->encSz > MAX_ENCRYPT_SZ) {
3394733948
ERROR_OUT(CLIENT_ID_ERROR, exit_scke);
3394833949
}
3394933950
XMEMCPY(args->encSecret, ssl->arrays->client_identity,
@@ -33974,6 +33975,9 @@ int SendClientKeyExchange(WOLFSSL* ssl)
3397433975
if (esSz > MAX_PSK_ID_LEN) {
3397533976
ERROR_OUT(CLIENT_ID_ERROR, exit_scke);
3397633977
}
33978+
if (esSz > MAX_ENCRYPT_SZ - (2 * OPAQUE16_LEN)) {
33979+
ERROR_OUT(CLIENT_ID_ERROR, exit_scke);
33980+
}
3397733981
/* CLIENT: Pre-shared Key for peer authentication. */
3397833982
ssl->options.peerAuthGood = 1;
3397933983

@@ -33988,7 +33992,7 @@ int SendClientKeyExchange(WOLFSSL* ssl)
3398833992
args->output += OPAQUE16_LEN;
3398933993
XMEMCPY(args->output, ssl->arrays->client_identity, esSz);
3399033994
args->output += esSz;
33991-
args->length = args->encSz - esSz - OPAQUE16_LEN;
33995+
args->length = args->encSz - esSz - (2 * OPAQUE16_LEN);
3399233996
args->encSz = esSz + OPAQUE16_LEN;
3399333997

3399433998
CHECK_RET(ret, AllocKey(ssl, DYNAMIC_TYPE_DH,
@@ -34025,6 +34029,9 @@ int SendClientKeyExchange(WOLFSSL* ssl)
3402534029
if (esSz > MAX_PSK_ID_LEN) {
3402634030
ERROR_OUT(CLIENT_ID_ERROR, exit_scke);
3402734031
}
34032+
if (esSz > MAX_ENCRYPT_SZ - OPAQUE16_LEN - OPAQUE8_LEN) {
34033+
ERROR_OUT(CLIENT_ID_ERROR, exit_scke);
34034+
}
3402834035
/* CLIENT: Pre-shared Key for peer authentication. */
3402934036
ssl->options.peerAuthGood = 1;
3403034037

@@ -34033,10 +34040,10 @@ int SendClientKeyExchange(WOLFSSL* ssl)
3403334040
args->output += OPAQUE16_LEN;
3403434041
XMEMCPY(args->output, ssl->arrays->client_identity, esSz);
3403534042
args->output += esSz;
34036-
args->encSz = esSz + OPAQUE16_LEN;
3403734043

34038-
/* length is used for public key size */
34039-
args->length = MAX_ENCRYPT_SZ;
34044+
args->length =
34045+
args->encSz - esSz - OPAQUE16_LEN - OPAQUE8_LEN;
34046+
args->encSz = esSz + OPAQUE16_LEN;
3404034047

3404134048
/* Create shared ECC key leaving room at the beginning
3404234049
* of buffer for size of shared key. */

src/tls13.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5375,7 +5375,8 @@ int DoTls13ServerHello(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
53755375

53765376
/* Session id */
53775377
args->sessIdSz = input[args->idx++];
5378-
if ((args->idx - args->begin) + args->sessIdSz > helloSz)
5378+
if (args->sessIdSz > ID_LEN || args->sessIdSz > RAN_LEN ||
5379+
((args->idx - args->begin) + args->sessIdSz > helloSz))
53795380
return BUFFER_ERROR;
53805381
args->sessId = input + args->idx;
53815382
args->idx += args->sessIdSz;

0 commit comments

Comments
 (0)