On 3/26/19 7:18 PM, M A Young wrote:
> On Tue, 26 Mar 2019, Wei Liu wrote:
> 
>> On Tue, Mar 26, 2019 at 01:16:35PM +0000, Wei Liu wrote:
>>> On Mon, Mar 25, 2019 at 10:20:05PM +0000, YOUNG, MICHAEL A. wrote:
>>>>          if ty.init_fn is not None:
>>>> --- xen-4.12.0-rc6/tools/pygrub/src/GrubConf.py.orig       2019-03-24 
>>>> 22:44:05.502581989 +0000
>>>> +++ xen-4.12.0-rc6/tools/pygrub/src/GrubConf.py    2019-03-24 
>>>> 22:49:14.025934786 +0000
>>>> @@ -230,10 +230,10 @@
>>>>      def _get_default(self):
>>>>          return self._default
>>>>      def _set_default(self, val):
>>>> -        if val == "saved":
>>>> +        if val == "saved" or not val.isdecimal():
>>
>> Your change suggested there could be a non-decimal string that is not
>> "saved" -- is this really needed?
> 
> It is getting set to ${next_entry} presumably from the clause 
> 
> if [ "${next_entry}" ] ; then
>    set default="${next_entry}"
>    set next_entry=
>    save_env next_entry
>    set boot_once=true
> else
>    set default="${saved_entry}"
> fi
> 
> in the grub.cfg file giving the error
> 
>   File "/usr/lib64/python3.7/site-packages/grub/GrubConf.py", line 239, in 
> _set_default
>     if self._default < 0:
> TypeError: '<' not supported between instances of 'str' and 'int'
> 
> I didn't see this with python 2 before the patch so I assume python3 is 
> more fussy.

Comparison is also used for sorting.

In Python 2, numeric values always sort before strings. So, for example:

== sorted(['a','b','c', 1, 2, 3])
[1, 2, 3, 'a', 'b', 'c']

However, this behavior also easily leads to bugs, for example when
someone forgets to convert strings that hold numeric values to actual
numbers and still compares things, which silently introduces unintended
behavior.

So, the above if self._default < 0 will just always be False if
self._default is a string. I didn't read the context of these lines, but
this looks like an actual bug currently.

Python 3 no longer allows comparing string and int, because it doesn't
make sense.

== sorted([1,2,3,'a','b','c'])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: str() < int()

So I guess that if the contents are expected to be "saved" or a number
as string like "1", "2", then:

1. check for "saved"
2. try: int(val) except: blah
3. etc

Also, python 2 does not have isdecimal() on strings.

Hans

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

Reply via email to