From 1cb01d3eb53fd5a0f616dea5d88a4c3c5a232a8e Mon Sep 17 00:00:00 2001 From: Mason Fish Date: Fri, 30 Apr 2021 15:02:03 -0700 Subject: [PATCH 1/2] fix quotes for brimcap cli args Signed-off-by: Mason Fish --- plugins/brimcap/brimcap-cli.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/brimcap/brimcap-cli.ts b/plugins/brimcap/brimcap-cli.ts index 5f3aef4ab3..8df3f525f4 100644 --- a/plugins/brimcap/brimcap-cli.ts +++ b/plugins/brimcap/brimcap-cli.ts @@ -63,10 +63,13 @@ export default class BrimcapCLI { private exec(subCommand: string, opts: searchOptions) { const commandWithArgs = [ - this.binPath, + `"${this.binPath}"`, subCommand, ...flatMap( - Object.entries(opts).map(([k, v]) => [`-${OPTION_NAME_MAP[k] || k}`, v]) + Object.entries(opts).map(([k, v]) => [ + `-${OPTION_NAME_MAP[k] || k}`, + `"${v}"` + ]) ) ].join(" ") From 7c3c3a551e2db070170dc1b9807d925534d35144 Mon Sep 17 00:00:00 2001 From: Mason Fish Date: Fri, 30 Apr 2021 15:59:43 -0700 Subject: [PATCH 2/2] try spawnSync Signed-off-by: Mason Fish --- plugins/brimcap/brimcap-cli.ts | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/plugins/brimcap/brimcap-cli.ts b/plugins/brimcap/brimcap-cli.ts index 8df3f525f4..cbfd45b543 100644 --- a/plugins/brimcap/brimcap-cli.ts +++ b/plugins/brimcap/brimcap-cli.ts @@ -1,4 +1,4 @@ -import {execSync, spawn, ChildProcess} from "child_process" +import {spawnSync, spawn, ChildProcess} from "child_process" import flatMap from "lodash/flatMap" interface packetOptions { @@ -42,17 +42,16 @@ const OPTION_NAME_MAP = { srcPort: "src.port" } +const toCliOpts = (opts: loadOptions | searchOptions): string[] => + flatMap( + Object.entries(opts).map(([k, v]) => [`-${OPTION_NAME_MAP[k] || k}`, v]) + ) + export default class BrimcapCLI { constructor(private binPath: string) {} public load(pcapPath: string, opts: loadOptions): ChildProcess { - const subCommandWithArgs = [ - "load", - ...flatMap( - Object.entries(opts).map(([k, v]) => [`-${OPTION_NAME_MAP[k] || k}`, v]) - ), - pcapPath - ] + const subCommandWithArgs = ["load", ...toCliOpts(opts), pcapPath] return spawn(this.binPath, subCommandWithArgs) } @@ -62,17 +61,8 @@ export default class BrimcapCLI { } private exec(subCommand: string, opts: searchOptions) { - const commandWithArgs = [ - `"${this.binPath}"`, - subCommand, - ...flatMap( - Object.entries(opts).map(([k, v]) => [ - `-${OPTION_NAME_MAP[k] || k}`, - `"${v}"` - ]) - ) - ].join(" ") + const subCommandWithArgs = [subCommand, ...toCliOpts(opts)] - return execSync(commandWithArgs) + return spawnSync(this.binPath, subCommandWithArgs) } }