chiark / gitweb /
[PATCH] fix possible buffer overflow
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>
Thu, 29 Jan 2004 03:00:51 +0000 (19:00 -0800)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 04:13:20 +0000 (21:13 -0700)
commit8a08e4b1906eef5d5cb585b125612cce8d565e5c
treeef577b437aa6c98efd7b2795ff271553cb49f8d2
parentbc59f0167a03be2d2e4cf8a680dda8444243c64f
[PATCH] fix possible buffer overflow

On Tue, Jan 27, 2004 at 11:02:25AM -0800, Greg KH wrote:
> On Mon, Jan 26, 2004 at 07:28:03PM -0500, Adrian Drzewiecki wrote:
> > Looking over the code, I noticed something odd in
> > namedev.c:strcmp_pattern() --
> >
> >  while (*p && (*p != ']'))
> >  p ++;
> >  return strcmp_pattern(p+1, s+1);
> >
> > If the pattern string is invalid, and is not terminated by a ']', then 'p'
> > will point at \0 and p+1 will be beyond the string.
>
> Yes, I think you are correct.
>
> Hm, Kay, any idea of the proper way to fix this?  I've attached a patch
> below, but I don't think it is correct.
>
>   while (*p && (*p != ']'))
>   p++;
> - return strcmp_pattern(p+1, s+1);
> + if (*p)
> + return strcmp_pattern(p+1, s+1);
> + else
> + return 1;
>   }
>   }

Sure, it's perfectly correct. I'm wondering how Adrian found this.

We can use the return 1 at the end of the whole function, and asking
for the closing ']' is more descriptive, but it does the same.

- return strcmp_pattern(p+1, s+1);
+ if (*p == ']')
+ return strcmp_pattern(p+1, s+1);

Patch is attached, that also replaces all the *s with s[0].
namedev.c