From: mortenp Date: Thu, 30 Oct 2008 19:13:09 +0000 (+1100) Subject: Fixed mmap()ing of zero-sized files (Robin H. Johnson) X-Git-Tag: RELEASE_1_2_16~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8082f304eff653d83e7e0f16358b23ea10954154;p=thirdparty%2Fmlmmj.git Fixed mmap()ing of zero-sized files (Robin H. Johnson) --- diff --git a/ChangeLog b/ChangeLog index 32afaa46..71b44ebf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + o Fixed mmap()ing of zero-sized files (Robin H. Johnson) o Fixed mlmmj-recieve [sic] for architectures where sizeof(int) and sizeof(char *) differ o Added support for the 'originalmail' keyword (Sascha Sommer) diff --git a/src/getaddrsfromfd.c b/src/getaddrsfromfd.c index ecd78540..6e23940c 100644 --- a/src/getaddrsfromfd.c +++ b/src/getaddrsfromfd.c @@ -21,6 +21,10 @@ off_t getaddrsfromfd(struct strlist *slist, int fd, int max) log_error(LOG_ARGS, "Could not fstat fd"); return -1; } + /* mmap of 0-bytes is invalid */ + if(st.st_size == 0) { + return 0; + } start = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0); if(start == MAP_FAILED) { diff --git a/src/mlmmj-list.c b/src/mlmmj-list.c index 049a0f9b..c1e42fc1 100644 --- a/src/mlmmj-list.c +++ b/src/mlmmj-list.c @@ -68,6 +68,11 @@ int dumpcount(const char *filename, int *count) if(!S_ISREG(st.st_mode)) return -1; + + /* Nobody there */ + if(st.st_size == 0) { + return 0; + } start = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0); if(start == MAP_FAILED)