lkml.org 
[lkml]   [2018]   [Dec]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v4] string.h: Add str_has_prefix() helper function
On Sat, 22 Dec 2018 10:12:44 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:

> On Sat, 22 Dec 2018 23:24:11 +0900
> Namhyung Kim <namhyung@kernel.org> wrote:
>
> > > No, because we don't know the length of str.
> > >
> > >
> > > [ str = "h\0[bad memory]" ]


> >
> > I don't know what's the bad memory causing memory fault but anyway

What I meant by that is if a string is allocated at a end of a page,
and the next page is marked as not present. A read into that page will
cause a page fault, and since memcmp() does not stop at the '\0' it
will read into that not-present memory and trigger a fault, and that
read wont be in the exception table, and it will then BUG.

> > memcpy() should stop at the NUL character first as it's different, no?
>
> No, that's the difference between memcpy() and strncpy(), memcpy()
> doesn't care about nul characters. It's copying memory not strings.

I think we both meant s/cpy/cmp/ ;-)

-- Steve

\
 
 \ /
  Last update: 2018-12-22 18:03    [W:0.908 / U:0.908 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site