curtin-dev team mailing list archive
-
curtin-dev team
-
Mailing list archive
-
Message #00159
[Merge] ~raharper/curtin:fix/udevadm-info-shlex-quote into curtin:master
Ryan Harper has proposed merging ~raharper/curtin:fix/udevadm-info-shlex-quote into curtin:master.
Commit message:
udev: use shlex.quote before shlex.split to preserve shell escape chars
The udev database includes shell escape characters in the output.
Use shlex.quote on the values before calling shlex.split to preserve
the original characture in the value.
- Python2.7 shlex does not implement quote, use a best approximation
LP: #1875085
Requested reviews:
curtin developers (curtin-dev)
Related bugs:
Bug #1875085 in curtin (Ubuntu): "curtin install hook fails with No closing quotation on new 20.04 install"
https://bugs.launchpad.net/ubuntu/+source/curtin/+bug/1875085
For more details, see:
https://code.launchpad.net/~raharper/curtin/+git/curtin/+merge/382993
--
Your team curtin developers is requested to review the proposed merge of ~raharper/curtin:fix/udevadm-info-shlex-quote into curtin:master.
diff --git a/curtin/udev.py b/curtin/udev.py
index e2e3dd0..a57f774 100644
--- a/curtin/udev.py
+++ b/curtin/udev.py
@@ -6,6 +6,13 @@ import os
from curtin import util
from curtin.log import logged_call
+try:
+ shlex_quote = shlex.quote
+except AttributeError:
+ # python2.7 shlex does not have quote, give it a try
+ def shlex_quote(value):
+ return ("'" + value.replace("'", "\'\"\'\"\'") + "'")
+
def compose_udev_equality(key, value):
"""Return a udev comparison clause, like `ACTION=="add"`."""
@@ -90,14 +97,14 @@ def udevadm_info(path=None):
value = None
if value:
# preserve spaces in values to match udev database
- parsed = shlex.split(value)
+ parsed = shlex.split(shlex_quote(value))
if ' ' not in value:
info[key] = parsed[0]
else:
# special case some known entries with spaces, e.g. ID_SERIAL
# and DEVLINKS, see tests/unittests/test_udev.py
if key == "DEVLINKS":
- info[key] = shlex.split(parsed[0])
+ info[key] = shlex.split(shlex_quote(parsed[0]))
elif key == 'ID_SERIAL':
info[key] = parsed[0]
else:
diff --git a/tests/unittests/test_udev.py b/tests/unittests/test_udev.py
index 33d5f44..98f3c41 100644
--- a/tests/unittests/test_udev.py
+++ b/tests/unittests/test_udev.py
@@ -16,6 +16,7 @@ ID_PART_TABLE_TYPE='gpt'
ID_PART_TABLE_UUID='ea0b9ddc-a114-4e01-b257-750d86e3a944'
ID_SERIAL='SAMSUNG MZVLB1T0HALR-000L7_S3TPNY0JB00151'
ID_SERIAL_SHORT='S3TPNY0JB00151'
+ID_VENDOR_ENC='SanDisk\''
MAJOR='259'
MINOR='0'
SUBSYSTEM='block'
@@ -33,6 +34,7 @@ INFO_DICT = {
'ID_PART_TABLE_UUID': 'ea0b9ddc-a114-4e01-b257-750d86e3a944',
'ID_SERIAL': 'SAMSUNG MZVLB1T0HALR-000L7_S3TPNY0JB00151',
'ID_SERIAL_SHORT': 'S3TPNY0JB00151',
+ 'ID_VENDOR_ENC': 'SanDisk\'',
'MAJOR': '259',
'MINOR': '0',
'SUBSYSTEM': 'block',
Follow ups