]> xenbits.xensource.com Git - people/dariof/xen.git/commitdiff
pygrub/grub: always use integer for default entry
authorWei Liu <wei.liu2@citrix.com>
Mon, 1 Apr 2019 10:32:36 +0000 (11:32 +0100)
committerWei Liu <wei.liu2@citrix.com>
Tue, 2 Apr 2019 08:47:38 +0000 (09:47 +0100)
The original code set the default to either a string or an integer
(0) and relies on a Python 2 specific behaviour to work (integer is
allowed to be compared to string in Python 2 but not 3).

Always use integer. The caller (pygrub) already has code to handle
that.

Reported-by: M A Young <m.a.young@durham.ac.uk>
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
tools/pygrub/src/GrubConf.py

index 0204d410acbc08a385166745cf0a183ded909dbc..594139bac736995f987abd93fd4f15f9103d37f4 100644 (file)
@@ -233,7 +233,11 @@ class _GrubConfigFile(object):
         if val == "saved":
             self._default = 0
         else:
-            self._default = val
+            try:
+                self._default = int(val)
+            except ValueError:
+                logging.warning("Invalid value %s, setting default to 0" %(val,))
+                self._default = 0
 
         if self._default < 0:
             raise ValueError("default must be non-negative number")