Skip to content

Commit 6d1cef7

Browse files
Retain the underlying CBPeripheral in MTRCommissionableBrowserResult
This avoids a dangling pointer if the BleConnectionDelegateImpl drops the peripheral from the cache while a client still holds the browser result. Also document what BLE_CONNECTION_OBJECT is on Darwin.
1 parent ab9931a commit 6d1cef7

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/darwin/Framework/CHIP/MTRCommissionableBrowser.mm

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939

4040
using namespace chip::Tracing::DarwinFramework;
4141

42+
@class CBPeripheral;
43+
4244
@implementation MTRCommissionableBrowserResultInterfaces
4345
@end
4446

@@ -48,6 +50,7 @@ @interface MTRCommissionableBrowserResult ()
4850
@property (nonatomic) NSNumber * productID;
4951
@property (nonatomic) NSNumber * discriminator;
5052
@property (nonatomic) BOOL commissioningMode;
53+
@property (nonatomic, strong, nullable) CBPeripheral * peripheral;
5154
@end
5255

5356
@implementation MTRCommissionableBrowserResult
@@ -302,6 +305,7 @@ void OnBleScanAdd(BLE_CONNECTION_OBJECT connObj, const ChipBLEDeviceIdentificati
302305
result.discriminator = @(info.GetDeviceDiscriminator());
303306
result.commissioningMode = YES;
304307
result.params = chip::MakeOptional(chip::Controller::SetUpCodePairerParameters(connObj, false /* connected */));
308+
result.peripheral = (__bridge CBPeripheral *) connObj; // avoid params holding a dangling pointer
305309

306310
MATTER_LOG_METRIC(kMetricBLEDevicesAdded, ++mBLEDevicesAdded);
307311

src/darwin/Framework/CHIPTests/MTRBleTests.m

-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ - (void)testBleCommissionableBrowserResultAdditionAndRemoval
117117

118118
- (void)testBleCommissionAfterStopBrowseUAF
119119
{
120-
XCTSkip(@"Skip reproducer for known UAF crash");
121-
122120
__block MTRCommissionableBrowserResult * device;
123121
XCTestExpectation * didFindDevice = [self expectationWithDescription:@"did find device"];
124122
TestBrowserDelegate * delegate = [[TestBrowserDelegate alloc] init];

src/platform/Darwin/BlePlatformConfig.h

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626

2727
// ==================== Platform Adaptations ====================
2828

29+
#define BLE_CONNECTION_OBJECT void * // actually __unsafe_unretained CBPeripheral *
30+
#define BLE_CONNECTION_UNINITIALIZED nullptr
31+
#define BLE_USES_DEVICE_EVENTS 0
32+
2933
// ========== Platform-specific Configuration Overrides =========
3034

3135
/* none so far */

0 commit comments

Comments
 (0)