* [PATCH] Avoid potential NULL deref in scripts/genksyms/lex.l
@ 2007-06-24 21:40 Jesper Juhl
2007-06-24 21:58 ` Andrew Morton
0 siblings, 1 reply; 5+ messages in thread
From: Jesper Juhl @ 2007-06-24 21:40 UTC (permalink / raw)
To: Richard Henderson; +Cc: Linux Kernel Mailing List, Andrew Morton, Jesper Juhl
strchr() returns NULL in case the string is not found and if that
happens we risk dereferencing a NULL pointer. It never hurts to
check for that condition and exit normally with an error rather
than crashing.
(no, the indentation is not according to CodingStyle, it's simply
following whatever else is in that file)
Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
---
scripts/genksyms/lex.l | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/scripts/genksyms/lex.l b/scripts/genksyms/lex.l
index 5e544a0..28edc0c 100644
--- a/scripts/genksyms/lex.l
+++ b/scripts/genksyms/lex.l
@@ -154,6 +154,8 @@ repeat:
file = strchr(yytext, '\"')+1;
e = strchr(file, '\"');
+ if (!file || !e)
+ exit(1);
*e = '\0';
cur_filename = memcpy(xmalloc(e-file+1), file, e-file+1);
cur_line = atoi(yytext+2);
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] Avoid potential NULL deref in scripts/genksyms/lex.l
2007-06-24 21:40 [PATCH] Avoid potential NULL deref in scripts/genksyms/lex.l Jesper Juhl
@ 2007-06-24 21:58 ` Andrew Morton
2007-06-24 22:02 ` Jesper Juhl
0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2007-06-24 21:58 UTC (permalink / raw)
To: Jesper Juhl; +Cc: Richard Henderson, Linux Kernel Mailing List
On Sun, 24 Jun 2007 23:40:03 +0200 Jesper Juhl <jesper.juhl@gmail.com> wrote:
> strchr() returns NULL in case the string is not found and if that
> happens we risk dereferencing a NULL pointer. It never hurts to
> check for that condition and exit normally with an error rather
> than crashing.
>
> (no, the indentation is not according to CodingStyle, it's simply
> following whatever else is in that file)
>
>
> Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
> ---
>
> scripts/genksyms/lex.l | 2 ++
> 1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/scripts/genksyms/lex.l b/scripts/genksyms/lex.l
> index 5e544a0..28edc0c 100644
> --- a/scripts/genksyms/lex.l
> +++ b/scripts/genksyms/lex.l
> @@ -154,6 +154,8 @@ repeat:
>
> file = strchr(yytext, '\"')+1;
> e = strchr(file, '\"');
If `file' can be null we'd have oopsed here.
> + if (!file || !e)
> + exit(1);
> *e = '\0';
> cur_filename = memcpy(xmalloc(e-file+1), file, e-file+1);
> cur_line = atoi(yytext+2);
I don't think the bug which you're fixing can occur:
^#[ \t]+{INT}[ \t]+\"[^\"\n]+\".*\n return FILENAME;
has anyone reported crashes in there?
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] Avoid potential NULL deref in scripts/genksyms/lex.l
2007-06-24 21:58 ` Andrew Morton
@ 2007-06-24 22:02 ` Jesper Juhl
2007-06-24 23:00 ` Andrew Morton
0 siblings, 1 reply; 5+ messages in thread
From: Jesper Juhl @ 2007-06-24 22:02 UTC (permalink / raw)
To: Andrew Morton; +Cc: Richard Henderson, Linux Kernel Mailing List
On 24/06/07, Andrew Morton <akpm@linux-foundation.org> wrote:
> On Sun, 24 Jun 2007 23:40:03 +0200 Jesper Juhl <jesper.juhl@gmail.com> wrote:
>
> > strchr() returns NULL in case the string is not found and if that
> > happens we risk dereferencing a NULL pointer. It never hurts to
> > check for that condition and exit normally with an error rather
> > than crashing.
> >
> > (no, the indentation is not according to CodingStyle, it's simply
> > following whatever else is in that file)
> >
> >
> > Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
> > ---
> >
> > scripts/genksyms/lex.l | 2 ++
> > 1 files changed, 2 insertions(+), 0 deletions(-)
> >
> > diff --git a/scripts/genksyms/lex.l b/scripts/genksyms/lex.l
> > index 5e544a0..28edc0c 100644
> > --- a/scripts/genksyms/lex.l
> > +++ b/scripts/genksyms/lex.l
> > @@ -154,6 +154,8 @@ repeat:
> >
> > file = strchr(yytext, '\"')+1;
> > e = strchr(file, '\"');
>
> If `file' can be null we'd have oopsed here.
>
> > + if (!file || !e)
> > + exit(1);
> > *e = '\0';
> > cur_filename = memcpy(xmalloc(e-file+1), file, e-file+1);
> > cur_line = atoi(yytext+2);
>
> I don't think the bug which you're fixing can occur:
>
> ^#[ \t]+{INT}[ \t]+\"[^\"\n]+\".*\n return FILENAME;
>
> has anyone reported crashes in there?
>
It may indeed not be possible. Found by inspection, not by any actual
observed crashes.
But does it really hurt to be defensive here? In case it can somehow
be caused to fail, with my patch it'll fail a bit nicer :) It's not
like it's at all speed critical code that will be hurt by that extra
'if'...
--
Jesper Juhl <jesper.juhl@gmail.com>
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.expita.com/nomime.html
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] Avoid potential NULL deref in scripts/genksyms/lex.l
2007-06-24 22:02 ` Jesper Juhl
@ 2007-06-24 23:00 ` Andrew Morton
2007-06-24 23:08 ` Jesper Juhl
0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2007-06-24 23:00 UTC (permalink / raw)
To: Jesper Juhl; +Cc: Richard Henderson, Linux Kernel Mailing List
On Mon, 25 Jun 2007 00:02:03 +0200 "Jesper Juhl" <jesper.juhl@gmail.com> wrote:
> > > + if (!file || !e)
> > > + exit(1);
> > > *e = '\0';
> > > cur_filename = memcpy(xmalloc(e-file+1), file, e-file+1);
> > > cur_line = atoi(yytext+2);
> >
> > I don't think the bug which you're fixing can occur:
> >
> > ^#[ \t]+{INT}[ \t]+\"[^\"\n]+\".*\n return FILENAME;
> >
> > has anyone reported crashes in there?
> >
>
> It may indeed not be possible. Found by inspection, not by any actual
> observed crashes.
> But does it really hurt to be defensive here? In case it can somehow
> be caused to fail, with my patch it'll fail a bit nicer :) It's not
> like it's at all speed critical code that will be hurt by that extra
> 'if'...
We can only get NULL pointers here if the regexp is wrong or if there's
a bug in the regexp parser. Getting a coredump at the failure site is
much better behaviour than mysteriously exiting.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] Avoid potential NULL deref in scripts/genksyms/lex.l
2007-06-24 23:00 ` Andrew Morton
@ 2007-06-24 23:08 ` Jesper Juhl
0 siblings, 0 replies; 5+ messages in thread
From: Jesper Juhl @ 2007-06-24 23:08 UTC (permalink / raw)
To: Andrew Morton; +Cc: Richard Henderson, Linux Kernel Mailing List
On 25/06/07, Andrew Morton <akpm@linux-foundation.org> wrote:
> On Mon, 25 Jun 2007 00:02:03 +0200 "Jesper Juhl" <jesper.juhl@gmail.com> wrote:
>
> > > > + if (!file || !e)
> > > > + exit(1);
> > > > *e = '\0';
> > > > cur_filename = memcpy(xmalloc(e-file+1), file, e-file+1);
> > > > cur_line = atoi(yytext+2);
> > >
> > > I don't think the bug which you're fixing can occur:
> > >
> > > ^#[ \t]+{INT}[ \t]+\"[^\"\n]+\".*\n return FILENAME;
> > >
> > > has anyone reported crashes in there?
> > >
> >
> > It may indeed not be possible. Found by inspection, not by any actual
> > observed crashes.
> > But does it really hurt to be defensive here? In case it can somehow
> > be caused to fail, with my patch it'll fail a bit nicer :) It's not
> > like it's at all speed critical code that will be hurt by that extra
> > 'if'...
>
> We can only get NULL pointers here if the regexp is wrong or if there's
> a bug in the regexp parser. Getting a coredump at the failure site is
> much better behaviour than mysteriously exiting.
>
Fair enough. Just ignore the patch then :-)
--
Jesper Juhl <jesper.juhl@gmail.com>
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.expita.com/nomime.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-06-24 23:08 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-24 21:40 [PATCH] Avoid potential NULL deref in scripts/genksyms/lex.l Jesper Juhl
2007-06-24 21:58 ` Andrew Morton
2007-06-24 22:02 ` Jesper Juhl
2007-06-24 23:00 ` Andrew Morton
2007-06-24 23:08 ` Jesper Juhl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®