Krolyxon
Commit 878d970

Branches

Refs →

nsxiv878d970

Only open regular files; fixes issue #252

Author
Bert Münnich
Date
2016-10-20 10:21 +0200
Parent
891f389
Commit
878d97068cb6c8ae044332ac3c8218fcad635b42

+15 −8

3 files changed

  1. M Makefile +1 −1
  2. M image.c +4 −1
  3. M thumbs.c +10 −6
M Makefile View
@@ -1,4 +1,4 @@
1−VERSION := git-20160928
1+VERSION := git-20161020
22
33 PREFIX := /usr/local
44 MANPREFIX := $(PREFIX)/share/man
M image.c View
@@ -19,6 +19,7 @@
1919 #include <errno.h>
2020 #include <stdlib.h>
2121 #include <string.h>
22+#include <sys/stat.h>
2223 #include <sys/types.h>
2324 #include <unistd.h>
2425
@@ -296,8 +297,10 @@ bool img_load_gif(img_t *img, const fileinfo_t *file)
296297 bool img_load(img_t *img, const fileinfo_t *file)
297298 {
298299 const char *fmt;
300+ struct stat st;
299301
300− if (access(file->path, R_OK) < 0 ||
302+ if (access(file->path, R_OK) == -1 ||
303+ stat(file->path, &st) == -1 || !S_ISREG(st.st_mode) ||
301304 (img->im = imlib_load_image(file->path)) == NULL)
302305 {
303306 if (file->flags & FF_WARN)
M thumbs.c View
@@ -239,6 +239,7 @@ bool tns_load(tns_t *tns, int n, bool force, bool cache_only)
239239 float zw, zh;
240240 thumb_t *t;
241241 fileinfo_t *file;
242+ struct stat st;
242243 Imlib_Image im = NULL;
243244
244245 if (n < 0 || n >= *tns->cnt)
@@ -330,12 +331,15 @@ bool tns_load(tns_t *tns, int n, bool force, bool cache_only)
330331 }
331332 }
332333
333− if (im == NULL && (access(file->path, R_OK) < 0 ||
334− (im = imlib_load_image(file->path)) == NULL))
335− {
336− if (file->flags & FF_WARN)
337− error(0, 0, "%s: Error opening image", file->name);
338− return false;
334+ if (im == NULL) {
335+ if (access(file->path, R_OK) == -1 ||
336+ stat(file->path, &st) == -1 || !S_ISREG(st.st_mode) ||
337+ (im = imlib_load_image(file->path)) == NULL)
338+ {
339+ if (file->flags & FF_WARN)
340+ error(0, 0, "%s: Error opening image", file->name);
341+ return false;
342+ }
339343 }
340344 imlib_context_set_image(im);
341345