You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@trafficserver.apache.org by "Copilot (via GitHub)" <gi...@apache.org> on 2026/02/20 07:55:24 UTC
Re: [PR] synserver accept assertion to log event details before aborting [trafficserver]
Copilot commented on code in PR #12903:
URL: https://github.com/apache/trafficserver/pull/12903#discussion_r2831891904
##########
src/api/InkAPITest.cc:
##########
@@ -892,7 +892,14 @@ synserver_delete(SocketServer *s)
static int
synserver_vc_refuse(TSCont contp, TSEvent event, void *data)
{
- TSAssert((event == TS_EVENT_NET_ACCEPT) || (event == TS_EVENT_NET_ACCEPT_FAILED));
+ if (event != TS_EVENT_NET_ACCEPT && event != TS_EVENT_NET_ACCEPT_FAILED) {
+ int err = -static_cast<int>(reinterpret_cast<intptr_t>(data));
+ if (err > 0 && err < 256) {
Review Comment:
`data` is treated as a negated errno via `reinterpret_cast<intptr_t>(data)` and then narrowed to `int` before negation. If `data` is actually a pointer (plausible for many events), the narrowing conversion can wrap/lose bits and accidentally produce a small positive value (e.g., <256), leading to a misleading `strerror()` message. Consider keeping the value as `intptr_t`, first checking it’s in a plausible negated-errno range (e.g., `< 0` and `>= -4095`), and only then converting to an `int` errno; otherwise log the raw integer/pointer value.
```suggestion
intptr_t data_val = reinterpret_cast<intptr_t>(data);
if (data_val < 0 && data_val >= -4095) {
int err = static_cast<int>(-data_val);
```
##########
src/api/InkAPITest.cc:
##########
@@ -913,7 +920,14 @@ synserver_vc_refuse(TSCont contp, TSEvent event, void *data)
static int
synserver_vc_accept(TSCont contp, TSEvent event, void *data)
{
- TSAssert((event == TS_EVENT_NET_ACCEPT) || (event == TS_EVENT_NET_ACCEPT_FAILED));
+ if (event != TS_EVENT_NET_ACCEPT && event != TS_EVENT_NET_ACCEPT_FAILED) {
+ int err = -static_cast<int>(reinterpret_cast<intptr_t>(data));
+ if (err > 0 && err < 256) {
+ ink_abort("synserver_vc_accept: unexpected event %d, accept errno: %s (%d)", event, strerror(err), err);
+ } else {
Review Comment:
Same issue here as in `synserver_vc_refuse`: narrowing `reinterpret_cast<intptr_t>(data)` to `int` before validating it can mis-identify arbitrary pointers as small errno values and print an incorrect `strerror()` string. To keep the diagnostics trustworthy, validate `data` as a plausible negated errno in `intptr_t` space (e.g., `<0` and within a small bound like 4095) before converting/logging it as an errno; otherwise log the raw value.
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org