bneradt commented on code in PR #13584:
URL: https://github.com/apache/trafficserver/pull/13584#discussion_r4051029886


##########
src/api/InkAPI.cc:
##########
@@ -8395,17 +8395,38 @@ TSSslServerCertUpdate(const char *cert_path, const char 
*key_path)
       return TS_ERROR;
     }
 
-    // Extract common name
-    const int              pos              = 
X509_NAME_get_index_by_NID(X509_get_subject_name(cert.get()), NID_commonName, 
-1);
-    const X509_NAME_ENTRY *common_name      = 
X509_NAME_get_entry(X509_get_subject_name(cert.get()), pos);
-    const ASN1_STRING     *common_name_asn1 = 
X509_NAME_ENTRY_get_data(common_name);
-    char *common_name_str = reinterpret_cast<char *>(const_cast<unsigned char 
*>(ASN1_STRING_get0_data(common_name_asn1)));
-    if (ASN1_STRING_length(common_name_asn1) != 
static_cast<int>(strlen(common_name_str))) {
+    // Extract common name. X509_NAME_get_index_by_NID() returns -1 when the
+    // certificate has no commonName, and ASN1_STRING_get0_data() does not
+    // guarantee NUL termination. Check both conditions before using the data.
+    auto     *subject = X509_get_subject_name(cert.get());
+    const int pos     = X509_NAME_get_index_by_NID(subject, NID_commonName, 
-1);
+    if (pos < 0) {

Review Comment:
   [P2] Restore the no-CN regression test lost during the merge
   
   The current head no longer contains Server-Cert-Update-No-CN in 
tests/gold_tests/pluginTest/cert_update/cert_update.test.py. Comparing merge 
79120a68 with its first parent shows that the merge removed the entire run: 
certificate generation, the cert_update.server invocation, the additive 
ContainsExpression for rejection, ReturnCode = 0, and StillRunningAfter = ts. 
Thus the earlier review fixes were implemented but subsequently lost, and the 
current green AuTests no longer exercise this missing-CN crash regression. 
Please restore that run alongside the upstream test additions and verify it 
fails against the unpatched API and passes with this fix.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to