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


##########
src/proxy/IPAllow.cc:
##########
@@ -243,6 +243,7 @@ IpAllow::IpAllow(const char *ip_allow_config_var, const 
char *ip_categories_conf
       std::string_view subject_sv = subjects_sv.substr(s, e);

Review Comment:
   `subjects_sv.substr(s, e)` is using `e` (the comma position) as the 
substring length. For 3+ comma-separated subjects this causes the middle token 
to include extra characters (e.g., "PROXY,PLUG...") and won’t match the 
expected values, leading to incorrect subject parsing. Use `substr(s, e == npos 
? npos : e - s)` (or equivalent) so the extracted token length is correct.
   ```suggestion
         auto len                    = (e == std::string_view::npos) ? 
std::string_view::npos : (e - s);
         std::string_view subject_sv = subjects_sv.substr(s, len);
   ```



##########
plugins/slice/server.cc:
##########
@@ -463,14 +464,19 @@ handleNextServerHeader(Data *const data)
       data->m_blockstate = BlockState::PendingRef;
 
       // interior headers for new identifier reference
+      etaglen         = std::min(etaglen, 
static_cast<int>(sizeof(data->m_etag) - 1));
       data->m_etaglen = etaglen;
       if (0 < etaglen) {
-        strncpy(data->m_etag, etag, etaglen);
+        memcpy(data->m_etag, etag, etaglen);
       }
+      data->m_etag[etaglen] = '\0';
+
+      lastmodifiedlen         = std::min(lastmodifiedlen, 
static_cast<int>(sizeof(data->m_lastmodified) - 1));
       data->m_lastmodifiedlen = lastmodifiedlen;
       if (0 < lastmodifiedlen) {
-        strncpy(data->m_lastmodified, lastmodified, lastmodifiedlen);
+        memcpy(data->m_lastmodified, lastmodified, lastmodifiedlen);
       }
+      data->m_lastmodified[lastmodifiedlen] = '\0';

Review Comment:
   The new truncation + explicit null-termination for ETag/Last-Modified 
addresses a memory-safety issue, but it’s hard to see this path covered by 
existing slice tests. Consider adding a slice gold test that returns an 
unusually long ETag/Last-Modified value (near the buffer size) to exercise the 
truncation and null-termination behavior.



##########
src/proxy/IPAllow.cc:
##########
@@ -243,6 +243,7 @@ IpAllow::IpAllow(const char *ip_allow_config_var, const 
char *ip_categories_conf
       std::string_view subject_sv = subjects_sv.substr(s, e);
       if (i >= MAX_SUBJECTS) {
         Error("Too many ACL subjects were provided");
+        break;

Review Comment:
   There are existing gold tests that set `proxy.config.acl.subjects`, but none 
appear to cover the new "too many subjects" handling. Add a regression test 
that sets `proxy.config.acl.subjects` to 4+ values and verifies the error is 
logged and ATS doesn’t crash (and that only the first `MAX_SUBJECTS` are 
applied).



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