Fix some problems found by Coverity static analysis.
[platform/upstream/cryptsetup.git] / lib / utils_devpath.c
index 9472873..472569e 100644 (file)
 #include <sys/types.h>
 #include "utils_dm.h"
 
+/* These are DM helpers used only by this file */
+int dm_is_dm_device(int major, int minor);
+int dm_is_dm_kernel_name(const char *name);
+char *dm_device_path(const char *prefix, int major, int minor);
+
 char *crypt_lookup_dev(const char *dev_id);
 int crypt_sysfs_get_rotational(int major, int minor, int *rotational);
 
@@ -134,7 +139,7 @@ char *crypt_lookup_dev(const char *dev_id)
        if (snprintf(path, sizeof(path), "/sys/dev/block/%s", dev_id) < 0)
                return NULL;
 
-       len = readlink(path, link, sizeof(link));
+       len = readlink(path, link, sizeof(link) - 1);
        if (len < 0) {
                /* Without /sys use old scan */
                if (stat("/sys/dev/block", &st) < 0)