fix ech config parsing to handle 1 byte public name len

This commit is contained in:
John Bland
2023-09-26 20:41:33 -04:00
parent a5963b4b9f
commit 36623f0869

View File

@ -652,7 +652,7 @@ int wolfSSL_SetEchConfigsBase64(WOLFSSL* ssl, char* echConfigs64,
/* set the ech config from a raw buffer, this is the format ech configs are /* set the ech config from a raw buffer, this is the format ech configs are
* sent using retry_configs from the ech server */ * sent using retry_configs from the ech server */
int wolfSSL_SetEchConfigs(WOLFSSL* ssl, const byte* echConfigs, int wolfSSL_SetEchConfigs(WOLFSSL* ssl, const byte* echConfigs,
word32 echConfigsLen) word32 echConfigsLen)
{ {
int ret = 0; int ret = 0;
int i; int i;
@ -779,16 +779,17 @@ int wolfSSL_SetEchConfigs(WOLFSSL* ssl, const byte* echConfigs,
&workingConfig->cipherSuites[j].aeadId); &workingConfig->cipherSuites[j].aeadId);
} }
echConfig += cipherSuitesLen; echConfig += cipherSuitesLen;
/* ignore the maximum name length */
echConfig++;
/* publicNameLen */ /* publicNameLen */
ato16(echConfig, &publicNameLen); publicNameLen = *(echConfig);
workingConfig->publicName = (char*)XMALLOC(publicNameLen + 1, workingConfig->publicName = (char*)XMALLOC(publicNameLen + 1,
ssl->heap, DYNAMIC_TYPE_TMP_BUFFER); ssl->heap, DYNAMIC_TYPE_TMP_BUFFER);
if (workingConfig->publicName == NULL) { if (workingConfig->publicName == NULL) {
ret = MEMORY_E; ret = MEMORY_E;
break; break;
} }
echConfig++;
echConfig += 2;
/* publicName */ /* publicName */
XMEMCPY(workingConfig->publicName, echConfig, publicNameLen); XMEMCPY(workingConfig->publicName, echConfig, publicNameLen);
/* null terminated */ /* null terminated */
@ -965,9 +966,13 @@ int GetEchConfig(WOLFSSL_EchConfig* config, byte* output, word32* outputLen)
output += 2; output += 2;
} }
/* set maximum name length to 0 */
*output = 0;
output++;
/* publicName len */ /* publicName len */
c16toa(XSTRLEN(config->publicName), output); *output = XSTRLEN(config->publicName);
output += 2; output++;
/* publicName */ /* publicName */
XMEMCPY(output, config->publicName, XMEMCPY(output, config->publicName,