From: Karel Zak Date: Mon, 21 Jun 2021 10:39:33 +0000 (+0200) Subject: fsck.cramfs: use open+fstat rather than stat+open X-Git-Tag: v2.37.1~62 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=b0f8d63e6314140a6e51c2cbe5bc143e6e53ab1b;p=thirdparty%2Futil-linux.git fsck.cramfs: use open+fstat rather than stat+open Fixes: https://github.com/karelzak/util-linux/issues/1353 Signed-off-by: Karel Zak --- diff --git a/disk-utils/fsck.cramfs.c b/disk-utils/fsck.cramfs.c index 8961685e17..9b7e2a93b8 100644 --- a/disk-utils/fsck.cramfs.c +++ b/disk-utils/fsck.cramfs.c @@ -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))