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


##########
src/iocore/net/quic/QUICTypes.cc:
##########
@@ -723,17 +723,22 @@ QUICConnectionId::ZERO()
   return QUICConnectionId(zero, 0);
 }
 
-QUICConnectionId::QUICConnectionId()
-{
-  this->randomize();
-}
-
 QUICConnectionId::QUICConnectionId(const uint8_t *buf, uint8_t len) : _len(len)
 {
   ink_assert(len <= QUICConnectionId::MAX_LENGTH);
   memcpy(this->_id, buf, std::min(static_cast<int>(len), 
QUICConnectionId::MAX_LENGTH));
 }
 
+QUICConnectionId
+QUICConnectionId::random()
+{
+  uint8_t id[MAX_LENGTH] = {0};
+
+  ink_release_assert(SCID_LEN <= MAX_LENGTH);
+  ink_release_assert(RAND_bytes(id, SCID_LEN) == 1);
+  return {id, SCID_LEN};
+}

Review Comment:
   `QUICConnectionId::random()` reads the mutable `SCID_LEN` multiple times 
(assert, `RAND_bytes`, and return). Since `SCID_LEN` is updated in 
`QUICConfig::reconfigure()` (src/iocore/net/quic/QUICConfig.cc:629), multiple 
reads can produce an inconsistent length within one call, and it makes the 
function harder to reason about during config reloads. Capture `SCID_LEN` once 
into a local and use that for all operations; optionally short-circuit the 
0-length case to avoid relying on `RAND_bytes(..., 0)` semantics.



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