Skip to content

Commit e09c75e

Browse files
committed
Revert "fix: improve subprocess spawning portability"
This reverts commit 2e9c8d3.
1 parent 96ab3cf commit e09c75e

5 files changed

Lines changed: 52 additions & 39 deletions

File tree

lib/analyzer/image-inspector.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,8 @@ async function getImageArchive(
212212

213213
try {
214214
inspectResult = await getInspectResult(docker, targetImage);
215-
} catch (error) {
216-
debug(
217-
`${targetImage} does not exist locally, proceeding to pull image.`,
218-
error.stack || error,
219-
);
215+
} catch {
216+
debug(`${targetImage} does not exist locally, proceeding to pull image.`);
220217
}
221218

222219
if (inspectResult === undefined) {

lib/sub-process.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as childProcess from "child_process";
2+
import { quoteAll } from "shescape/stateless";
23

34
export { execute, CmdOutput };
45
interface CmdOutput {
@@ -12,15 +13,13 @@ function execute(
1213
options?,
1314
): Promise<CmdOutput> {
1415
const spawnOptions: any = {
15-
// Some distributions may not have /bin/bash, which would cause `child_process.spawn` to fail.
16-
// By setting `shell: false`, we tell `spawn` to execute the command directly without a shell,
17-
// which is more portable.
18-
shell: false,
16+
shell: process.platform !== "win32" ? "/bin/bash" : true,
1917
env: { ...process.env },
2018
};
2119
if (options && options.cwd) {
2220
spawnOptions.cwd = options.cwd;
2321
}
22+
args = quoteAll(args, { ...spawnOptions, flagProtection: false });
2423

2524
// Before spawning an external process, we look if we need to restore the system proxy configuration,
2625
// which overrides the cli internal proxy configuration.

package-lock.json

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"mkdirp": "^1.0.4",
4646
"packageurl-js": "1.2.0",
4747
"semver": "^7.6.3",
48+
"shescape": "2.1.0",
4849
"snyk-nodejs-lockfile-parser": "^2.0.0",
4950
"snyk-poetry-lockfile-parser": "^1.4.0",
5051
"snyk-resolve-deps": "^4.7.1",

test/system/plugin.spec.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { DepGraph } from "@snyk/dep-graph";
22
import * as plugin from "../../lib";
3-
import * as subProcess from "../../lib/sub-process";
43
import { getFixture } from "../util";
54

65
describe("plugin", () => {
@@ -92,35 +91,6 @@ describe("plugin", () => {
9291
});
9392
});
9493

95-
describe("when scanning a locally loaded image", () => {
96-
const imageName = "busybox";
97-
const imageTag = "latest";
98-
const imageNameWithTag = `${imageName}:${imageTag}`;
99-
100-
beforeAll(async () => {
101-
const fixturePath = getFixture([
102-
"../fixtures/docker-archives",
103-
"skopeo-copy/busybox.tar",
104-
]);
105-
await subProcess.execute("docker", ["load", "--input", fixturePath]);
106-
}, 10000); // 10s timeout for loading image
107-
108-
afterAll(async () => {
109-
await subProcess.execute("docker", ["rmi", imageNameWithTag]);
110-
});
111-
112-
test("should successfully scan a local image loaded from a tar archive", async () => {
113-
const pluginResult = await plugin.scan({ path: imageNameWithTag });
114-
const depGraph: DepGraph = pluginResult.scanResults[0].facts.find(
115-
(fact) => fact.type === "depGraph",
116-
)!.data;
117-
118-
expect(depGraph.rootPkg.name).toEqual(`docker-image|${imageName}`);
119-
expect(depGraph.rootPkg.version).toEqual(imageTag);
120-
expect(pluginResult.scanResults[0].identity.type).toEqual("linux");
121-
});
122-
});
123-
12494
test("image pulled by tag has version set", async () => {
12595
const imageNameAndTag = `nginx:1.19.0`;
12696

0 commit comments

Comments
 (0)