Blame SOURCES/0187-p2v-Fix-parsing-of-p2v.memory-parameter-RHBZ-1229262.patch

ffd6ed
From 1cfdb89206039d93e5bc203e1d7d4a12077020e3 Mon Sep 17 00:00:00 2001
ffd6ed
From: "Richard W.M. Jones" <rjones@redhat.com>
ffd6ed
Date: Wed, 10 Jun 2015 13:38:11 +0100
ffd6ed
Subject: [PATCH] p2v: Fix parsing of p2v.memory parameter (RHBZ#1229262).
ffd6ed
ffd6ed
The sscanf call always failed because we checked for the wrong return
ffd6ed
code.
ffd6ed
ffd6ed
We don't need to allocate two characters for the mem_code field since
ffd6ed
sscanf doesn't append a nul byte.
ffd6ed
ffd6ed
This commit also allows you to use lowercase 'm' or 'g' as a memory
ffd6ed
unit.
ffd6ed
ffd6ed
Also clarify the documentation: the memory unit must be given.
ffd6ed
ffd6ed
(cherry picked from commit bb5b23c1519a3901909a5ed51ce2f88e0904cb85)
ffd6ed
---
ffd6ed
 p2v/kernel.c     | 12 +++++++-----
ffd6ed
 p2v/virt-p2v.pod |  9 ++++++---
ffd6ed
 2 files changed, 13 insertions(+), 8 deletions(-)
ffd6ed
ffd6ed
diff --git a/p2v/kernel.c b/p2v/kernel.c
ffd6ed
index d7664d5..d9fe50d 100644
ffd6ed
--- a/p2v/kernel.c
ffd6ed
+++ b/p2v/kernel.c
ffd6ed
@@ -104,19 +104,21 @@ kernel_configuration (struct config *config, char **cmdline, int cmdline_source)
ffd6ed
 
ffd6ed
   p = get_cmdline_key (cmdline, "p2v.memory");
ffd6ed
   if (p) {
ffd6ed
-    char mem_code[2];
ffd6ed
+    char mem_code;
ffd6ed
 
ffd6ed
-    if (sscanf (p, "%" SCNu64 "%c", &config->memory, mem_code) != 1) {
ffd6ed
+    if (sscanf (p, "%" SCNu64 "%c", &config->memory, &mem_code) != 2) {
ffd6ed
       fprintf (stderr, "%s: cannot parse p2v.memory from kernel command line\n",
ffd6ed
                guestfs_int_program_name);
ffd6ed
       exit (EXIT_FAILURE);
ffd6ed
     }
ffd6ed
     config->memory *= 1024;
ffd6ed
-    if (mem_code[0] == 'M' || mem_code[0] == 'G')
ffd6ed
+    if (mem_code == 'M' || mem_code == 'm'
ffd6ed
+        || mem_code == 'G' || mem_code == 'g')
ffd6ed
       config->memory *= 1024;
ffd6ed
-    if (mem_code[0] == 'G')
ffd6ed
+    if (mem_code == 'G' || mem_code == 'g')
ffd6ed
       config->memory *= 1024;
ffd6ed
-    if (mem_code[0] != 'M' && mem_code[0] != 'G') {
ffd6ed
+    if (mem_code != 'M' && mem_code != 'm'
ffd6ed
+        && mem_code != 'G' && mem_code != 'g') {
ffd6ed
       fprintf (stderr, "%s: p2v.memory on kernel command line must be followed by 'G' or 'M'\n",
ffd6ed
                guestfs_int_program_name);
ffd6ed
       exit (EXIT_FAILURE);
ffd6ed
diff --git a/p2v/virt-p2v.pod b/p2v/virt-p2v.pod
ffd6ed
index dd44a1c..a70b39c 100644
ffd6ed
--- a/p2v/virt-p2v.pod
ffd6ed
+++ b/p2v/virt-p2v.pod
ffd6ed
@@ -342,9 +342,12 @@ use the same as the number of physical CPUs.
ffd6ed
 
ffd6ed
 =item B<p2v.memory=NN(M|G)>
ffd6ed
 
ffd6ed
-The size of the guest memory.  You can specify this in megabytes or
ffd6ed
-gigabytes by using (eg) C<p2v.memory=1024M> or C<p2v.memory=1G>.  The
ffd6ed
-default is to use the same amount of RAM as on the physical machine.
ffd6ed
+The size of the guest memory.  You must specify the unit as either
ffd6ed
+megabytes or gigabytes by using (eg) C<p2v.memory=1024M> or
ffd6ed
+C<p2v.memory=1G>.
ffd6ed
+
ffd6ed
+The default is to use the same amount of RAM as on the physical
ffd6ed
+machine.
ffd6ed
 
ffd6ed
 =item B<p2v.debug>
ffd6ed
 
ffd6ed
-- 
ffd6ed
1.8.3.1
ffd6ed