From db176529529c142333f668f2c1334753f7f406bf Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 9 Nov 2005 00:04:15 +0000 Subject: [PATCH] Include checks for mmap() returning NULL --- common/textfile.c | 4 ++-- tools/csr.c | 2 +- tools/oui.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common/textfile.c b/common/textfile.c index dd77980cf..b21345623 100644 --- a/common/textfile.c +++ b/common/textfile.c @@ -149,7 +149,7 @@ int textfile_put(char *pathname, char *key, char *value) } map = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_LOCKED, fd, 0); - if (map == MAP_FAILED) { + if (!map || map == MAP_FAILED) { err = errno; goto unlock; } @@ -243,7 +243,7 @@ char *textfile_get(char *pathname, char *key) size = st.st_size; map = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); - if (map == MAP_FAILED) { + if (!map || map == MAP_FAILED) { err = errno; goto unlock; } diff --git a/tools/csr.c b/tools/csr.c index 698122dcc..3f6717400 100644 --- a/tools/csr.c +++ b/tools/csr.c @@ -2697,7 +2697,7 @@ int psr_read(const char *filename) } map = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0); - if (map == MAP_FAILED) { + if (!map || map == MAP_FAILED) { err = -errno; goto close; } diff --git a/tools/oui.c b/tools/oui.c index 0a1d67bcb..6ebf91a5d 100644 --- a/tools/oui.c +++ b/tools/oui.c @@ -65,7 +65,7 @@ char *ouitocomp(const char *oui) memset(str, 0, 128); map = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0); - if (map == MAP_FAILED) { + if (!map || map == MAP_FAILED) { free(str); close(fd); return NULL;