@@ -33880,7 +33880,8 @@ int SendClientKeyExchange(WOLFSSL* ssl)
3388033880 /* Ensure the buffer is null-terminated. */
3388133881 ssl->arrays->client_identity[MAX_PSK_ID_LEN] = '\0';
3388233882 args->encSz = (word32)XSTRLEN(ssl->arrays->client_identity);
33883- if (args->encSz > MAX_PSK_ID_LEN) {
33883+ if (args->encSz > MAX_PSK_ID_LEN ||
33884+ args->encSz > MAX_ENCRYPT_SZ) {
3388433885 ERROR_OUT(CLIENT_ID_ERROR, exit_scke);
3388533886 }
3388633887 XMEMCPY(args->encSecret, ssl->arrays->client_identity,
@@ -33911,6 +33912,9 @@ int SendClientKeyExchange(WOLFSSL* ssl)
3391133912 if (esSz > MAX_PSK_ID_LEN) {
3391233913 ERROR_OUT(CLIENT_ID_ERROR, exit_scke);
3391333914 }
33915+ if (esSz > MAX_ENCRYPT_SZ - OPAQUE16_LEN) {
33916+ ERROR_OUT(CLIENT_ID_ERROR, exit_scke);
33917+ }
3391433918 /* CLIENT: Pre-shared Key for peer authentication. */
3391533919 ssl->options.peerAuthGood = 1;
3391633920
@@ -33962,6 +33966,9 @@ int SendClientKeyExchange(WOLFSSL* ssl)
3396233966 if (esSz > MAX_PSK_ID_LEN) {
3396333967 ERROR_OUT(CLIENT_ID_ERROR, exit_scke);
3396433968 }
33969+ if (esSz > MAX_ENCRYPT_SZ - OPAQUE16_LEN) {
33970+ ERROR_OUT(CLIENT_ID_ERROR, exit_scke);
33971+ }
3396533972 /* CLIENT: Pre-shared Key for peer authentication. */
3396633973 ssl->options.peerAuthGood = 1;
3396733974
@@ -33970,10 +33977,9 @@ int SendClientKeyExchange(WOLFSSL* ssl)
3397033977 args->output += OPAQUE16_LEN;
3397133978 XMEMCPY(args->output, ssl->arrays->client_identity, esSz);
3397233979 args->output += esSz;
33973- args->encSz = esSz + OPAQUE16_LEN;
3397433980
33975- /* length is used for public key size */
33976- args->length = MAX_ENCRYPT_SZ ;
33981+ args-> length = args->encSz - esSz - OPAQUE16_LEN;
33982+ args->encSz = esSz + OPAQUE16_LEN ;
3397733983
3397833984 /* Create shared ECC key leaving room at the beginning
3397933985 * of buffer for size of shared key. */
0 commit comments