[PATCHES] Some fixes in s4/scripting/upgradeprovision

Noel Power nopower at suse.com
Fri Oct 12 06:51:48 UTC 2018


On 12/10/2018 03:21, Douglas Bagnall wrote:
> On 12/10/18 12:47, Douglas Bagnall via samba-technical wrote:
>> On 11/10/18 21:24, Noel Power wrote:
>>> -            if (long(str(old[0][att])) == 0):
>>> +            if (int(str(old[0][att])) == 0):
>>>
>>>
>>> very minor nitpick, we should do
>>>
>>> -            if (long(str(old[0][att])) == 0):
>>> +            if (int(old[0][att]) == 0):
>>>
>>> and remove the attempt to convert to str because it could cause a
>>> UnicodeDecode error rather than a desired ValueError if the attribute
>>> value is not a valid string/byte/bytearray representation of a number. I
>>> don't think anyone is filtering any particular exceptions here so
>>> probably not a real issue with this piece of code perse
>> A good point. There are a few other cases in that file so I have made
>> another patch as attached.
> Ah, but it won't work, at least not in the form of my patch:
>
> Traceback (most recent call last):
>    File "/tmp/samba-testbase/b17/samba-none-env/bin/samba_upgradeprovision", line 1702, in <module>
>      minUSN = int(get_max_usn(ldbs.sam, str(names.rootdn))) + 1
> TypeError: int() argument must be a string or a number, not 'ldb.MessageElement'

you are right, sorry

str(ldb.MessageElement) is actually returning ldb.MessageElement[0] 
(converted to python string by c library)

so probably better is

+if (int(old[0][att][0]))

as str(old[0][att]) incurs the same risk of unexpected decode error


Noel




More information about the samba-technical mailing list