lkml.org 
[lkml]   [1998]   [May]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: 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

\
 
 \ /
  Last update: 2005-03-22 13:42    [W:0.041 / U:0.060 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site