lkml.org 
[lkml]   [2008]   [Dec]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [RFC] globmatch() helper function
From
Date

On Wed, 2008-12-17 at 11:04 -0500, George Spelvin wrote:

>
> The problem is, what if some future thoughtless person feeds user data
> into the pattern argument?
>
> I could just take support for non-trailing * out entirely. That would be
> a different sort of documentation burden.
>
> Or I could just add an explicit 2-level stack. If you overflow the stack,
> matching always fails. Unfortunately, the code will be larger.
>
> Do people think that would be, on balance, better? It would be plenty
> good enough for the blacklist application.

Having a static function do the work and pass in a "depth" parameter
should be sufficient. As Andi mentioned, a depth of 10 should be plenty.

Like this:

static bool
globmatch_internal(const char *pat, const char *str, int depth)
{
if (depth > 10)
return false;

[...]

while (!globmatch_internal(pat+1, str, depth+1))
[...]
}

bool globmatch(const char *pat, const char *str)
{
return globmatch_internal(pat, str, 0);
}

Make sure you include a "Signed-off-by:" as well.

-- Steve




\
 
 \ /
  Last update: 2008-12-17 17:25    [W:0.580 / U:0.404 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site