Skip to content

Commit

Permalink
check for failure of dup/dup2 even though it will never happen
Browse files Browse the repository at this point in the history
  • Loading branch information
rfm committed Feb 4, 2018
1 parent 54bf659 commit 546deb4
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions Source/NSTask.m
Expand Up @@ -1614,12 +1614,12 @@ - (void) launch
/* Set up stdin, stdout and stderr by duplicating descriptor as
* necessary and closing the original.
*/
dup2(s, 0);
dup2(s, 1);
dup2(s, 2);
if (dup2(s, 0) != 0) exit(1);
if (dup2(s, 1) != 1) exit(1);
if (dup2(s, 2) != 2) exit(1);
if (s != 0 && s != 1 && s != 2)
{
close(s);
(void)close(s);
}
}
else
Expand All @@ -1630,15 +1630,15 @@ - (void) launch
*/
if (idesc != 0)
{
dup2(idesc, 0);
if (dup2(idesc, 0) != 0) exit(1);
}
if (odesc != 1)
{
dup2(odesc, 1);
if (dup2(odesc, 1) != 1) exit(1);
}
if (edesc != 2)
{
dup2(edesc, 2);
if (dup2(edesc, 2) != 2) exit(1);
}
}

Expand All @@ -1650,8 +1650,8 @@ - (void) launch
(void) close(i);
}

chdir(path);
execve(executable, (char**)args, (char**)envl);
(void)chdir(path);
(void)execve(executable, (char**)args, (char**)envl);
exit(-1);
}
else
Expand Down Expand Up @@ -1746,6 +1746,7 @@ - (void) _collectChild

- (BOOL) usePseudoTerminal
{
int desc;
int master;
NSFileHandle *fh;

Expand All @@ -1762,13 +1763,21 @@ - (BOOL) usePseudoTerminal
closeOnDealloc: YES];
[self setStandardInput: fh];
RELEASE(fh);
master = dup(master);
fh = [[NSFileHandle alloc] initWithFileDescriptor: master

if ((desc = dup(master)) < 0)
{
return NO;
}
fh = [[NSFileHandle alloc] initWithFileDescriptor: desc
closeOnDealloc: YES];
[self setStandardOutput: fh];
RELEASE(fh);
master = dup(master);
fh = [[NSFileHandle alloc] initWithFileDescriptor: master

if ((desc = dup(master)) < 0)
{
return NO;
}
fh = [[NSFileHandle alloc] initWithFileDescriptor: desc
closeOnDealloc: YES];
[self setStandardError: fh];
RELEASE(fh);
Expand Down

0 comments on commit 546deb4

Please sign in to comment.