Messages in this thread | | | Date | Fri, 29 May 1998 12:07:12 -0700 (PDT) | From | Dean Gaudet <> | Subject | Re: mmap bug? |
| |
On Fri, 29 May 1998, Matthew Kirkwood wrote:
> On Fri, 29 May 1998, Natarajan Krishnaswami wrote: > > > [someone] wrote: > > >> It seems that attempts to mmap a region of size zero causes > > >> mmap to return zero. Is this a bug? > > >> > > >> Since it doesn't return -1, it looks like success, but of > > >> course dereferencing this NULL pointer causes a crash. > > > > Zero is a multiple of the page size, so there is no partial page mapped: > > the map is empty. Returning a pointer which may not be dereferenced > > seems reasonable. However, mmap is explicitly forbidden from returning > > 0, and SIGBUS would probably be the correct signal to deliver if an > > address in a 0-length map were dereferenced. > > Thank you. > > I was surprised at the number of people prepared to tell me not to > mmap zero length areas. Here's a trivial patch to fix this, although > I don't know if this will affect many programs.
I'm surprised that you never answered the important question: If you're mapping 0 bytes then how the hell do you get a SEGV? You shouldn't be referencing anything at the address. Your program is at fault as much or more than linux. (I can't find a reference which claims that 0 is not a valid response.)
Dean
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu
| |