From adde78647bbdbbca2f6e1252f7786afe238c1c5d Mon Sep 17 00:00:00 2001 From: Steffen Moeller Date: Tue, 10 Sep 2019 14:55:08 +0200 Subject: [PATCH] Check return value of write function This patch closes the file descriptor and returns with a failure, when there is a failure. --- lib/shmem.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/shmem.cpp b/lib/shmem.cpp index 19d63cd486..52649aa687 100644 --- a/lib/shmem.cpp +++ b/lib/shmem.cpp @@ -339,7 +339,10 @@ int create_shmem_mmap(const char *path, size_t size, void** pp) { // area to all zeros because they write beyond the old EOF. // See the lseek man page for details. lseek(fd, size-1, SEEK_SET); - write(fd, "\0", 1); + if (1 != write(fd, "\0", 1)) { + close(fd); + return ERR_SHMGET; + } } *pp = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0);