Messages in this thread Patch in this message | | | Date | Fri, 29 May 1998 19:50:26 +0100 (BST) | From | Matthew Kirkwood <> | Subject | Re: mmap bug? |
| |
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.
--- mm/mmap.c.old Fri May 29 19:48:18 1998 +++ mm/mmap.c Fri May 29 19:48:45 1998 @@ -165,7 +165,7 @@ int correct_wcount = 0, error; if ((len = PAGE_ALIGN(len)) == 0) - return addr; + return -ENXIO; if (len > TASK_SIZE || addr > TASK_SIZE-len) return -EINVAL; Cheers, Matthew.
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu
| |