Copilot commented on code in PR #12988:
URL: https://github.com/apache/trafficserver/pull/12988#discussion_r2954690426
##########
src/proxy/ReverseProxy.cc:
##########
@@ -68,22 +69,28 @@ int
init_reverse_proxy()
{
ink_assert(rewrite_table.load() == nullptr);
- reconfig_mutex = new_ProxyMutex();
- rewrite_table.store(new UrlRewrite());
+ reconfig_mutex = new_ProxyMutex();
+ auto *initial_table = new UrlRewrite();
- rewrite_table.load()->acquire();
+ initial_table->acquire();
Note("%s loading ...", ts::filename::REMAP);
- if (!rewrite_table.load()->load()) {
+ if (!initial_table->load()) {
Emergency("%s failed to load", ts::filename::REMAP);
} else {
Note("%s finished loading", ts::filename::REMAP);
}
+ rewrite_table.store(initial_table, std::memory_order_release);
+
RecRegisterConfigUpdateCb("proxy.config.url_remap.filename", url_rewrite_CB,
(void *)FILE_CHANGED);
RecRegisterConfigUpdateCb("proxy.config.proxy_name", url_rewrite_CB, (void
*)TSNAME_CHANGED);
RecRegisterConfigUpdateCb("proxy.config.reverse_proxy.enabled",
url_rewrite_CB, (void *)REVERSE_CHANGED);
RecRegisterConfigUpdateCb("proxy.config.http.referer_default_redirect",
url_rewrite_CB, (void *)HTTP_DEFAULT_REDIRECT_CHANGED);
+ if (initial_table->is_valid() && CacheProcessor::IsCacheEnabled() ==
CacheInitState::INITIALIZED) {
+ init_remap_volume_host_records();
+ }
+
Review Comment:
After `rewrite_table.store(initial_table, ...)`, the only reference that
keeps `initial_table` alive is the global lease; if a remap reload is
triggered, `reloadUrlRewrite()` will `exchange()` and `release()` the old
table, potentially deleting it on ET_TASK. The subsequent
`initial_table->is_valid()` dereference can become a use-after-free. To avoid
this, don’t dereference `initial_table` after publishing it unless you hold an
additional `acquire()`/`release()` pair, or re-load/acquire the table from
`rewrite_table` for the validity check; alternatively, perform the cache-ready
initialization before registering callbacks that can trigger reloads.
--
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]