Bug #1399

fnmatch(3) escapes '0' to '\'

Added by Beket almost 5 years ago. Updated almost 5 years ago.

Status:NewStart date:
Priority:NormalDue date:
Assignee:Beket% Done:

0%

Category:-
Target version:-

Description

Salute.

Suppose that we supply fnmatch(3) with a pattern of the form "\" (that is '\'
followed by '0') without setting the FNM_NOESCAPE flag. Wouldn't the normal
thing to do is escape the terminating character and return just '0' ? Instead
'\' is returned. As if one has provided a pattern "\\".

This behavior is exhibited by NetBSD 5.0_STABLE, FreeBSD 7.2-RELEASE and
DragonFlyBSD HEAD.

On the other side sunOS 5.10 and Linux with a relatively recent glibc translate
the pattern to '0'.

You can check with the following snippet:

#include <assert.h>
#include <fnmatch.h>
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
int rv;

rv = fnmatch(/* pattern */ "\\", "\\", 0);
assert(rv == FNM_NOMATCH);

printf("passed\n");

return (EXIT_SUCCESS)
}

I've looked into the specs but couldn't find anything relevant.
Any thoughts ?

Cheers,
Stathis

fnmatch-3-Properly-escape-the-terminating-characte.patch Magnifier (769 Bytes) Beket, 06/10/2009 07:24 PM

History

#1 Updated by corecode almost 5 years ago

Stathis Kamperis (via DragonFly issue tracker) wrote:
> Suppose that we supply fnmatch(3) with a pattern of the form "\" (that is '\'
> followed by '0') without setting the FNM_NOESCAPE flag. Wouldn't the normal
> thing to do is escape the terminating character and return just '0' ? Instead
> '\' is returned. As if one has provided a pattern "\\".

I guess that also happens for any other trailing \. In this case I'd keep
the current behavior, because I'd expect more the \ to be used, than it to
just disappear.

cheers
simon

#2 Updated by Beket almost 5 years ago

>> Suppose that we supply fnmatch(3) with a pattern of the form "\" (that is '\'
>> followed by '0') without setting the FNM_NOESCAPE flag. Wouldn't the normal
>> thing to do is escape the terminating character and return just '0' ? Instead
>> '\' is returned. As if one has provided a pattern "\\".
> I guess that also happens for any other trailing \. In this case I'd keep
> the current behavior, because I'd expect more the \ to be used, than it to
> just disappear.
It happens only with the last \ before '0'. But what bugs me most, is that it
escapes it while we are in non-escape mode (FNM_NOESCAPE flag set).

Cheers,
Stathis

#3 Updated by Beket almost 5 years ago

> It happens only with the last \ before '0'. But what bugs me most, is that it
> escapes it while we are in non-escape mode (FNM_NOESCAPE flag set).
I take it back. It only happens in escape mode.

Cheers,
Stathis

Also available in: Atom PDF