@@ -694,26 +694,26 @@ build_ssl_verify_error(_sslmodulestate *state, PySSLSocket *sslsock, int ssl_err
694
694
/* verify code for cert validation error */
695
695
long verify_code_value = SSL_get_verify_result (sslsock -> ssl );
696
696
697
- const char * what =
698
- verify_code_value == X509_V_ERR_HOSTNAME_MISMATCH
699
- ? "Hostname"
700
- : verify_code_value == X509_V_ERR_IP_ADDRESS_MISMATCH
701
- ? "IP address"
702
- : NULL ;
703
-
704
- if (what == NULL ) {
705
- const char * s = X509_verify_cert_error_string (verify_code_value );
706
- verify = s == NULL ? Py_None : PyUnicode_FromString (s );
707
- }
708
- else {
709
- // The server's hostname is known to be an ASCII string.
710
- assert (PyUnicode_IS_ASCII (sslsock -> server_hostname ));
711
- const char * hostname = PyUnicode_AsUTF8 (sslsock -> server_hostname );
712
- verify = PyUnicode_FromFormat (
713
- "%s mismatch, certificate is not valid for '%s'." ,
714
- what , hostname
715
- );
697
+ switch (verify_code_value ) {
698
+ case X509_V_ERR_IP_ADDRESS_MISMATCH : _Py_FALLTHROUGH ;
699
+ case X509_V_ERR_HOSTNAME_MISMATCH : {
700
+ // The server's hostname is known to be an ASCII string.
701
+ assert (PyUnicode_IS_ASCII (sslsock -> server_hostname ));
702
+ const char * hostname = PyUnicode_AsUTF8 (sslsock -> server_hostname );
703
+ const char * fmt =
704
+ verify_code_value == X509_V_ERR_IP_ADDRESS_MISMATCH
705
+ ? "IP address mismatch, certificate is not valid for '%s'."
706
+ : "Hostname mismatch, certificate is not valid for '%s'." ;
707
+ verify = PyUnicode_FromFormat (fmt , hostname );
708
+ break ;
709
+ }
710
+ default : {
711
+ const char * s = X509_verify_cert_error_string (verify_code_value );
712
+ verify = s == NULL ? Py_None : PyUnicode_FromString (s );
713
+ break ;
714
+ }
716
715
}
716
+
717
717
if (verify == NULL ) {
718
718
goto fail ;
719
719
}
0 commit comments