From a384ec65698faeebfb40a15bdf60d0c04c643902 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Sat, 19 Sep 2015 07:12:02 +1000 Subject: [PATCH] 4218. [bug] Potential null pointer dereference on out of memory if mmap is not supported. [RT #40777] (cherry picked from commit 4dd41c7d5976ff6889e4fbf306036f4256af409a) --- CHANGES | 2 ++ lib/isc/unix/file.c | 3 +++ lib/isc/win32/file.c | 3 +++ 3 files changed, 8 insertions(+) diff --git a/CHANGES b/CHANGES index aca743c578..b27b290107 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,5 @@ +4218. [bug] Potential null pointer dereference on out of memory if mmap is not supported. [RT #40777] + 4217. [protocol] Add support for CSYNC. [RT #40532] 4216. [cleanup] Silence static analysis warnings. [RT #40649] diff --git a/lib/isc/unix/file.c b/lib/isc/unix/file.c index 4be9eced75..f0dc9fdf1c 100644 --- a/lib/isc/unix/file.c +++ b/lib/isc/unix/file.c @@ -674,6 +674,9 @@ isc_file_mmap(void *addr, size_t len, int prot, len = end - offset; buf = malloc(len); + if (buf == NULL) + return (NULL); + ret = read(fd, buf, len); if (ret != (ssize_t) len) { free(buf); diff --git a/lib/isc/win32/file.c b/lib/isc/win32/file.c index c6adaae20f..572dce4a5a 100644 --- a/lib/isc/win32/file.c +++ b/lib/isc/win32/file.c @@ -751,6 +751,9 @@ isc_file_mmap(void *addr, size_t len, int prot, len = end - offset; buf = malloc(len); + if (buf == NULL) + return (NULL); + ret = read(fd, buf, (unsigned int) len); if (ret != (ssize_t) len) { free(buf);