xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Wei Liu <wei.liu2@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Ian Jackson <ian.jackson@eu.citrix.com>,
	Wei Liu <wei.liu2@citrix.com>,
	m.a.young@durham.ac.uk
Subject: [PATCH 2/4] pygrub/grub: always use integer for default entry
Date: Mon, 1 Apr 2019 11:32:36 +0100	[thread overview]
Message-ID: <20190401103238.15649-3-wei.liu2@citrix.com> (raw)
In-Reply-To: <20190401103238.15649-1-wei.liu2@citrix.com>

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>
---
 tools/pygrub/src/GrubConf.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tools/pygrub/src/GrubConf.py b/tools/pygrub/src/GrubConf.py
index 0204d410ac..594139bac7 100644
--- a/tools/pygrub/src/GrubConf.py
+++ b/tools/pygrub/src/GrubConf.py
@@ -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")
-- 
2.20.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2019-04-01 10:32 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-01 10:32 [PATCH 0/4] More python fixes Wei Liu
2019-04-01 10:32 ` [PATCH 1/4] pygrub: fix message in grub parser Wei Liu
2019-04-01 16:16   ` Andrew Cooper
2019-04-01 10:32 ` Wei Liu [this message]
2019-04-01 16:20   ` [PATCH 2/4] pygrub/grub: always use integer for default entry Andrew Cooper
2019-04-01 10:32 ` [PATCH 3/4] pygrub: decode string in Python 3 Wei Liu
2019-04-01 16:21   ` Andrew Cooper
2019-04-01 10:32 ` [PATCH 4/4] tools/ocaml: make python scripts 2 and 3 compatible Wei Liu
2019-04-01 16:22   ` Andrew Cooper
2019-04-01 16:24   ` Christian Lindig
2019-04-01 20:36 ` [PATCH 0/4] More python fixes YOUNG, MICHAEL A.
2019-04-02  8:18   ` Wei Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190401103238.15649-3-wei.liu2@citrix.com \
    --to=wei.liu2@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=m.a.young@durham.ac.uk \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).