Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sieve :matches fix #3932

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Sieve :matches fix #3932

wants to merge 1 commit into from

Conversation

ksmurchison
Copy link
Contributor

A script like

if header :matches "subject" "\\\\foo" {

was NOT matching

Subject: \foo

The reason was that we were skipping '' regardless of the following character.

Strings in :matches only need to escape '?' and '*' (match explicity against themselves).

If correct, this fix should be backported.

if (*p == '?' || *p == '*') {
/* escaped wildcard character */
c = *p++;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think this is correct. In a match pattern, \ is used to quote any following character, and that is what happens in the original code: the \ in c is replaced by the next character in the pattern, and then it falls through to process it as a verbatim character.

I think there is a small bug here in the original code, though: If the \ is last in the pattern string (e.g., *foo\, c becomes 0, and it will enter the else for "literal char does not match" in the default block. Behaviour is undefined here, ie. the pattern is invalid and probably should throw an error during upload. At least it is good it never returns a successful match.

Copy link

@kjetilho kjetilho Feb 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually - after reading the RFC again, I still think the patch is wrong, but also the existing code.

It can be argued that in a match context only ? and * can be escaped. In other words, "\\a" is \a and also "\\\\" is \\. "\\?" is however just ?.

So - the code should rewind the pointer when the character following \ is not a wildcard.

    if (*p != '?' && *p != '*') {
        c = *--p;
    }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrm. I think my suggested code breaks for "\\\\?", it becomes a literal \ followed by a literal ?, but should be a literal \\ followed by the wildcard ? - I think? Perhaps we need to ask the Sieve mailing list what the correct meaning is.

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.

2 participants