The GRUB2 multiboot module merges series of spaces into a single space.
Do the same when generating grub.cfg in the first place.
This enable users to copy/paste command lines from grub.cfg into
lcp_crtpolelt or tb_polgen command lines, reducing the likelyhood
of typos resulting in TXT boot failure.

# HG changeset patch
# User Martin Wilck <martin.wi...@ts.fujitsu.com>
# Date 1456320187 -3600
#      Wed Feb 24 14:23:07 2016 +0100
# Branch mw-001
# Node ID e218c239de4be18bb0c6ad6beb9b6db3a24ce405
# Parent  dd6d0b5f2fc9e242701f2c9c4caf6066dfd32e80
grub2: sanitize whitespace in command lines

The GRUB2 multiboot module merges series of spaces into a single space.
Do the same when generating grub.cfg in the first place.
This enable users to copy/paste command lines from grub.cfg into
lcp_crtpolelt or tb_polgen command lines, reducing the likelyhood
of typos resulting in TXT boot failure.

diff -r dd6d0b5f2fc9 -r e218c239de4b tboot/20_linux_tboot
--- a/tboot/20_linux_tboot	Wed Feb 24 13:44:39 2016 +0100
+++ b/tboot/20_linux_tboot	Wed Feb 24 14:23:07 2016 +0100
@@ -90,6 +90,12 @@
   LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
 fi
 
+# Merge all sequences of spaces into a single space, like GRUB2 does during boot.
+# Simplistic, doesn't check for quoting, but should be good enough for the kernel command line.
+merge_spaces() {
+  echo "$*" | sed -e 's/ \{1,\}/ /g' -e 's/^ //' -e 's/ $//'
+}
+
 linux_entry ()
 {
   os="$1"
@@ -129,11 +135,13 @@
   printf '%s\n' "${prepare_boot_cache}"
   xmessage="$(gettext_printf "Loading tboot %s ..." ${tboot_version})"
   lmessage="$(gettext_printf "Loading Linux %s ..." ${version})"
+  tbargs=`merge_spaces ${rel_tboot_dirname}/${tboot_basename} ${tboot_args}`
+  lxargs=`merge_spaces ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} ${iommu_args} ${mb_extra_kernel}`
   cat << EOF
 	echo	'$xmessage'
-	${mb_directive}	${rel_tboot_dirname}/${tboot_basename} ${rel_tboot_dirname}/${tboot_basename} ${tboot_args}
+	${mb_directive}	${rel_tboot_dirname}/${tboot_basename} ${tbargs}
 	echo	'$lmessage'
-	${mb_mod_directive} ${rel_dirname}/${basename} ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} ${iommu_args} ${mb_extra_kernel}
+	${mb_mod_directive} ${rel_dirname}/${basename} ${lxargs}
 EOF
   if test -n "${initrd}" ; then
     message="$(gettext_printf "Loading initial ramdisk ...")"
diff -r dd6d0b5f2fc9 -r e218c239de4b tboot/20_linux_xen_tboot
--- a/tboot/20_linux_xen_tboot	Wed Feb 24 13:44:39 2016 +0100
+++ b/tboot/20_linux_xen_tboot	Wed Feb 24 14:23:07 2016 +0100
@@ -92,6 +92,12 @@
   fi
 fi
 
+# Merge all sequences of spaces into a single space, like GRUB2 does during boot.
+# Simplistic, doesn't check for quoting, but should be good enough for the kernel command line.
+merge_spaces() {
+  echo "$*" | sed -e 's/ \{1,\}/ /g' -e 's/^ //' -e 's/ $//'
+}
+
 linux_entry ()
 {
   os="$1"
@@ -120,13 +126,16 @@
   xmessage="$(gettext_printf "Loading Xen %s ..." ${xen_version})"
   tmessage="$(gettext_printf "Loading Tboot %s ..." ${tboot_version})"
   lmessage="$(gettext_printf "Loading Linux %s ..." ${version})"
+  tbargs=`merge_spaces ${rel_tboot_dirname}/${tboot_basename} ${tboot_args}`
+  xnargs=`merge_spaces placeholder ${xen_args} ${iommu_args}`
+  lxargs=`merge_spaces placeholder root=${linux_root_device_thisversion} ro ${args}`
   cat << EOF
 	echo	'$tmessage'
-	multiboot	${rel_tboot_dirname}/${tboot_basename} ${rel_tboot_dirname}/${tboot_basename} ${tboot_args}
+	multiboot	${rel_tboot_dirname}/${tboot_basename} ${tbargs}
 	echo	'$xmessage'
-	module	${rel_xen_dirname}/${xen_basename} placeholder ${xen_args} ${iommu_args}
+	module	${rel_xen_dirname}/${xen_basename} ${xnargs}
 	echo	'$lmessage'
-	module	${rel_dirname}/${basename} placeholder root=${linux_root_device_thisversion} ro ${args}
+	module	${rel_dirname}/${basename} ${lxargs}
 EOF
   if test -n "${initrd}" ; then
     message="$(gettext_printf "Loading initial ramdisk ...")"
------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
tboot-devel mailing list
tboot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tboot-devel

Reply via email to