Merge ~cjwatson/launchpad-buildd:image-targets-fix into launchpad-buildd:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: d7cdc6fa0ed3cd4cc5dcf3ce9174aabfe183c05f
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad-buildd:image-targets-fix
Merge into: launchpad-buildd:master
Diff against target: 79 lines (+33/-2)
4 files modified
debian/changelog (+1/-0)
lpbuildd/target/chroot.py (+1/-2)
lpbuildd/target/tests/test_chroot.py (+16/-0)
lpbuildd/target/tests/test_lxd.py (+15/-0)
Reviewer Review Type Date Requested Status
Tom Wardill (community) Approve
Review via email: mp+387221@code.launchpad.net

Commit message

Fix environment variable quoting in chroot backend

Description of the change

The arguments to "env" are assembled as an argv list, so they shouldn't be internally-quoted.

Reported by Dimitri John Ledkov.

To post a comment you must log in.
Revision history for this message
Tom Wardill (twom) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index 9e45fea..3530cff 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -30,6 +30,7 @@ launchpad-buildd (190) UNRELEASED; urgency=medium
6 * lpbuildd/binarypackage.py: Use "apt-get indextargets" and "apt-helper
7 cat-file" where they exist to read Packages files, rather than looking
8 in /var/lib/apt/lists/ directly.
9+ * Fix environment variable quoting in chroot backend (LP: #1884936).
10
11 [ Dimitri John Ledkov ]
12 * lxd: Add riscv64 to arch table.
13diff --git a/lpbuildd/target/chroot.py b/lpbuildd/target/chroot.py
14index 203142c..436e21b 100644
15--- a/lpbuildd/target/chroot.py
16+++ b/lpbuildd/target/chroot.py
17@@ -62,8 +62,7 @@ class Chroot(Backend):
18 """See `Backend`."""
19 if env:
20 args = ["env"] + [
21- "%s=%s" % (key, shell_escape(value))
22- for key, value in env.items()] + args
23+ "%s=%s" % (key, value) for key, value in env.items()] + args
24 if self.arch is not None:
25 args = set_personality(args, self.arch, series=self.series)
26 if cwd is not None:
27diff --git a/lpbuildd/target/tests/test_chroot.py b/lpbuildd/target/tests/test_chroot.py
28index 88e3137..8004fa9 100644
29--- a/lpbuildd/target/tests/test_chroot.py
30+++ b/lpbuildd/target/tests/test_chroot.py
31@@ -139,6 +139,22 @@ class TestChroot(TestCase):
32 expected_args,
33 [proc._args["args"] for proc in processes_fixture.procs])
34
35+ def test_run_env_shell_metacharacters(self):
36+ self.useFixture(EnvironmentVariable("HOME", "/expected/home"))
37+ processes_fixture = self.useFixture(FakeProcesses())
38+ processes_fixture.add(lambda _: {}, name="sudo")
39+ Chroot("1", "xenial", "amd64").run(
40+ ["echo", "hello"], env={"OBJECT": "{'foo': 'bar'}"})
41+
42+ expected_args = [
43+ ["sudo", "/usr/sbin/chroot",
44+ "/expected/home/build-1/chroot-autobuild",
45+ "linux64", "env", "OBJECT={'foo': 'bar'}", "echo", "hello"],
46+ ]
47+ self.assertEqual(
48+ expected_args,
49+ [proc._args["args"] for proc in processes_fixture.procs])
50+
51 def test_copy_in(self):
52 self.useFixture(EnvironmentVariable("HOME", "/expected/home"))
53 source_dir = self.useFixture(TempDir()).path
54diff --git a/lpbuildd/target/tests/test_lxd.py b/lpbuildd/target/tests/test_lxd.py
55index 145630b..38d3337 100644
56--- a/lpbuildd/target/tests/test_lxd.py
57+++ b/lpbuildd/target/tests/test_lxd.py
58@@ -649,6 +649,21 @@ class TestLXD(TestCase):
59 expected_args,
60 [proc._args["args"] for proc in processes_fixture.procs])
61
62+ def test_run_env_shell_metacharacters(self):
63+ processes_fixture = self.useFixture(FakeProcesses())
64+ processes_fixture.add(lambda _: {}, name="lxc")
65+ LXD("1", "xenial", "amd64").run(
66+ ["echo", "hello"], env={"OBJECT": "{'foo': 'bar'}"})
67+
68+ expected_args = [
69+ ["lxc", "exec", "lp-xenial-amd64",
70+ "--env", "OBJECT={'foo': 'bar'}", "--",
71+ "linux64", "echo", "hello"],
72+ ]
73+ self.assertEqual(
74+ expected_args,
75+ [proc._args["args"] for proc in processes_fixture.procs])
76+
77 def test_copy_in(self):
78 source_dir = self.useFixture(TempDir()).path
79 self.useFixture(MockPatch("pylxd.Client"))

Subscribers

People subscribed via source and target branches