Skip to content

Commit 418a4e2

Browse files
committed
Make 633 parsing more strict
Fixes microsoft#181939
1 parent 21dda74 commit 418a4e2

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/vs/platform/terminal/common/xterm/shellIntegrationAddon.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,11 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
316316
}
317317

318318
// Pass the sequence along to the capability
319-
const [command, ...args] = data.split(';');
320-
switch (command) {
319+
const argsIndex = data.indexOf(';');
320+
const sequenceCommand = argsIndex === -1 ? data : data.substring(0, argsIndex);
321+
// Cast to strict checked index access
322+
const args: (string | undefined)[] = argsIndex === -1 ? [] : data.substring(argsIndex + 1).split(';');
323+
switch (sequenceCommand) {
321324
case VSCodeOscPt.PromptStart:
322325
this._createOrGetCommandDetection(this._terminal).handlePromptStart();
323326
return true;
@@ -328,18 +331,21 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
328331
this._createOrGetCommandDetection(this._terminal).handleCommandExecuted();
329332
return true;
330333
case VSCodeOscPt.CommandFinished: {
331-
const exitCode = args.length === 1 ? parseInt(args[0]) : undefined;
334+
const arg0 = args[0];
335+
const exitCode = arg0 !== undefined ? parseInt(arg0) : undefined;
332336
this._createOrGetCommandDetection(this._terminal).handleCommandFinished(exitCode);
333337
return true;
334338
}
335339
case VSCodeOscPt.CommandLine: {
340+
const arg0 = args[0];
341+
const arg1 = args[1];
336342
let commandLine: string;
337-
if (args.length >= 1 || args.length <= 2) {
338-
commandLine = deserializeMessage(args[0]);
343+
if (arg0 !== undefined) {
344+
commandLine = deserializeMessage(arg0);
339345
} else {
340346
commandLine = '';
341347
}
342-
this._createOrGetCommandDetection(this._terminal).setCommandLine(commandLine, args[1] === this._nonce);
348+
this._createOrGetCommandDetection(this._terminal).setCommandLine(commandLine, arg1 === this._nonce);
343349
return true;
344350
}
345351
case VSCodeOscPt.ContinuationStart: {
@@ -359,7 +365,8 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
359365
return true;
360366
}
361367
case VSCodeOscPt.Property: {
362-
const deserialized = args.length ? deserializeMessage(args[0]) : '';
368+
const arg0 = args[0];
369+
const deserialized = arg0 !== undefined ? deserializeMessage(arg0) : '';
363370
const { key, value } = parseKeyValueAssignment(deserialized);
364371
if (value === undefined) {
365372
return true;
@@ -539,10 +546,14 @@ export function parseKeyValueAssignment(message: string): { key: string; value:
539546
}
540547

541548

542-
export function parseMarkSequence(sequence: string[]): { id?: string; hidden?: boolean } {
549+
export function parseMarkSequence(sequence: (string | undefined)[]): { id?: string; hidden?: boolean } {
543550
let id = undefined;
544551
let hidden = false;
545552
for (const property of sequence) {
553+
// Sanity check, this shouldn't happen in practice
554+
if (property === undefined) {
555+
continue;
556+
}
546557
if (property === 'Hidden') {
547558
hidden = true;
548559
}

0 commit comments

Comments
 (0)