diff options
author | Martin Pärtel <martin.partel@gmail.com> | 2023-02-07 08:53:56 +0200 |
---|---|---|
committer | Martin Pärtel <martin.partel@gmail.com> | 2023-02-07 08:53:56 +0200 |
commit | 50847862ed3329482a87b2d8091a03bdaa7f4ab6 (patch) | |
tree | 8fc504e6fbcfc047962614cced15e85cc7e09ead /src | |
parent | 6d46e55a59bc5e36e4f7b19691fc8cc48a369f66 (diff) | |
download | bindfs-50847862ed3329482a87b2d8091a03bdaa7f4ab6.tar.gz |
Fixed FD leak when using --block-devices-as-files (#125)
Diffstat (limited to 'src')
-rw-r--r-- | src/bindfs.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/bindfs.c b/src/bindfs.c index 263aa0e..b049679 100644 --- a/src/bindfs.c +++ b/src/bindfs.c @@ -457,25 +457,26 @@ static int getattr_common(const char *procpath, struct stat *stbuf) if (settings.block_devices_as_files && S_ISBLK(stbuf->st_mode)) { stbuf->st_mode ^= S_IFBLK | S_IFREG; // Flip both bits int fd = open(procpath, O_RDONLY); + if (fd == -1) { + return -errno; + } #ifdef __linux__ uint64_t size; ioctl(fd, BLKGETSIZE64, &size); stbuf->st_size = (off_t)size; if (stbuf->st_size < 0) { // Underflow + close(fd); return -EOVERFLOW; } #else - if (fd == -1) { - return -errno; - } off_t size = lseek(fd, 0, SEEK_END); if (size == (off_t)-1) { close(fd); return -errno; } stbuf->st_size = size; - close(fd); #endif + close(fd); } /* Then permission bits. Symlink permissions don't matter, though. */ |