[SERVER-53775] Add clang rule to detect access to deleted pointers Created: 14/Jan/21  Updated: 04/Jan/24

Status: Open
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 6.0 Desired

Type: Task Priority: Major - P3
Reporter: Pierlauro Sciarelli Assignee: Backlog - Service Architecture
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Service Arch
Participants:

 Description   

benety.goh noticed that XCode 12.3 with the option -Wdangling-gsl was able to spot an unsafe unique pointer usage in resharding_recipient_service.cpp:

// UNSAFE because opCtx will then be an OperationContext* to a deleted OperationContext
auto opCtx = cc().makeOperationContext().get();
auto catalogCache = Grid::get(opCtx)->catalogCache();
catalogCache->getShardedCollectionRoutingInfo(opCtx, _recipientDoc.getNss());

// SAFE
auto opCtx = cc().makeOperationContext();
auto catalogCache = Grid::get(opCtx.get())->catalogCache();
catalogCache->getShardedCollectionRoutingInfo(opCtx.get(), _recipientDoc.getNss());

It would be good to add a clang check equivalent to -Wdangling-gsl , probably bugprone-dangling-handle could make the trick but it requires configuring HandleClasses . acm also pointed out that we could start using a clang-tidy configuration file (e.g. as done by envoyproxy) instead of manually passing the parameters.


Generated at Thu Feb 08 05:31:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.