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


##########
plugins/stats_over_http/stats_over_http.cc:
##########
@@ -804,7 +804,17 @@ stats_origin(TSCont contp, TSEvent /* event ATS_UNUSED */, 
void *edata)
   my_state->encoding    = encoding_format_t::NONE;
   if (accept_encoding_field != TS_NULL_MLOC) {
     int         len = -1;
-    const char *str = TSMimeHdrFieldValueStringGet(reqp, hdr_loc, 
accept_encoding_field, -1, &len);
+    const char *mime_str = TSMimeHdrFieldValueStringGet(reqp, hdr_loc, 
accept_encoding_field, -1, &len);
+    char       *str = nullptr;
+
+    // Ensure str is null-terminated for strstr()
+    if (len > 0) {
+      str = TSstrndup(mime_str, len);

Review Comment:
   I like the std::string_view suggestion too. It would be nice to avoid the 
cost of the allocation and the need to free.
   
   Thank you for working on this.



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