Skip to content

ignore: fix determining whether a shorter pattern negates another - #5173

Merged
ethomson merged 1 commit into
libgit2:masterfrom
pks-t:pks/gitignore-wildmatch-error
Jul 20, 2019
Merged

ignore: fix determining whether a shorter pattern negates another#5173
ethomson merged 1 commit into
libgit2:masterfrom
pks-t:pks/gitignore-wildmatch-error

Conversation

@pks-t

@pks-t pks-t commented Jul 18, 2019

Copy link
Copy Markdown
Member

When computing whether we need to store a negative pattern, we iterate
through all previously known patterns and check whether the negative
pattern undoes any of the previous ones. In doing so we call wildmatch
and check it's return for any negative error values. If there was a
negative return, we will abort and bubble up that error to the caller.

In fact, this check for negative values stems from the time where we
still used fnmatch instead of wildmatch. For fnmatch, negative
values indicate a "real" error, while for wildmatch a negative value
may be returned if the matching was prematurely aborted. A premature
abort may for example also happen if the pattern matches a prefix of the
haystack if the pattern is shorter. Returning an error in that case is
the wrong thing to do.

Fix the code to compare for equality with WM_MATCH, only. Negative
values returned by wildmatch are perfectly fine and thus should be
ignored. Add a test that verifies we do not see the error.


I've skimmed through the tree to see whether there's any other places where we fail to use wildmatch correctly. The only place that struck me was when matching pathspecs, but I failed to come up with any breaking pattern. I think this one is fine, as WM_ABORT_* is only returned if the text is a prefix of the pattern. And as we're swallowing all negative values up the callchain we should be good.

Fixes #5166

When computing whether we need to store a negative pattern, we iterate
through all previously known patterns and check whether the negative
pattern undoes any of the previous ones. In doing so we call `wildmatch`
and check it's return for any negative error values. If there was a
negative return, we will abort and bubble up that error to the caller.

In fact, this check for negative values stems from the time where we
still used `fnmatch` instead of `wildmatch`. For `fnmatch`, negative
values indicate a "real" error, while for `wildmatch` a negative value
may be returned if the matching was prematurely aborted. A premature
abort may for example also happen if the pattern matches a prefix of the
haystack if the pattern is shorter. Returning an error in that case is
the wrong thing to do.

Fix the code to compare for equality with `WM_MATCH`, only. Negative
values returned by `wildmatch` are perfectly fine and thus should be
ignored. Add a test that verifies we do not see the error.
@ethomson
ethomson merged commit e07dbc9 into libgit2:master Jul 20, 2019
@pks-t
pks-t deleted the pks/gitignore-wildmatch-error branch July 20, 2019 16:38
@andreacanton

Copy link
Copy Markdown

Hi everyone, somebody knows when this fix will be released?
Thank you

@pks-t

pks-t commented Aug 8, 2019

Copy link
Copy Markdown
Member Author

We do not yet have any schedule for the next releases. Given that it has been nearly three months since doing the last bugfix release I'd be up to prepare one towards the end of this month.

@pks-t

pks-t commented Aug 8, 2019

Copy link
Copy Markdown
Member Author

With that being said, though, this only fixes an issue that has been introduced with the conversion to wildmatch, and in fact there is no release with the wildmatch code yet. So there is no need to backport this PR anyway

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.

status: git_status_list_new errors on does_negate_rule

3 participants