Skip to content

Commit

Permalink
Don't assert inside lock protected region (could leave lock held).
Browse files Browse the repository at this point in the history
  • Loading branch information
rfm committed Dec 6, 2024
1 parent 476b4f7 commit e7dd2f7
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions Source/NSBundle.m
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,10 @@ + (NSString**) frameworkClasses;
static inline NSString *
_find_main_bundle_for_tool(NSString *toolName)
{
NSArray *paths;
NSEnumerator *enumerator;
NSString *path;
NSString *tail;
NSArray *paths;
NSEnumerator *enumerator;
NSString *path;
NSString *tail;
NSFileManager *fm = manager();

/*
Expand All @@ -458,11 +458,10 @@ + (NSString**) frameworkClasses;
}

tail = [@"Tools" stringByAppendingPathComponent:
[@"Resources" stringByAppendingPathComponent:
toolName]];
[@"Resources" stringByAppendingPathComponent: toolName]];

paths = NSSearchPathForDirectoriesInDomains (NSLibraryDirectory,
NSAllDomainsMask, YES);
paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
NSAllDomainsMask, YES);

enumerator = [paths objectEnumerator];
while ((path = [enumerator nextObject]))
Expand Down Expand Up @@ -502,12 +501,13 @@ + (NSString**) frameworkClasses;
the executable name here - just in case it turns out it's a
tool. */
NSString *toolName = [GSPrivateExecutablePath() lastPathComponent];

#if defined(_WIN32) || defined(__CYGWIN__)
toolName = [toolName stringByDeletingPathExtension];
#endif

/* Strip off the name of the program */
path = [GSPrivateExecutablePath() stringByDeletingLastPathComponent];
/* Strip off the name of the executable */
path = [toolName stringByDeletingLastPathComponent];

This comment has been minimized.

Copy link
@triplef

triplef Dec 7, 2024

Member

I think this change was a mistake: toolName is not the full executable path, but only its last path component. I think the result of this code is an empty string.


/* We now need to chop off the extra subdirectories, the library
combo and the target directory if they exist. The executable
Expand Down Expand Up @@ -1841,24 +1841,28 @@ + (NSArray *) allFrameworks
*/
+ (NSBundle *) mainBundle
{
[load_lock lock];
if (!_mainBundle)
{
NSString *path = _find_main_bundle_path();
NSString *path = nil;

NSDebugMLLog(@"NSBundle", @"Main bundle path is %@\n", path);
/* We do alloc and init separately so initWithPath: knows we are
the _mainBundle. Please note that we do *not* autorelease
mainBundle, because we don't want it to be ever released. */
_mainBundle = [self alloc];
/* Please note that _mainBundle should *not* be nil. */
_mainBundle = [_mainBundle initWithPath: path];
[load_lock lock];
if (!_mainBundle)
{
path = _find_main_bundle_path();
/* We do alloc and init separately so initWithPath: knows we are
the _mainBundle. Please note that we do *not* autorelease
mainBundle, because we don't want it to be ever released. */
_mainBundle = [self alloc];
/* Please note that _mainBundle should *not* be nil. */
_mainBundle = [_mainBundle initWithPath: path];
}
[load_lock unlock];
NSAssert(path != nil, NSInternalInconsistencyException);
NSAssert(_mainBundle != nil, NSInternalInconsistencyException);
NSDebugMLLog(@"NSBundle", @"Main bundle path is %@\n", path);
}
[load_lock unlock];
return _mainBundle;
}

/**
* Returns the bundle whose code contains the specified class.<br />
* NB: We will not find a class if the bundle has not been loaded yet!
Expand Down

0 comments on commit e7dd2f7

Please sign in to comment.