[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[rhel5-branch] Fix shlex traceback if pxeboot cmdline ends in a quote (#500198)



There's a pxelinux bug where it fails to add the beginning quote
when it tries to add BOOT_IMAGE= to the commandline and the label
has spaces (you get e.g.: 'linux BOOT_IMAGE=vmlinuz with label"')

Previously we tried to fix this up by adding a quote after
BOOT_IMAGE= whenever the cmdline ends in a quote. This causes us
to have unbalanced quotes if the cmdline is something like:
    linux BOOT_IMAGE=vmlinuz ethtool="speed 100 duplex"

With this change, we now split the commandline at BOOT_IMAGE= and
check to see if the right side has unbalanced quotes. If so, we add
a quote after BOOT_IMAGE=.
---
 flags.py |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/flags.py b/flags.py
index 0351889..a5d380a 100644
--- a/flags.py
+++ b/flags.py
@@ -37,8 +37,9 @@ class Flags:
         # if the BOOT_IMAGE contains a space, pxelinux will strip one of the
         # quotes leaving one at the end that shlex doesn't know what to do
         # with
-        if cmdline.find("BOOT_IMAGE=") and cmdline.endswith('"'):
-            cmdline = cmdline.replace("BOOT_IMAGE=", "BOOT_IMAGE=\"")
+        (left, middle, right) = cmdline.rpartition("BOOT_IMAGE=")
+        if right.count('"') % 2:
+            cmdline = left + middle + '"' + right
 
         lst = shlex.split(cmdline)
 
-- 
1.7.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]