From 2829c62ef9f0f79fc6aa6ea0da7381d12591ef2f Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Sun, 27 Mar 2022 19:14:40 -0700 Subject: [PATCH] Fix error handling after calling X509_NAME_get_index_by_NID This should fix #376 --- ixwebsocket/IXSocketOpenSSL.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ixwebsocket/IXSocketOpenSSL.cpp b/ixwebsocket/IXSocketOpenSSL.cpp index 0028707e..96ed860d 100644 --- a/ixwebsocket/IXSocketOpenSSL.cpp +++ b/ixwebsocket/IXSocketOpenSSL.cpp @@ -339,12 +339,12 @@ namespace ix { int cn_pos = X509_NAME_get_index_by_NID( X509_get_subject_name((X509*) server_cert), NID_commonName, -1); - if (cn_pos) + if (cn_pos >= 0) { X509_NAME_ENTRY* cn_entry = X509_NAME_get_entry(X509_get_subject_name((X509*) server_cert), cn_pos); - if (cn_entry) + if (cn_entry != nullptr) { ASN1_STRING* cn_asn1 = X509_NAME_ENTRY_get_data(cn_entry); char* cn = (char*) ASN1_STRING_data(cn_asn1);