[Ocfs2-test-devel] [PATCH 42/59] mmap-test: fix segment fault

Eric Ren zren at suse.com
Sat Oct 10 00:23:33 PDT 2015


Hi Junxiao,

> 4. How to fix
> =============
> Frist,this line of code:
> ptr = buf + (stat_buf.st_size - offset);
> should be changed to
> ptr = buf + (stat_buf.st_size - offset -1);

It's wrong! -1 make ptr point to the end of mapping page, but it should
point to the start of the last mapping page.

Sorry, this's not neccessary.

Thanks,
Eric

> 
> Then, when offset==0, the rest of code actually doesn't make any sense. Could we just
> return, or output the last whole page?
> 
> Thanks,
> Eric
> 
> On Mon, Sep 14, 2015 at 10:44:28AM +0800, Junxiao Bi wrote: 
> > When test file size is multiple of page size, there will be write out of
> > mmap range and cause segment fault.
> > 
> > Signed-off-by: Junxiao Bi <junxiao.bi at oracle.com>
> > ---
> >  programs/mmap_test/mmap_test.c |    8 ++++++++
> >  1 file changed, 8 insertions(+)
> > 
> > diff --git a/programs/mmap_test/mmap_test.c b/programs/mmap_test/mmap_test.c
> > index 9edbb58..711bb81 100644
> > --- a/programs/mmap_test/mmap_test.c
> > +++ b/programs/mmap_test/mmap_test.c
> > @@ -80,6 +80,14 @@ int main(int argc, char *argv[])
> >      }
> >  
> >      offset = stat_buf.st_size % page_size;
> > +
> > +    /* fix offset if the file size is multiple of page size */
> > +    if (offset == 0)
> > +	    offset = page_size;
> > +
> > +    if (offset > stat_buf.st_size)
> > +	    offset = stat_buf.st_size;
> > +
> >      ptr = buf + (stat_buf.st_size - offset);
> >      remain = page_size - offset;
> >  
> > -- 
> > 1.7.9.5
> > 
> > 
> > _______________________________________________
> > Ocfs2-test-devel mailing list
> > Ocfs2-test-devel at oss.oracle.com
> > https://oss.oracle.com/mailman/listinfo/ocfs2-test-devel
> > 
> 
> _______________________________________________
> Ocfs2-test-devel mailing list
> Ocfs2-test-devel at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/ocfs2-test-devel
> 



More information about the Ocfs2-test-devel mailing list