bneradt commented on code in PR #13518:
URL: https://github.com/apache/trafficserver/pull/13518#discussion_r3738562344
##########
src/api/InkAPI.cc:
##########
@@ -7775,24 +7776,31 @@ TSHttpTxnCloseAfterResponse(TSHttpTxn txnp, int
should_close)
}
// Parse a port descriptor for the proxy.config.http.server_ports descriptor
format.
-TSPortDescriptor
-TSPortDescriptorParse(const char *descriptor)
+TSReturnCode
+TSPortDescriptorParse(const char *descriptor, TSPortDescriptor *result)
{
- HttpProxyPort *port = new HttpProxyPort();
+ static_assert(sizeof(TSPortDescriptor) == sizeof(HttpProxyPort));
+ static_assert(alignof(TSPortDescriptor) == alignof(HttpProxyPort));
+ static_assert(std::is_trivially_destructible_v<HttpProxyPort>);
- if (descriptor && port->processOptions(descriptor)) {
- return reinterpret_cast<TSPortDescriptor>(port);
+ if (descriptor == nullptr || result == nullptr) {
+ return TS_ERROR;
}
- delete port;
- return nullptr;
+ auto *port = new (result->_get_internal()) HttpProxyPort();
+
+ return port->processOptions(descriptor) ? TS_SUCCESS : TS_ERROR;
}
TSReturnCode
-TSPortDescriptorAccept(TSPortDescriptor descp, TSCont contp)
+TSPortDescriptorAccept(const TSPortDescriptor *descp, TSCont contp)
{
+ if (descp == nullptr || contp == nullptr) {
+ return TS_ERROR;
+ }
+
Action *action = nullptr;
- HttpProxyPort *port = reinterpret_cast<HttpProxyPort
*>(descp);
+ const HttpProxyPort *port = std::launder(reinterpret_cast<const
HttpProxyPort *>(descp->_get_internal()));
NetProcessor::AcceptOptions net(make_net_accept_options(port, -1 /* nthreads
*/));
Review Comment:
Added validity tracking and port validation so unparsed or failed
descriptors return TS_ERROR; the test plugin now covers both cases.
--
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]