From 479bb9df2cd21ec1b144999638065f6305a9beb4 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 5 Dec 2012 13:59:08 +0100 Subject: [PATCH] fail nicely when trying to open a directory --- src/file.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/file.cc b/src/file.cc index 2aedb67b..985e802f 100644 --- a/src/file.cc +++ b/src/file.cc @@ -83,6 +83,11 @@ Buffer* create_buffer_from_file(const String& filename) } struct stat st; fstat(fd, &st); + if (S_ISDIR(st.st_mode)) + { + close(fd); + throw file_access_error(filename, "is a directory"); + } const char* data = (const char*)mmap(nullptr, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); auto cleanup = on_scope_end([&]{ munmap((void*)data, st.st_size); close(fd); });