Copilot commented on code in PR #12679:
URL: https://github.com/apache/trafficserver/pull/12679#discussion_r2547525933
##########
src/api/InkAPI.cc:
##########
@@ -7188,6 +7188,28 @@ _memberp_to_generic(MgmtFloat *ptr, MgmtConverter const
*&conv)
return ptr;
}
+/// API conversion for @c char*, handles string assignment.
+inline void *
+_memberp_to_generic(char **ptr, MgmtConverter const *&conv)
+{
+ static const MgmtConverter converter{
+ nullptr, // load_int
+ nullptr, // store_int
+ nullptr, // load_float
+ nullptr, // store_float
+ [](const void *data) -> std::string_view {
+ const char *str = *static_cast<const char *const *>(data);
+ return str ? std::string_view(str) : std::string_view();
+ }, // load_string
+ [](void *data, std::string_view value) -> void {
+ *static_cast<char **>(data) = const_cast<char *>(value.data());
Review Comment:
The store_string lambda directly assigns the string_view's data pointer
without ensuring the string outlives the pointer. This can cause use-after-free
if the string_view is backed by temporary storage. The value should be
duplicated using ats_strdup or handled through TSHttpTxnConfigStringSet's
default path which performs proper memory management. Consider removing the
custom char** converter and adding
TS_CONFIG_HTTP_CACHE_TARGETED_CACHE_CONTROL_HEADERS to the
TSHttpTxnConfigStringSet switch statement instead.
```suggestion
char **p = static_cast<char **>(data);
if (*p) {
ats_free(*p);
}
*p = ats_strdup(value.data(), value.size());
```
--
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]