Skip to content

fix(ubshm): reject a null trx before loading its generation - #63

Merged
zchuango merged 1 commit into
LinQuickDev:ubshm_transport_fix_2from
Sherlock0203:ubshm_transport_fix_2
Oct 8, 2026
Merged

zchuango merged 1 commit into
LinQuickDev:ubshm_transport_fix_2from
Sherlock0203:ubshm_transport_fix_2

Conversation

@Sherlock0203

Copy link
Copy Markdown

No description provided.

UbrTrxClose loaded _trx->ubr_id before calling UbrTrxCloseCheck, which is
where the null check lived, so that guard became unreachable and the load
dereferenced null.

The path is reachable: UbrAllocateLocalShm and UbrAllocateServerShm reset
_trx to nullptr on their error paths (a failing shm map, acquire or trx
init) while the endpoint keeps the non-null _ub_ring, and
UBShmEndpoint::DeallocateResources calls UbrTrxClose unconditionally from
Reset(), so a connection whose setup failed crashes when its endpoint is
destroyed, or when it falls back to TCP.

Check _trx first and return UBRING_ERR, which restores the behavior from
before the generation argument was added; DeallocateResources ignores the
return value. UbrAddTimer takes the same guard: its failure branch reports
_trx->local_shm.name before the guards in UbrAddCloseTimer/UbrAddHBTimer
can reject a null trx.

UbrTrxCloseCheck keeps its own null check: UbrPassiveClearTrx still routes
through it.

Tested: cmake --build cmake-build-debug --target brpc_ubring_unittest, and
./test/brpc_ubring_unittest (12/12 passed).
@zchuango
zchuango merged commit 6305d2d into LinQuickDev:ubshm_transport_fix_2 Oct 8, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants