@@ -2394,9 +2394,10 @@ static int TLSX_SNI_Parse(WOLFSSL* ssl, const byte* input, word16 length,
23942394 else
23952395#endif
23962396 {
2397- matched = cacheOnly || (XSTRLEN(sni->data.host_name) == size &&
2398- XSTRNCMP(sni->data.host_name, (const char*)input + offset,
2399- size) == 0);
2397+ const char* hostName = (sni != NULL) ? sni->data.host_name : NULL;
2398+ matched = cacheOnly || (hostName != NULL &&
2399+ XSTRLEN(hostName) == size &&
2400+ XSTRNCMP(hostName, (const char*)input + offset, size) == 0);
24002401 }
24012402
24022403#if defined(WOLFSSL_TLS13) && defined(HAVE_ECH)
@@ -2415,7 +2416,8 @@ static int TLSX_SNI_Parse(WOLFSSL* ssl, const byte* input, word16 length,
24152416 }
24162417#endif
24172418
2418- if (matched || sni->options & WOLFSSL_SNI_ANSWER_ON_MISMATCH) {
2419+ if (matched ||
2420+ (sni != NULL && (sni->options & WOLFSSL_SNI_ANSWER_ON_MISMATCH))) {
24192421 int matchStat;
24202422 int r = TLSX_UseSNI(&ssl->extensions, type, input + offset, size,
24212423 ssl->heap);
@@ -2441,7 +2443,8 @@ static int TLSX_SNI_Parse(WOLFSSL* ssl, const byte* input, word16 length,
24412443 if (!cacheOnly)
24422444 TLSX_SetResponse(ssl, TLSX_SERVER_NAME);
24432445 }
2444- else if (!(sni->options & WOLFSSL_SNI_CONTINUE_ON_MISMATCH)) {
2446+ else if ((sni == NULL) ||
2447+ !(sni->options & WOLFSSL_SNI_CONTINUE_ON_MISMATCH)) {
24452448 SendAlert(ssl, alert_fatal, unrecognized_name);
24462449 WOLFSSL_ERROR_VERBOSE(UNKNOWN_SNI_HOST_NAME_E);
24472450 return UNKNOWN_SNI_HOST_NAME_E;
0 commit comments