JosiahWI commented on code in PR #13476:
URL: https://github.com/apache/trafficserver/pull/13476#discussion_r3713857287


##########
plugins/certifier/certifier.cc:
##########
@@ -401,12 +402,20 @@ mkcrt(const std::string &commonName, int serial)
   X509_gmtime_adj(X509_get_notAfter(cert.get()), static_cast<long>(3650) * 24 
* 3600);
 
   // Get handle to subject name
-  X509_NAME *n = X509_get_subject_name(cert.get());
+  scoped_X509_NAME n{X509_NAME_dup(X509_get_subject_name(cert.get())), 
X509_NAME_free};
+  if (n == nullptr) {
+    TSError("[%s] %s: failed to duplicate certificate subject", PLUGIN_NAME, 
__func__);
+    return nullptr;
+  }

Review Comment:
   Error checking added in this patch. Very good! Thanks @maskit !



##########
plugins/certifier/certifier.cc:
##########
@@ -401,12 +402,20 @@ mkcrt(const std::string &commonName, int serial)
   X509_gmtime_adj(X509_get_notAfter(cert.get()), static_cast<long>(3650) * 24 
* 3600);
 
   // Get handle to subject name
-  X509_NAME *n = X509_get_subject_name(cert.get());
+  scoped_X509_NAME n{X509_NAME_dup(X509_get_subject_name(cert.get())), 
X509_NAME_free};
+  if (n == nullptr) {
+    TSError("[%s] %s: failed to duplicate certificate subject", PLUGIN_NAME, 
__func__);
+    return nullptr;
+  }
   // Set common name field
-  if (X509_NAME_add_entry_by_txt(n, "CN", MBSTRING_ASC, (unsigned char 
*)commonName.c_str(), -1, -1, 0) != 1) {
+  if (X509_NAME_add_entry_by_txt(n.get(), "CN", MBSTRING_ASC, (unsigned char 
*)commonName.c_str(), -1, -1, 0) != 1) {
     TSError("[%s] %s: failed to add certificate subject CN", PLUGIN_NAME, 
__func__);
     return nullptr;
   }
+  if (X509_set_subject_name(cert.get(), n.get()) != 1) {
+    TSError("[%s] %s: failed to set certificate subject", PLUGIN_NAME, 
__func__);
+    return nullptr;
+  }

Review Comment:
   What is the purpose of this added logic?



##########
example/plugins/c-api/verify_cert/verify_cert.cc:
##########
@@ -37,7 +37,7 @@ namespace
 DbgCtl dbg_ctl{PLUGIN_NAME};
 
 static void
-debug_certificate(const char *msg, X509_NAME *name)
+debug_certificate(const char *msg, const X509_NAME *name)

Review Comment:
   This is correct! The parameter can be `const` because `X509_NAME_print_ex` 
takes a const pointer to the name since OpenSSL 1.1.1.



-- 
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