Define device-mapper crypt UUID maximal length and check for its size.

git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@57 36d66b0a-2a48-0410-832c-cd162a569da5
This commit is contained in:
Milan Broz
2009-06-21 10:02:10 +00:00
parent 6fe5246956
commit 9ed9ba3d85

View File

@@ -16,11 +16,14 @@
#include "libcryptsetup.h" #include "libcryptsetup.h"
#include "internal.h" #include "internal.h"
#include "luks.h"
#define DEVICE_DIR "/dev" #define DEVICE_DIR "/dev"
#define UUID_PREFIX "CRYPT-" #define DM_UUID_PREFIX "CRYPT-"
#define CRYPT_TARGET "crypt" #define DM_UUID_PREFIX_LEN 6
#define RETRY_COUNT 5 #define DM_UUID_LEN UUID_STRING_L
#define DM_CRYPT_TARGET "crypt"
#define RETRY_COUNT 5
static void set_dm_error(int level, const char *file, int line, static void set_dm_error(int level, const char *file, int line,
const char *f, ...) const char *f, ...)
@@ -254,7 +257,7 @@ static int dm_create_device(int reload, struct crypt_options *options,
struct dm_info dmi; struct dm_info dmi;
char *params = NULL; char *params = NULL;
char *error = NULL; char *error = NULL;
char dev_uuid[64]; char dev_uuid[DM_UUID_PREFIX_LEN + DM_UUID_LEN + 1] = {0};
int r = -EINVAL; int r = -EINVAL;
uint32_t read_ahead = 0; uint32_t read_ahead = 0;
@@ -263,8 +266,9 @@ static int dm_create_device(int reload, struct crypt_options *options,
goto out_no_removal; goto out_no_removal;
if (uuid) { if (uuid) {
strcpy(dev_uuid, UUID_PREFIX); strncpy(dev_uuid, DM_UUID_PREFIX, DM_UUID_PREFIX_LEN);
strcat(dev_uuid, uuid); strncpy(dev_uuid + DM_UUID_PREFIX_LEN, uuid, DM_UUID_LEN);
dev_uuid[DM_UUID_PREFIX_LEN + DM_UUID_LEN] = '\0';
} }
if (!(dmt = dm_task_create(reload ? DM_DEVICE_RELOAD if (!(dmt = dm_task_create(reload ? DM_DEVICE_RELOAD
@@ -274,7 +278,7 @@ static int dm_create_device(int reload, struct crypt_options *options,
goto out; goto out;
if (options->flags & CRYPT_FLAG_READONLY && !dm_task_set_ro(dmt)) if (options->flags & CRYPT_FLAG_READONLY && !dm_task_set_ro(dmt))
goto out; goto out;
if (!dm_task_add_target(dmt, 0, options->size, CRYPT_TARGET, params)) if (!dm_task_add_target(dmt, 0, options->size, DM_CRYPT_TARGET, params))
goto out; goto out;
#ifdef DM_READ_AHEAD_MINIMUM_FLAG #ifdef DM_READ_AHEAD_MINIMUM_FLAG
@@ -361,7 +365,7 @@ static int dm_query_device(int details, struct crypt_options *options,
next = dm_get_next_target(dmt, next, &start, &length, next = dm_get_next_target(dmt, next, &start, &length,
&target_type, &params); &target_type, &params);
if (!target_type || strcmp(target_type, CRYPT_TARGET) != 0 || if (!target_type || strcmp(target_type, DM_CRYPT_TARGET) != 0 ||
start != 0 || next) start != 0 || next)
goto out; goto out;