mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Return error if task directory is bad
This commit is contained in:
parent
9d0887e4d6
commit
a5a9423c10
4 changed files with 65 additions and 4 deletions
|
@ -1,3 +1,11 @@
|
|||
2023-10-10 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/GSPrivate.h: New method to set up system error information.
|
||||
* Source/Additions/NSError+GNUstepBase.m: Implement method.
|
||||
* Source/NSTask.m(launchAndReturnError:): Return an error if the
|
||||
path to launch in does not exist, is not a directory or is not
|
||||
accessible.
|
||||
|
||||
2023-10-09 Wolfgang Lux <wolfgang.lux@gmail.com>
|
||||
|
||||
* Source/NSTask.m(launchAndReturnError:): Use _exit instead of
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
#import "Foundation/NSDictionary.h"
|
||||
#import "Foundation/NSError.h"
|
||||
#import "Foundation/NSException.h"
|
||||
#import "Foundation/NSLock.h"
|
||||
#import "GSPrivate.h"
|
||||
|
||||
|
@ -167,4 +168,18 @@ strerror_r(int eno, char *buf, int len)
|
|||
error = [self errorWithDomain: domain code: code userInfo: info];
|
||||
return error;
|
||||
}
|
||||
|
||||
- (void) _setObject: (NSObject*)anObject forKey: (NSString*)aKey
|
||||
{
|
||||
NSMutableDictionary *ui = (NSMutableDictionary*)[self userInfo];
|
||||
|
||||
NSAssert([anObject isKindOfClass: [NSObject class]],
|
||||
NSInvalidArgumentException);
|
||||
NSAssert([aKey isKindOfClass: [NSString class]],
|
||||
NSInvalidArgumentException);
|
||||
NSAssert([ui isKindOfClass: [NSMutableDictionary class]],
|
||||
NSGenericException);
|
||||
[ui setObject: anObject forKey: aKey];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -307,6 +307,7 @@ typedef enum {
|
|||
@interface NSError (GNUstepBase)
|
||||
+ (NSError*) _last;
|
||||
+ (NSError*) _systemError: (long)number;
|
||||
- (void) _setObject: (NSObject*)anObject forKey: (NSString*)aKey;
|
||||
@end
|
||||
|
||||
@class NSRunLoop;
|
||||
|
|
|
@ -27,11 +27,13 @@
|
|||
|
||||
#import "common.h"
|
||||
#define EXPOSE_NSTask_IVARS 1
|
||||
#import "Foundation/FoundationErrors.h"
|
||||
#import "Foundation/NSAutoreleasePool.h"
|
||||
#import "Foundation/NSCharacterSet.h"
|
||||
#import "Foundation/NSData.h"
|
||||
#import "Foundation/NSDate.h"
|
||||
#import "Foundation/NSEnumerator.h"
|
||||
#import "Foundation/NSError.h"
|
||||
#import "Foundation/NSException.h"
|
||||
#import "Foundation/NSFileHandle.h"
|
||||
#import "Foundation/NSFileManager.h"
|
||||
|
@ -339,7 +341,7 @@ pty_slave(const char* name)
|
|||
if (_currentDirectoryPath == nil)
|
||||
{
|
||||
[self setCurrentDirectoryPath:
|
||||
[[NSFileManager defaultManager] currentDirectoryPath]];
|
||||
[[NSFileManager defaultManager] currentDirectoryPath]];
|
||||
}
|
||||
return _currentDirectoryPath;
|
||||
}
|
||||
|
@ -1526,8 +1528,12 @@ GSPrivateCheckTasks()
|
|||
// 10.13 method...
|
||||
- (BOOL) launchAndReturnError: (NSError **)error
|
||||
{
|
||||
NSFileManager *mgr = [NSFileManager defaultManager];
|
||||
NSDictionary *info;
|
||||
NSMutableArray *toClose;
|
||||
NSString *lpath;
|
||||
NSString *cwd;
|
||||
BOOL ok;
|
||||
int pid;
|
||||
const char *executable;
|
||||
const char *path;
|
||||
|
@ -1548,8 +1554,6 @@ GSPrivateCheckTasks()
|
|||
{
|
||||
if (error)
|
||||
{
|
||||
NSDictionary *info;
|
||||
|
||||
info = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"task has already been launched", NSLocalizedDescriptionKey, nil];
|
||||
*error = [NSError errorWithDomain: NSCocoaErrorDomain
|
||||
|
@ -1589,7 +1593,40 @@ GSPrivateCheckTasks()
|
|||
}
|
||||
envl[ec] = 0;
|
||||
|
||||
path = [[self currentDirectoryPath] fileSystemRepresentation];
|
||||
cwd = [self currentDirectoryPath];
|
||||
if (NO == [mgr fileExistsAtPath: cwd isDirectory: &ok])
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
info = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"does not exist", NSLocalizedDescriptionKey,
|
||||
cwd, NSFilePathErrorKey,
|
||||
nil];
|
||||
*error = [NSError errorWithDomain: NSCocoaErrorDomain
|
||||
code: NSFileNoSuchFileError
|
||||
userInfo: info];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
if (NO == ok)
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
*error = [NSError _systemError: ENOTDIR];
|
||||
[*error _setObject: cwd forKey: NSFilePathErrorKey];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
if (NO == [mgr isExecutableFileAtPath: cwd])
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
*error = [NSError _systemError: EACCES];
|
||||
[*error _setObject: cwd forKey: NSFilePathErrorKey];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
path = [cwd fileSystemRepresentation];
|
||||
|
||||
toClose = [NSMutableArray arrayWithCapacity: 3];
|
||||
hdl = [self standardInput];
|
||||
|
|
Loading…
Reference in a new issue