Skip to content

Commit ae622ff

Browse files
committed
schannel: x509: F-047: fix
1 parent 72edd1d commit ae622ff

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

lib/tls/schannel/schannel-ssl.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -975,11 +975,22 @@ lws_tls_client_confirm_peer_cert(struct lws *wsi, char *ebuf, size_t ebuf_len)
975975
polHttps.cbStruct = sizeof(HTTPSPolicyCallbackData);
976976
polHttps.dwAuthType = AUTHTYPE_SERVER;
977977

978-
/* Convert stored hostname to WCHAR for validation */
978+
/*
979+
* Convert stored hostname to WCHAR for validation. If the
980+
* hostname is not valid UTF-8 (or does not fit), we must fail
981+
* closed: leaving pwszServerName NULL makes the SSL chain
982+
* policy skip name matching entirely (F-047).
983+
*/
979984
WCHAR wszServerName[128];
980-
if (MultiByteToWideChar(CP_UTF8, 0, conn->hostname, -1, wszServerName, LWS_ARRAY_SIZE(wszServerName))) {
981-
polHttps.pwszServerName = wszServerName;
985+
if (!MultiByteToWideChar(CP_UTF8, 0, conn->hostname, -1,
986+
wszServerName,
987+
LWS_ARRAY_SIZE(wszServerName))) {
988+
lws_snprintf(ebuf, ebuf_len,
989+
"hostname not valid UTF-8, refusing to"
990+
" skip peer name check");
991+
goto bail;
982992
}
993+
polHttps.pwszServerName = wszServerName;
983994

984995
CERT_CHAIN_POLICY_PARA PolicyPara;
985996
memset(&PolicyPara, 0, sizeof(PolicyPara));
@@ -1025,6 +1036,7 @@ lws_tls_client_confirm_peer_cert(struct lws *wsi, char *ebuf, size_t ebuf_len)
10251036
}
10261037
}
10271038

1039+
bail:
10281040
CertFreeCertificateChain(pChainContext);
10291041
}
10301042

0 commit comments

Comments
 (0)