libfstools: handle open() return value properly in F2FS check
[project/fstools.git] / libfstools / common.c
index f2d415d7012ce36bb885ed0fc71dcc63092050a8..c4847766a0389a444b2dab39c2c14a0574587d97 100644 (file)
@@ -90,8 +90,12 @@ static bool use_f2fs(struct volume *v, uint64_t offset, const char *bdev)
        int fd;
 
        fd = open(bdev, O_RDONLY);
+       if (fd < 0)
+               return false;
+
        if (ioctl(fd, BLKGETSIZE64, &size) == 0)
                ret = size - offset > F2FS_MINSIZE;
+
        close(fd);
 
        return ret;