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
diff --git a/debian/changelog b/debian/changelog
index 9e45fea..3530cff 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -30,6 +30,7 @@ launchpad-buildd (190) UNRELEASED; urgency=medium
30 * lpbuildd/binarypackage.py: Use "apt-get indextargets" and "apt-helper30 * lpbuildd/binarypackage.py: Use "apt-get indextargets" and "apt-helper
31 cat-file" where they exist to read Packages files, rather than looking31 cat-file" where they exist to read Packages files, rather than looking
32 in /var/lib/apt/lists/ directly.32 in /var/lib/apt/lists/ directly.
33 * Fix environment variable quoting in chroot backend (LP: #1884936).
3334
34 [ Dimitri John Ledkov ]35 [ Dimitri John Ledkov ]
35 * lxd: Add riscv64 to arch table.36 * lxd: Add riscv64 to arch table.
diff --git a/lpbuildd/target/chroot.py b/lpbuildd/target/chroot.py
index 203142c..436e21b 100644
--- a/lpbuildd/target/chroot.py
+++ b/lpbuildd/target/chroot.py
@@ -62,8 +62,7 @@ class Chroot(Backend):
62 """See `Backend`."""62 """See `Backend`."""
63 if env:63 if env:
64 args = ["env"] + [64 args = ["env"] + [
65 "%s=%s" % (key, shell_escape(value))65 "%s=%s" % (key, value) for key, value in env.items()] + args
66 for key, value in env.items()] + args
67 if self.arch is not None:66 if self.arch is not None:
68 args = set_personality(args, self.arch, series=self.series)67 args = set_personality(args, self.arch, series=self.series)
69 if cwd is not None:68 if cwd is not None:
diff --git a/lpbuildd/target/tests/test_chroot.py b/lpbuildd/target/tests/test_chroot.py
index 88e3137..8004fa9 100644
--- a/lpbuildd/target/tests/test_chroot.py
+++ b/lpbuildd/target/tests/test_chroot.py
@@ -139,6 +139,22 @@ class TestChroot(TestCase):
139 expected_args,139 expected_args,
140 [proc._args["args"] for proc in processes_fixture.procs])140 [proc._args["args"] for proc in processes_fixture.procs])
141141
142 def test_run_env_shell_metacharacters(self):
143 self.useFixture(EnvironmentVariable("HOME", "/expected/home"))
144 processes_fixture = self.useFixture(FakeProcesses())
145 processes_fixture.add(lambda _: {}, name="sudo")
146 Chroot("1", "xenial", "amd64").run(
147 ["echo", "hello"], env={"OBJECT": "{'foo': 'bar'}"})
148
149 expected_args = [
150 ["sudo", "/usr/sbin/chroot",
151 "/expected/home/build-1/chroot-autobuild",
152 "linux64", "env", "OBJECT={'foo': 'bar'}", "echo", "hello"],
153 ]
154 self.assertEqual(
155 expected_args,
156 [proc._args["args"] for proc in processes_fixture.procs])
157
142 def test_copy_in(self):158 def test_copy_in(self):
143 self.useFixture(EnvironmentVariable("HOME", "/expected/home"))159 self.useFixture(EnvironmentVariable("HOME", "/expected/home"))
144 source_dir = self.useFixture(TempDir()).path160 source_dir = self.useFixture(TempDir()).path
diff --git a/lpbuildd/target/tests/test_lxd.py b/lpbuildd/target/tests/test_lxd.py
index 145630b..38d3337 100644
--- a/lpbuildd/target/tests/test_lxd.py
+++ b/lpbuildd/target/tests/test_lxd.py
@@ -649,6 +649,21 @@ class TestLXD(TestCase):
649 expected_args,649 expected_args,
650 [proc._args["args"] for proc in processes_fixture.procs])650 [proc._args["args"] for proc in processes_fixture.procs])
651651
652 def test_run_env_shell_metacharacters(self):
653 processes_fixture = self.useFixture(FakeProcesses())
654 processes_fixture.add(lambda _: {}, name="lxc")
655 LXD("1", "xenial", "amd64").run(
656 ["echo", "hello"], env={"OBJECT": "{'foo': 'bar'}"})
657
658 expected_args = [
659 ["lxc", "exec", "lp-xenial-amd64",
660 "--env", "OBJECT={'foo': 'bar'}", "--",
661 "linux64", "echo", "hello"],
662 ]
663 self.assertEqual(
664 expected_args,
665 [proc._args["args"] for proc in processes_fixture.procs])
666
652 def test_copy_in(self):667 def test_copy_in(self):
653 source_dir = self.useFixture(TempDir()).path668 source_dir = self.useFixture(TempDir()).path
654 self.useFixture(MockPatch("pylxd.Client"))669 self.useFixture(MockPatch("pylxd.Client"))

Subscribers

People subscribed via source and target branches