Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Darwin: Fix error handling in GetMACAddressFromInterfaces #32658

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions src/platform/Darwin/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,20 @@ CHIP_ERROR FindInterfaces(io_iterator_t * primaryInterfaceIterator)

CHIP_ERROR GetMACAddressFromInterfaces(io_iterator_t primaryInterfaceIterator, uint8_t * buf)
{
CHIP_ERROR err = CHIP_NO_ERROR;
CHIP_ERROR err = CHIP_ERROR_NOT_FOUND;

kern_return_t kernResult;
io_object_t interfaceService;
io_object_t controllerService = 0;

while ((interfaceService = IOIteratorNext(primaryInterfaceIterator)))
{
CFTypeRef MACAddressAsCFData = nullptr;
CFTypeRef linkStatusAsCFNumber = nullptr;
kernResult = IORegistryEntryGetParentEntry(interfaceService, kIOServicePlane, &controllerService);
kernResult = IORegistryEntryGetParentEntry(interfaceService, kIOServicePlane, &controllerService);
IOObjectRelease(interfaceService);
VerifyOrExit(KERN_SUCCESS == kernResult, err = CHIP_ERROR_INTERNAL);

linkStatusAsCFNumber = IORegistryEntryCreateCFProperty(controllerService, CFSTR(kIOLinkStatus), kCFAllocatorDefault, 0);
CFTypeRef linkStatusAsCFNumber =
IORegistryEntryCreateCFProperty(controllerService, CFSTR(kIOLinkStatus), kCFAllocatorDefault, 0);
VerifyOrExit(linkStatusAsCFNumber != nullptr, err = CHIP_ERROR_INTERNAL);

uint64_t linkStatus;
Expand All @@ -115,27 +115,21 @@ CHIP_ERROR GetMACAddressFromInterfaces(io_iterator_t primaryInterfaceIterator, u

if ((linkStatus & kIONetworkLinkValid) && (linkStatus & kIONetworkLinkActive))
{
MACAddressAsCFData = IORegistryEntryCreateCFProperty(controllerService, CFSTR(kIOMACAddress), kCFAllocatorDefault, 0);
CFTypeRef MACAddressAsCFData =
IORegistryEntryCreateCFProperty(controllerService, CFSTR(kIOMACAddress), kCFAllocatorDefault, 0);
VerifyOrExit(MACAddressAsCFData != nullptr, err = CHIP_ERROR_INTERNAL);

CFDataGetBytes((CFDataRef) MACAddressAsCFData, CFRangeMake(0, kIOEthernetAddressSize), buf);
CFRelease(MACAddressAsCFData);
ExitNow(err = CHIP_NO_ERROR);
}

kernResult = IOObjectRelease(controllerService);
VerifyOrExit(KERN_SUCCESS == kernResult, err = CHIP_ERROR_INTERNAL);

kernResult = IOObjectRelease(interfaceService);
VerifyOrExit(KERN_SUCCESS == kernResult, err = CHIP_ERROR_INTERNAL);
IOObjectRelease(controllerService);
controllerService = 0;
}

exit:
if (IOObjectGetRetainCount(interfaceService))
{
IOObjectRelease(interfaceService);
}

if (IOObjectGetRetainCount(controllerService))
if (controllerService)
{
IOObjectRelease(controllerService);
}
Expand Down
Loading