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


##########
plugins/experimental/wasm/ats_context.cc:
##########
@@ -143,7 +143,7 @@ print_port(struct sockaddr const *ip, std::string *result)
     if (ip->sa_family == AF_INET) {
       const auto *s_sockaddr_in = reinterpret_cast<const struct sockaddr_in 
*>(ip);
       port                      = s_sockaddr_in->sin_port;
-    } else {
+    } else if (ip->sa_family == AF_INET6) {
       const auto *s_sockaddr_in6 = reinterpret_cast<const struct sockaddr_in6 
*>(ip);
       port                       = s_sockaddr_in6->sin6_port;

Review Comment:
   After adding the explicit `AF_INET6` check, `port` will remain 0 if 
`ip->sa_family` is neither `AF_INET` nor `AF_INET6`. This could silently 
produce incorrect results for unsupported address families. Consider adding an 
else clause that logs a warning or sets an error state to make unsupported 
families explicit.
   ```suggestion
         port                       = s_sockaddr_in6->sin6_port;
       } else {
         Dbg(dbg_ctl, "[%s] unsupported address family: %d", __FUNCTION__, 
static_cast<int>(ip->sa_family));
         *result = pv_empty;
         return;
   ```



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