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


##########
src/mgmt/rpc/handlers/hostdb/HostDB.cc:
##########
@@ -203,4 +212,18 @@ get_hostdb_status(std::string_view const & /* id 
ATS_UNUSED */, YAML::Node const
   }
   return resp;
 }
+
+swoc::Rv<YAML::Node>
+clear_hostdb(std::string_view const & /* id ATS_UNUSED */, YAML::Node const & 
/* params ATS_UNUSED */)
+{
+  swoc::Rv<YAML::Node> resp;
+  if (hostDBProcessor.cache()->refcountcache == nullptr) {
+    resp.errata().assign(std::error_code{errors::Codes::SERVER}).note("HostDB 
is not initialized");
+    return resp;
+  }

Review Comment:
   This handler dereferences `refcountcache` without the initialization check 
used by `get_hostdb_status`. If the restricted RPC is reached before HostDB 
startup has created its cache (or while startup is still in progress), 
`traffic_ctl hostdb clear` will crash the server instead of returning the 
documented RPC error. Reuse the same null check before calling `clear()`.



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