Remove VLAs from UUID block parsing code.

This commit is contained in:
Milan Broz
2021-02-13 22:22:26 +01:00
parent 20320dfd0e
commit 2d9c0b507d
5 changed files with 11 additions and 15 deletions

View File

@@ -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); char *crypt_get_base_device(const char *dev_path);
uint64_t crypt_dev_partition_offset(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_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); int crypt_uuid_cmp(const char *dm_uuid, const char *hdr_uuid);
size_t crypt_getpagesize(void); size_t crypt_getpagesize(void);

View File

@@ -56,4 +56,10 @@
#define DEFAULT_DISK_ALIGNMENT 1048576 /* 1MiB */ #define DEFAULT_DISK_ALIGNMENT 1048576 /* 1MiB */
#define DEFAULT_MEM_ALIGNMENT 4096 #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 */ #endif /* _LIBCRYPTSETUP_MACROS_H */

View File

@@ -36,11 +36,6 @@
#include "internal.h" #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_CRYPT_TARGET "crypt"
#define DM_VERITY_TARGET "verity" #define DM_VERITY_TARGET "verity"
#define DM_INTEGRITY_TARGET "integrity" #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); r = lookup_by_disk_id(dev_uuid);
if (r == -ENOENT) { if (r == -ENOENT) {
log_dbg(cd, "Search by disk id not available. Using sysfs instead."); 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; return r;

View File

@@ -406,10 +406,10 @@ int lookup_by_disk_id(const char *dm_uuid)
return r; 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; struct dirent *entry;
char subpath[PATH_MAX], uuid[max_len]; char subpath[PATH_MAX], uuid[DM_UUID_LEN];
ssize_t s; ssize_t s;
struct stat st; struct stat st;
int fd, len, r = 0; /* not found */ 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 */ /* reads binary data */
s = read_buffer(fd, uuid, max_len - 1); s = read_buffer(fd, uuid, sizeof(uuid) - 1);
if (s > 0) { if (s > 0) {
uuid[s] = '\0'; uuid[s] = '\0';
if (!strncmp(uuid, dm_uuid, strlen(dm_uuid))) if (!strncmp(uuid, dm_uuid, strlen(dm_uuid)))

View File

@@ -26,11 +26,6 @@
#endif #endif
#include <uuid/uuid.h> #include <uuid/uuid.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 UUID_LEN 37 /* 36 + \0, libuuid ... */ #define UUID_LEN 37 /* 36 + \0, libuuid ... */
static int dm_prepare_uuid(const char *type, const char *uuid, char *buf, size_t buflen) static int dm_prepare_uuid(const char *type, const char *uuid, char *buf, size_t buflen)