diff --git a/lib/libdevmapper.c b/lib/libdevmapper.c index 9100a3ef..9fd01b42 100644 --- a/lib/libdevmapper.c +++ b/lib/libdevmapper.c @@ -696,6 +696,14 @@ int dm_status_device(struct crypt_device *cd, const char *name) { int r; struct dm_info dmi; + struct stat st; + + /* libdevmapper is too clever and handles + * path argument differenly with error. + * Fail early here if parameter is non-existent path. + */ + if (strchr(name, '/') && stat(name, &st) < 0) + return -ENODEV; if (dm_init_context(cd)) return -ENOTSUP; diff --git a/src/cryptsetup.c b/src/cryptsetup.c index 46b32b9a..29a96f99 100644 --- a/src/cryptsetup.c +++ b/src/cryptsetup.c @@ -374,13 +374,12 @@ static int action_status(void) crypt_status_info ci; struct crypt_active_device cad; struct crypt_device *cd = NULL; - struct stat st; char *backing_file; const char *device; int path = 0, r = 0; /* perhaps a path, not a dm device name */ - if (strchr(action_argv[0], '/') && !stat(action_argv[0], &st)) + if (strchr(action_argv[0], '/')) path = 1; ci = crypt_status(NULL, action_argv[0]); diff --git a/tests/tcrypt-compat-test b/tests/tcrypt-compat-test index 71545bcd..71375ac3 100755 --- a/tests/tcrypt-compat-test +++ b/tests/tcrypt-compat-test @@ -97,6 +97,8 @@ echo "ACTIVATION FS UUID CHECK (LRW/XTS modes only)" for file in $(ls $TST_DIR/tc_*-lrw-* $TST_DIR/tc_*-xts-*) ; do echo -n " $file" echo $PASSWORD | $CRYPTSETUP tcryptOpen -r $file $MAP || fail + $CRYPTSETUP status $MAP >/dev/null || fail + $CRYPTSETUP status /dev/mapper/$MAP >/dev/null || fail UUID=$(lsblk -n -o UUID /dev/mapper/$MAP) $CRYPTSETUP remove $MAP || fail [ "$UUID" != "DEAD-BABE" ] && fail "UUID check failed."