diff options
author | kwaclaw <kwaclaw> | 2006-06-28 02:55:51 +0000 |
---|---|---|
committer | kwaclaw <kwaclaw> | 2006-06-28 02:55:51 +0000 |
commit | ec51dcfa944084307841fec0bfa0fc8a13e89382 (patch) | |
tree | fb38898e31b3e3a819b949767501d6bb91c550cb | |
parent | 326f5c6091b15df55fa7a704f1c45484e35c5b94 (diff) | |
download | libexpat-ec51dcfa944084307841fec0bfa0fc8a13e89382.tar.gz |
Fix for bug #1513566: filemap() in readfilemap.c doesn't handle zero length
files, and the same issue applies to filemap() in unixfilemap.c
-rwxr-xr-x | xmlwf/readfilemap.c | 8 | ||||
-rwxr-xr-x | xmlwf/unixfilemap.c | 7 |
2 files changed, 15 insertions, 0 deletions
diff --git a/xmlwf/readfilemap.c b/xmlwf/readfilemap.c index 42b5e03..0a91f08 100755 --- a/xmlwf/readfilemap.c +++ b/xmlwf/readfilemap.c @@ -57,9 +57,17 @@ filemap(const char *name, return 0; } nbytes = sb.st_size; + /* malloc will return NULL with nbytes == 0, handle files with size 0 */ + if (nbytes == 0) { + static const char c = '\0'; + processor(&c, 0, name, arg); + close(fd); + return 1; + } p = malloc(nbytes); if (!p) { fprintf(stderr, "%s: out of memory\n", name); + close(fd); return 0; } n = read(fd, p, nbytes); diff --git a/xmlwf/unixfilemap.c b/xmlwf/unixfilemap.c index 22048c8..93adce3 100755 --- a/xmlwf/unixfilemap.c +++ b/xmlwf/unixfilemap.c @@ -44,6 +44,13 @@ filemap(const char *name, } nbytes = sb.st_size; + /* mmap fails for zero length files */ + if (nbytes == 0) { + static const char c = '\0'; + processor(&c, 0, name, arg); + close(fd); + return 1; + } p = (void *)mmap((caddr_t)0, (size_t)nbytes, PROT_READ, MAP_FILE|MAP_PRIVATE, fd, (off_t)0); if (p == (void *)-1) { |