]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: make sure we call stat() propely [coverity scan]
authorKarel Zak <kzak@redhat.com>
Wed, 11 Oct 2017 12:59:16 +0000 (14:59 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 11 Oct 2017 12:59:16 +0000 (14:59 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/context_mount.c

index 8ef806314687f5181a2b7ecdb8a86da41bb4419c..c6a794d7e27c1db0e5aa9dfee558c3c3530b5a77 100644 (file)
@@ -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;
                }