X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmetadata%2Ffile-mmap-posix.c;h=4b9ce74499e04ec81a5b1ad1e422615d7c44636b;hb=4c960e1dd530396fdd9400c87729a6ce3101e5c1;hp=84e3b4aa68d75000fbec036787887c36f1fe8930;hpb=7f51d473ef1a8bcb08ba488cb35500445a501b39;p=mono.git diff --git a/mono/metadata/file-mmap-posix.c b/mono/metadata/file-mmap-posix.c index 84e3b4aa68d..4b9ce74499e 100644 --- a/mono/metadata/file-mmap-posix.c +++ b/mono/metadata/file-mmap-posix.c @@ -63,7 +63,9 @@ enum { COULD_NOT_OPEN, CAPACITY_MUST_BE_POSITIVE, INVALID_FILE_MODE, - COULD_NOT_MAP_MEMORY + COULD_NOT_MAP_MEMORY, + ACCESS_DENIED, + CAPACITY_LARGER_THAN_LOGICAL_ADDRESS_SPACE }; enum { @@ -300,10 +302,16 @@ static void* open_memory_map (const char *c_mapName, int mode, gint64 *capacity, int access, int options, int *ioerror) { MmapHandle *handle; - if (*capacity <= 1) { + if (*capacity <= 0) { *ioerror = CAPACITY_MUST_BE_POSITIVE; return NULL; } +#if SIZEOF_VOID_P == 4 + if (*capacity > UINT32_MAX) { + *ioerror = CAPACITY_LARGER_THAN_LOGICAL_ADDRESS_SPACE; + return NULL; + } +#endif if (!(mode == FILE_MODE_CREATE_NEW || mode == FILE_MODE_OPEN_OR_CREATE || mode == FILE_MODE_OPEN)) { *ioerror = INVALID_FILE_MODE; @@ -499,8 +507,11 @@ mono_mmap_map (void *handle, gint64 offset, gint64 *size, int access, void **mma struct stat buf = { 0 }; fstat (fh->fd, &buf); //FIXME error handling + *mmap_handle = NULL; + *base_address = NULL; + if (offset > buf.st_size || ((eff_size + offset) > buf.st_size && !is_special_zero_size_file (&buf))) - goto error; + return ACCESS_DENIED; /** * We use the file size if one of the following conditions is true: * -input size is zero @@ -522,9 +533,6 @@ mono_mmap_map (void *handle, gint64 offset, gint64 *size, int access, void **mma return 0; } -error: - *mmap_handle = NULL; - *base_address = NULL; return COULD_NOT_MAP_MEMORY; }