diff --git a/lib/internal.h b/lib/internal.h index 2b967b37..58355d64 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -159,7 +159,7 @@ char *crypt_get_partition_device(const char *dev_path, uint64_t offset, uint64_t char *crypt_get_base_device(const char *dev_path); uint64_t crypt_dev_partition_offset(const char *dev_path); int lookup_by_disk_id(const char *dm_uuid); -int lookup_by_sysfs_uuid_field(const char *dm_uuid, size_t max_len); +int lookup_by_sysfs_uuid_field(const char *dm_uuid); int crypt_uuid_cmp(const char *dm_uuid, const char *hdr_uuid); size_t crypt_getpagesize(void); diff --git a/lib/libcryptsetup_macros.h b/lib/libcryptsetup_macros.h index 6b7f02dc..7ccf3a15 100644 --- a/lib/libcryptsetup_macros.h +++ b/lib/libcryptsetup_macros.h @@ -56,4 +56,10 @@ #define DEFAULT_DISK_ALIGNMENT 1048576 /* 1MiB */ #define DEFAULT_MEM_ALIGNMENT 4096 +#define DM_UUID_LEN 129 +#define DM_BY_ID_PREFIX "dm-uuid-" +#define DM_BY_ID_PREFIX_LEN 8 +#define DM_UUID_PREFIX "CRYPT-" +#define DM_UUID_PREFIX_LEN 6 + #endif /* _LIBCRYPTSETUP_MACROS_H */ diff --git a/lib/libdevmapper.c b/lib/libdevmapper.c index 2bf5c730..51634a35 100644 --- a/lib/libdevmapper.c +++ b/lib/libdevmapper.c @@ -36,11 +36,6 @@ #include "internal.h" -#define DM_UUID_LEN 129 -#define DM_BY_ID_PREFIX "dm-uuid-" -#define DM_BY_ID_PREFIX_LEN 8 -#define DM_UUID_PREFIX "CRYPT-" -#define DM_UUID_PREFIX_LEN 6 #define DM_CRYPT_TARGET "crypt" #define DM_VERITY_TARGET "verity" #define DM_INTEGRITY_TARGET "integrity" @@ -1244,7 +1239,7 @@ int lookup_dm_dev_by_uuid(struct crypt_device *cd, const char *uuid, const char r = lookup_by_disk_id(dev_uuid); if (r == -ENOENT) { log_dbg(cd, "Search by disk id not available. Using sysfs instead."); - r = lookup_by_sysfs_uuid_field(dev_uuid + DM_BY_ID_PREFIX_LEN, DM_UUID_LEN); + r = lookup_by_sysfs_uuid_field(dev_uuid + DM_BY_ID_PREFIX_LEN); } return r; diff --git a/lib/utils_devpath.c b/lib/utils_devpath.c index 343cd76a..be89cc9a 100644 --- a/lib/utils_devpath.c +++ b/lib/utils_devpath.c @@ -406,10 +406,10 @@ int lookup_by_disk_id(const char *dm_uuid) return r; } -int lookup_by_sysfs_uuid_field(const char *dm_uuid, size_t max_len) +int lookup_by_sysfs_uuid_field(const char *dm_uuid) { struct dirent *entry; - char subpath[PATH_MAX], uuid[max_len]; + char subpath[PATH_MAX], uuid[DM_UUID_LEN]; ssize_t s; struct stat st; int fd, len, r = 0; /* not found */ @@ -441,7 +441,7 @@ int lookup_by_sysfs_uuid_field(const char *dm_uuid, size_t max_len) } /* reads binary data */ - s = read_buffer(fd, uuid, max_len - 1); + s = read_buffer(fd, uuid, sizeof(uuid) - 1); if (s > 0) { uuid[s] = '\0'; if (!strncmp(uuid, dm_uuid, strlen(dm_uuid))) diff --git a/src/utils_blockdev.c b/src/utils_blockdev.c index fea9577b..6d94e9b9 100644 --- a/src/utils_blockdev.c +++ b/src/utils_blockdev.c @@ -26,11 +26,6 @@ #endif #include -#define DM_UUID_LEN 129 -#define DM_BY_ID_PREFIX "dm-uuid-" -#define DM_BY_ID_PREFIX_LEN 8 -#define DM_UUID_PREFIX "CRYPT-" -#define DM_UUID_PREFIX_LEN 6 #define UUID_LEN 37 /* 36 + \0, libuuid ... */ static int dm_prepare_uuid(const char *type, const char *uuid, char *buf, size_t buflen)