Skip to content

Commit e3c0d11

Browse files
committed
DFX AU utilities library: add a null-pointer safety check when recursing sub-directories of AU preset files (creating the tree node can fail)
1 parent df534ec commit e3c0d11

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

dfx-library/dfx-au-utilities-preset-files.m

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,23 +301,26 @@ void CollectAllAUPresetFilesInDir(CFURLRef inDirURL, CFTreeRef inParentTree, Aud
301301
}
302302

303303
// first, we query the directory's contents
304-
NSArray<NSURL*>* dirContents = [NSFileManager.defaultManager contentsOfDirectoryAtURL:(__bridge NSURL*)inDirURL includingPropertiesForKeys:resourceKeys options:NSDirectoryEnumerationSkipsHiddenFiles error:nil];
304+
NSArray<NSURL*>* const dirContents = [NSFileManager.defaultManager contentsOfDirectoryAtURL:(__bridge NSURL*)inDirURL includingPropertiesForKeys:resourceKeys options:NSDirectoryEnumerationSkipsHiddenFiles error:nil];
305305
if (dirContents == nil)
306306
{
307307
goto checkEmptyTree;
308308
}
309309

310310
// this is the main loop through each directory item using the array of contents
311-
for (NSURL* url in dirContents)
311+
for (NSURL* const url in dirContents)
312312
{
313313
CFURLRef const urlCF = (__bridge CFURLRef)url;
314314
NSNumber* isDirectory = nil;
315315
BOOL const success = [url getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:nil];
316316
// if the current item itself is a directory, then we recursively call this function on that sub-directory
317-
if (success && (isDirectory != nil) && isDirectory.boolValue)
317+
if (success && [isDirectory boolValue])
318318
{
319319
CFTreeRef const newSubTree = AddFileItemToTree(urlCF, inParentTree);
320-
CollectAllAUPresetFilesInDir(urlCF, newSubTree, inAUComponent);
320+
if (newSubTree != NULL)
321+
{
322+
CollectAllAUPresetFilesInDir(urlCF, newSubTree, inAUComponent);
323+
}
321324
}
322325
// otherwise it's a file, so we add it (if it is an AU preset file)
323326
else if (CFURLIsAUPreset(urlCF))

0 commit comments

Comments
 (0)