From 66bebc21e2a2aead4393f98003986299f85ff425 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 12 Feb 2018 20:49:33 +0000 Subject: [Minor] Treat EPERM specially Issue: #1996 --- contrib/libucl/ucl_internal.h | 2 +- contrib/libucl/ucl_util.c | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) (limited to 'contrib') diff --git a/contrib/libucl/ucl_internal.h b/contrib/libucl/ucl_internal.h index 44a8fe70e..11b71de70 100644 --- a/contrib/libucl/ucl_internal.h +++ b/contrib/libucl/ucl_internal.h @@ -321,7 +321,7 @@ ucl_create_err (UT_string **err, const char *fmt, ...) } #ifdef UCL_FATAL_ERRORS - assert (0); + abort (); #endif } diff --git a/contrib/libucl/ucl_util.c b/contrib/libucl/ucl_util.c index f0ce5b5e3..85b700a4d 100644 --- a/contrib/libucl/ucl_util.c +++ b/contrib/libucl/ucl_util.c @@ -751,13 +751,20 @@ ucl_fetch_file (const unsigned char *filename, unsigned char **buf, size_t *bufl int fd; struct stat st; - if (stat (filename, &st) == -1 || !S_ISREG (st.st_mode)) { - if (must_exist) { + if (stat (filename, &st) == -1) { + if (must_exist || errno == EPERM) { ucl_create_err (err, "cannot stat file %s: %s", filename, strerror (errno)); } return false; } + if (!S_ISREG (st.st_mode)) { + if (must_exist) { + ucl_create_err (err, "file %s is not a regular file", filename); + } + + return false; + } if (st.st_size == 0) { /* Do not map empty files */ *buf = NULL; @@ -951,9 +958,10 @@ ucl_include_file_single (const unsigned char *data, size_t len, if (params->soft_fail) { return false; } - if (!params->must_exist) { + if (!params->must_exist && errno != EPERM) { return true; } + ucl_create_err (&parser->err, "cannot open file %s: %s", filebuf, strerror (errno)); @@ -976,7 +984,12 @@ ucl_include_file_single (const unsigned char *data, size_t len, return false; } - return (!params->must_exist || false); + if (params->must_exist || parser->err != NULL) { + /* The case of fatal errors */ + return false; + } + + return true; } if (params->check_signature) { -- cgit v1.2.3