From patchwork Mon Apr 1 10:32:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 10879667 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8C39815AC for ; Mon, 1 Apr 2019 10:34:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 770FD286A9 for ; Mon, 1 Apr 2019 10:34:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6AB37287D4; Mon, 1 Apr 2019 10:34:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CA01B286A9 for ; Mon, 1 Apr 2019 10:34:50 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hAuFO-0008Lc-4Y; Mon, 01 Apr 2019 10:32:58 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hAuFM-0008Jr-B5 for xen-devel@lists.xenproject.org; Mon, 01 Apr 2019 10:32:56 +0000 X-Inumbo-ID: 825f0c26-5469-11e9-bc90-bc764e045a96 Received: from SMTP03.CITRIX.COM (unknown [162.221.156.55]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 825f0c26-5469-11e9-bc90-bc764e045a96; Mon, 01 Apr 2019 10:32:54 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.60,296,1549929600"; d="scan'208";a="82363718" From: Wei Liu To: Date: Mon, 1 Apr 2019 11:32:36 +0100 Message-ID: <20190401103238.15649-3-wei.liu2@citrix.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190401103238.15649-1-wei.liu2@citrix.com> References: <20190401103238.15649-1-wei.liu2@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 2/4] pygrub/grub: always use integer for default entry X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , Wei Liu , m.a.young@durham.ac.uk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Signed-off-by: Wei Liu Acked-by: Andrew Cooper --- 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")