Copilot commented on code in PR #3728:
URL: https://github.com/apache/brpc/pull/3728#discussion_r4533185395


##########
src/brpc/ubshm/ub_endpoint.cpp:
##########
@@ -619,11 +619,11 @@ void* UBShmEndpoint::ProcessHandshakeAtServer(void* arg) {
         }
         int result = snprintf(local_trx_shm.name, SHM_MAX_NAME_BUFF_LEN, 
"%s_%s",
             client_name, SERVER_SHM_NAME_SUFFIX);
-        if (UNLIKELY(result < 0)) {
+        if (UNLIKELY(result < 0 || result >= SHM_MAX_NAME_BUFF_LEN)) {
             LOG(WARNING) << "Copy client shared memory name failed, ret=" << 
result;
             ub_transport->_ub_state = UBShmTransport::UB_OFF;
         }
-        if (result >= 0 && ep->AllocateServerResources(
+        if (result >= 0 && result < SHM_MAX_NAME_BUFF_LEN && 
ep->AllocateServerResources(

Review Comment:
   The added regression only exercises `ApplyAndMapLocalShm`, so it verifies 
client-local name rejection and slot release but never reaches this 
server-handshake branch. Please add coverage for an overlong peer name through 
`ProcessHandshakeAtServer` (or an equivalent focused helper) and assert that 
the server falls back without allocating a truncated shared-memory object; 
otherwise this independently changed collision-prone path can regress while the 
new test stays green.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to