From 0df2f69c0a46b2aff3d5d5b30bdcc529438d930f Mon Sep 17 00:00:00 2001 From: Jim Paris Date: Thu, 28 May 2015 19:11:14 -0400 Subject: [PATCH] Handle errors in diskfile_open() and diskfile_device_size() File sizes are otherwise filled with junk if the device nodes were not readable. --- diskfile.c | 2 ++ linux-size.c | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/diskfile.c b/diskfile.c index 6d25670..c1dcf68 100644 --- a/diskfile.c +++ b/diskfile.c @@ -73,6 +73,8 @@ diskfile_open(const char *path, struct fuse_file_info *fi) { return -EACCES; fi->fh = open(entry->source, O_RDONLY); + if (fi->fh == -1) + return -1; return 0; } } diff --git a/linux-size.c b/linux-size.c index 43c9255..5898645 100644 --- a/linux-size.c +++ b/linux-size.c @@ -10,7 +10,10 @@ off_t diskfile_device_size(const char *path) { unsigned long long size; int fd = open(path, O_RDONLY); - ioctl(fd, BLKGETSIZE64, &size); + if (fd == -1) + return 0; + if (ioctl(fd, BLKGETSIZE64, &size) == -1) + size = 0; close(fd); return size; }