]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fsck.cramfs: use open+fstat rather than stat+open
authorKarel Zak <kzak@redhat.com>
Mon, 21 Jun 2021 10:39:33 +0000 (12:39 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 20 Jul 2021 09:33:27 +0000 (11:33 +0200)
Fixes: https://github.com/karelzak/util-linux/issues/1353
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/fsck.cramfs.c

index 8961685e17f5f6c8c74795b02f3d047d3084eeae..9b7e2a93b840ba623f555b17444c3f33e0ce189e 100644 (file)
@@ -152,14 +152,15 @@ static void test_super(int *start, size_t * length)
 {
        struct stat st;
 
-       /* find the physical size of the file or block device */
-       if (stat(filename, &st) < 0)
-               err(FSCK_EX_ERROR, _("stat of %s failed"), filename);
 
        fd = open(filename, O_RDONLY);
        if (fd < 0)
                err(FSCK_EX_ERROR, _("cannot open %s"), filename);
 
+       /* find the physical size of the file or block device */
+       if (fstat(fd, &st) < 0)
+               err(FSCK_EX_ERROR, _("stat of %s failed"), filename);
+
        if (S_ISBLK(st.st_mode)) {
                unsigned long long bytes;
                if (blkdev_get_size(fd, &bytes))