[PATCH STABLE] templater: protect word() from crashing on out of range negative value

Pierre-Yves David pierre-yves.david at ens-lyon.org
Wed Oct 7 14:05:14 CDT 2015



On 10/07/2015 05:22 AM, Yuya Nishihara wrote:
> On Tue, 06 Oct 2015 15:43:26 -0700, Pierre-Yves David wrote:
>> On 10/05/2015 09:45 AM, Matt Harbison wrote:
>>> # HG changeset patch
>>> # User Matt Harbison <matt_harbison at yahoo.com>
>>> # Date 1444063046 14400
>>> #      Mon Oct 05 12:37:26 2015 -0400
>>> # Branch stable
>>> # Node ID 05972c639f5fdb09048d2f4de2397ba29ce8427a
>>> # Parent  93bfa9fc96e31f1cc5f444bdc2436966c665cf1f
>>> templater: protect word() from crashing on out of range negative value
>>>
>>> The function isn't documented to work with negative values at all, but it does,
>>> which can be useful.  However, the range check didn't account for this.
>
>>> -    if num >= len(tokens):
>>> +    if abs(num) >= len(tokens):
>
> Off-by-one error? Negative index should be inclusive.
>
> I think catching IndexError would be less error-prone.

snap, +1 for IndexError


-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list