Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-53775

Add clang rule to detect access to deleted pointers

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • 6.0 Desired
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Service Arch

      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.

            Assignee:
            backlog-server-servicearch [DO NOT USE] Backlog - Service Architecture
            Reporter:
            pierlauro.sciarelli@mongodb.com Pierlauro Sciarelli
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: