Skip to content

Commit

Permalink
Fix unsync bugs when the shell terminates with raised privileges
Browse files Browse the repository at this point in the history
  • Loading branch information
JLChnToZ committed Jan 2, 2019
1 parent f592e37 commit c519d79
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 47 deletions.
18 changes: 7 additions & 11 deletions lib/terminals/uachost.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/terminals/uachost.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 5 additions & 11 deletions lib/terminals/uacwrapper.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/terminals/uacwrapper.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 6 additions & 11 deletions src/terminals/uachost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export function connectToClient(path: string) {
let flushRequested = false;
const client = connectServer(joinPath('\\\\.\\pipe', path));
client
.on('error', handleRemoteClose)
.on('close', handleRemoteClose)
.on('end', handleRemoteClose)
.pipe(createDecodeStream())
.on('data', handleRequest);
const writer = createEncodeStream();
Expand Down Expand Up @@ -55,14 +54,12 @@ export function connectToClient(path: string) {
break;
case CMDType.Exit:
if(!host) throw new Error('Host is not spawned.');
host.end();
host = undefined;
throw new Error('Host closed.');
host.destroy();
break;
default: throw new Error('Invalid code');
}
} catch {
client.end();
process.exit();
client.destroy();
}
}

Expand All @@ -71,18 +68,16 @@ export function connectToClient(path: string) {
}

function handleClose(code?: number, signal?: number) {
if(host) host = undefined;
writeAndFlush(CMDType.Exit, code || 0, signal || 0);
client.end();
process.exit();
}

function handleError(error: Error) {
writeAndFlush(CMDType.Error, error.message);
}

function handleRemoteClose() {
if(host) host.end();
host = undefined;
if(host) host.destroy();
process.exit();
}

Expand Down
Loading

0 comments on commit c519d79

Please sign in to comment.