From 626d37511f968e70c1eac329667e354363a0ebb9 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sat, 3 May 2014 10:42:14 +0100 Subject: check return from stat() fixes coverity 1164069 --- monkey/filetype.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/monkey/filetype.c b/monkey/filetype.c index db9c49ab4..8c5037781 100644 --- a/monkey/filetype.c +++ b/monkey/filetype.c @@ -149,6 +149,15 @@ void monkey_fetch_filetype_fin(void) hash_destroy(mime_hash); } +/** + * Determine the MIME type of a local file. + * + * @note used in file fetcher + * + * \param unix_path Unix style path to file on disk + * \return Pointer to static MIME type string (should not be freed) not NULL. + * invalidated on next call to fetch_filetype. + */ const char *monkey_fetch_filetype(const char *unix_path) { struct stat statbuf; @@ -158,9 +167,16 @@ const char *monkey_fetch_filetype(const char *unix_path) const char *type; int l; - stat(unix_path, &statbuf); - if (S_ISDIR(statbuf.st_mode)) + if (stat(unix_path, &statbuf) != 0) { + /* error calling stat, the file has probably become + * inacessible, this routine cannot fail so just + * return the default mime type. + */ + return "text/plain"; + } + if (S_ISDIR(statbuf.st_mode)) { return "application/x-netsurf-directory"; + } l = strlen(unix_path); if ((3 < l) && (strcasecmp(unix_path + l - 4, ",f79") == 0)) { @@ -176,8 +192,9 @@ const char *monkey_fetch_filetype(const char *unix_path) while (*ptr != '.' && *ptr != '/') ptr--; - if (*ptr != '.') + if (*ptr != '.') { return "text/plain"; + } ext = strdup(ptr + 1); /* skip the . */ -- cgit v1.2.3