summaryrefslogtreecommitdiffstats
path: root/libmount/src/context_mount.c
diff options
context:
space:
mode:
authorKarel Zak2017-10-11 14:59:16 +0200
committerKarel Zak2017-10-11 14:59:16 +0200
commit78c57214ade665eb692c3450b0d6e410e615147a (patch)
tree09c5b677f4075a378490e1eb4be285609286f200 /libmount/src/context_mount.c
parentlibfdisk: (sun) make math more robust [coverity scan] (diff)
downloadkernel-qcow2-util-linux-78c57214ade665eb692c3450b0d6e410e615147a.tar.gz
kernel-qcow2-util-linux-78c57214ade665eb692c3450b0d6e410e615147a.tar.xz
kernel-qcow2-util-linux-78c57214ade665eb692c3450b0d6e410e615147a.zip
libmount: make sure we call stat() propely [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/context_mount.c')
-rw-r--r--libmount/src/context_mount.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c
index 8ef806314..c6a794d7e 100644
--- a/libmount/src/context_mount.c
+++ b/libmount/src/context_mount.c
@@ -1534,13 +1534,13 @@ int mnt_context_get_mount_excode(
return MNT_EX_SUCCESS;
if (!buf)
break;
- if (stat(src, &st))
+ if (src && stat(src, &st))
snprintf(buf, bufsz, _("%s is not a block device, and stat(2) fails?"), src);
- else if (S_ISBLK(st.st_mode))
+ else if (src && S_ISBLK(st.st_mode))
snprintf(buf, bufsz,
_("the kernel does not recognize %s as a block device; "
"maybe \"modprobe driver\" is necessary"), src);
- else if (S_ISREG(st.st_mode))
+ else if (src && S_ISREG(st.st_mode))
snprintf(buf, bufsz, _("%s is not a block device; try \"-o loop\""), src);
else
snprintf(buf, bufsz, _("%s is not a block device"), src);
@@ -1580,7 +1580,8 @@ int mnt_context_get_mount_excode(
case EBADMSG:
/* Bad CRC for classic filesystems (e.g. extN or XFS) */
- if (buf && (S_ISBLK(st.st_mode) || S_ISREG(st.st_mode))) {
+ if (buf && src && stat(src, &st) == 0
+ && (S_ISBLK(st.st_mode) || S_ISREG(st.st_mode))) {
snprintf(buf, bufsz, _("cannot mount; probably corrupted filesystem on %s"), src);
break;
}