Skip to content

Commit b69d6c8

Browse files
authored
fix: cache.key.files containing ' or * should'nt crash (#1575)
1 parent aa531c4 commit b69d6c8

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

src/job.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,8 +1216,8 @@ export class Job {
12161216

12171217
time = process.hrtime();
12181218
let cmd = "shopt -s globstar nullglob dotglob\n";
1219-
cmd += `mkdir -p ${cachePath}/${cacheName}\n`;
1220-
cmd += `rsync -Ra ${paths} ${cachePath}/${cacheName}/. || true\n`;
1219+
cmd += `mkdir -p ${Utils.safeBashString(cachePath + "/" + cacheName)}\n`;
1220+
cmd += `rsync -Ra ${paths} ${Utils.safeBashString(cachePath + "/" + cacheName + "/.")} || true\n`;
12211221

12221222
await Mutex.exclusive(cacheName, async () => {
12231223
await this.copyOut(cmd, stateDir, "cache", []);
@@ -1336,7 +1336,7 @@ export class Job {
13361336
await fs.mkdirp(`${cwd}/${stateDir}/${type}`);
13371337

13381338
if (this.imageName(this._variables)) {
1339-
const {stdout: containerId} = await Utils.bash(`${this.argv.containerExecutable} create -i ${dockerCmdExtras.join(" ")} -v ${buildVolumeName}:${this.ciProjectDir} -w ${this.ciProjectDir} ${helperImageName} bash -c "${cmd}"`, cwd);
1339+
const {stdout: containerId} = await Utils.bash(`${this.argv.containerExecutable} create -i ${dockerCmdExtras.join(" ")} -v ${buildVolumeName}:${this.ciProjectDir} -w ${this.ciProjectDir} ${helperImageName} bash -c "${cmd.replace(/"/g, "\\\"")}"`, cwd);
13401340
this._containersToClean.push(containerId);
13411341
await Utils.spawn([this.argv.containerExecutable, "start", containerId, "--attach"]);
13421342
await Utils.spawn([this.argv.containerExecutable, "cp", `${containerId}:/${type}/.`, `${stateDir}/${type}/.`], cwd);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
test:
3+
image: bash
4+
cache:
5+
paths:
6+
- fakepackage.json
7+
key:
8+
files:
9+
- fake*
10+
script:
11+
- echo "Wiiiii"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
test:
3+
image: bash
4+
cache:
5+
paths:
6+
- fakepackage.json
7+
key:
8+
files:
9+
- fake'
10+
script:
11+
- echo "Wiiiii"

tests/test-cases/cache-key-files/integration.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,21 @@ test("cache-key-files <cache-key-file file dont exist>", async () => {
4545
const expected = "cache-key-file file dont exist cache created in '.gitlab-ci-local/cache/0_no-such-file-18bbe9d7603e540e28418cf4a072938ac477a2c1'";
4646
expect(writeStreams.stdoutLines.join("\n")).toContain(expected);
4747
});
48+
49+
test("cache-key-files file containing `*` should not crash", async () => {
50+
const writeStreams = new WriteStreamsMock();
51+
await handler({
52+
cwd: "tests/test-cases/cache-key-files",
53+
file: ".gitlab-ci-1.yml",
54+
noColor: true,
55+
}, writeStreams);
56+
});
57+
58+
test("cache-key-files file containing `'` should not crash", async () => {
59+
const writeStreams = new WriteStreamsMock();
60+
await handler({
61+
cwd: "tests/test-cases/cache-key-files",
62+
file: ".gitlab-ci-2.yml",
63+
noColor: true,
64+
}, writeStreams);
65+
});

0 commit comments

Comments
 (0)