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


##########
plugins/certifier/certifier.cc:
##########
@@ -367,12 +367,18 @@ 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());
+  X509_NAME *n = X509_NAME_dup(X509_get_subject_name(cert.get()));
   // Set common name field
   if (X509_NAME_add_entry_by_txt(n, "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;

Review Comment:
   `X509_NAME_dup()` can return `nullptr`, and on the 
`X509_NAME_add_entry_by_txt()` failure path the duplicated `X509_NAME` is 
currently leaked. This can lead to a crash (null deref) or a leak during 
certificate generation.



##########
src/tscore/X509HostnameValidator.cc:
##########
@@ -205,12 +205,12 @@ do_check_string(ASN1_STRING *a, int cmp_type, equal_fn 
equal, const unsigned cha
 {
   bool retval = false;
 
-  if (!a->data || !a->length || cmp_type != a->type) {
+  if (!ASN1_STRING_get0_data(a) || !ASN1_STRING_length(a) || cmp_type != 
ASN1_STRING_type(a)) {
     return false;
   }
-  retval = equal(a->data, a->length, b, blen);
+  retval = equal(ASN1_STRING_get0_data(a), ASN1_STRING_length(a), b, blen);
   if (retval && peername) {
-    *peername = ats_strndup((char *)a->data, a->length);
+    *peername = ats_strndup((char *)ASN1_STRING_get0_data(a), 
ASN1_STRING_length(a));
   }

Review Comment:
   `ats_strndup` expects a `const char *` input (via `_xstrdup(const char *, 
...)`), but this line casts the ASN1 data pointer to `char *`, dropping const. 
This is inconsistent with the nearby `asn1_strdup()` helper in `SSLUtils.cc` 
and may hide const-correctness issues.



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