Skip to content

sha1_position: convert do-while to while#4326

Merged
ethomson merged 1 commit intomasterfrom
peff/binary-search-do-while
Aug 14, 2017
Merged

sha1_position: convert do-while to while#4326
ethomson merged 1 commit intomasterfrom
peff/binary-search-do-while

Conversation

@peff
Copy link
Copy Markdown
Member

@peff peff commented Aug 9, 2017

If we enter the sha1_position() function with "lo == hi", we have no elements. But the do-while loop means that we'll enter the loop body once anyway, picking "mi" at that same value and comparing nonsense to our desired key. This is unlikely to match in practice, but we still shouldn't be looking at the memory in the first place.

This bug is inherited from git.git; it was fixed there in git/git@e01580c.

If we enter the sha1_position() function with "lo == hi",
we have no elements. But the do-while loop means that we'll
enter the loop body once anyway, picking "mi" at that same
value and comparing nonsense to our desired key. This is
unlikely to match in practice, but we still shouldn't be
looking at the memory in the first place.

This bug is inherited from git.git; it was fixed there in
e01580cfe01526ec2c4eb4899f776a82ade7e0e1.
@ethomson
Copy link
Copy Markdown
Member

Thanks!

@ethomson ethomson merged commit e536fa3 into master Aug 14, 2017
@peff peff deleted the peff/binary-search-do-while branch August 14, 2017 21:03
@pks-t pks-t added the backport label Jan 11, 2018
@pks-t pks-t mentioned this pull request Jan 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants