From 0482a033108a2b6e34ee99c470fd84d91119e291 Mon Sep 17 00:00:00 2001 From: Alex Hornung Date: Sun, 22 Aug 2010 12:16:23 +0100 Subject: [PATCH] cryptsetup - Fix uuid bug, cleanup * Clean up some useless debug and improve some other to be more meaningful. * Fix (another) bug in the uuid mess. Linux' uuid_unparse doesn't allocate any memory, unlike our uuid_to_string. Work around it by using a temporary buffer and then copying into the final destination. The compiler has been warning me about this one long enough... --- contrib/cryptsetup/lib/libdevmapper.c | 4 +--- contrib/cryptsetup/lib/utils.c | 3 +++ contrib/cryptsetup/luks/keymanage.c | 9 ++++++++- contrib/cryptsetup/luks/pbkdf.c | 1 - 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/contrib/cryptsetup/lib/libdevmapper.c b/contrib/cryptsetup/lib/libdevmapper.c index 5c59aecb25..5c46a0bc1d 100644 --- a/contrib/cryptsetup/lib/libdevmapper.c +++ b/contrib/cryptsetup/lib/libdevmapper.c @@ -391,15 +391,13 @@ static void dm_prepare_uuid(const char *name, const char *type, const char *uuid if (uuid) { uuid_from_string(uuid, &uu, &ret); if (ret != uuid_s_ok) { - printf("crap happened in uuid_from_string(%s), err = %d\n", uuid, ret); + printf("error in uuid_from_string(%s), err = %d\n", uuid, ret); for (ptr = uuid2, i = 0; i < UUID_LEN; i++) { if (uuid[i] != '-') { *ptr = uuid[i]; ptr++; } } - } else { - printf("went well in uuid_from_string(%s), err = %d\n", uuid, ret); } } diff --git a/contrib/cryptsetup/lib/utils.c b/contrib/cryptsetup/lib/utils.c index 5999a063f4..b898b08ba6 100644 --- a/contrib/cryptsetup/lib/utils.c +++ b/contrib/cryptsetup/lib/utils.c @@ -645,7 +645,10 @@ int crypt_memlock_inc(struct crypt_device *ctx) if (!_memlock_count++) { log_dbg("Locking memory."); if (mlockall(MCL_CURRENT | MCL_FUTURE)) { +#if 0 log_err(ctx, _("WARNING!!! Possibly insecure memory. Are you root?\n")); +#endif + log_err(ctx, _("WARNING!!! Possibly insecure memory, missing mlockall()\n")); _memlock_count--; return 0; } diff --git a/contrib/cryptsetup/luks/keymanage.c b/contrib/cryptsetup/luks/keymanage.c index 5bc8996ae0..954ff7b389 100644 --- a/contrib/cryptsetup/luks/keymanage.c +++ b/contrib/cryptsetup/luks/keymanage.c @@ -433,6 +433,7 @@ int LUKS_generate_phdr(struct luks_phdr *header, int r; uint32_t ret; char luksMagic[] = LUKS_MAGIC; + char *uu; uuid_t partitionUuid; int currentSector; int alignSectors = LUKS_ALIGN_KEYSLOTS / SECTOR_SIZE; @@ -499,7 +500,13 @@ int LUKS_generate_phdr(struct luks_phdr *header, } if (!uuid) uuid_create(&partitionUuid, &ret); - uuid_to_string(&partitionUuid, &header->uuid, &ret); + uuid_to_string(&partitionUuid, &uu, &ret); + if (uu == NULL) { + log_err(ctx, _("Cannot allocate memory in uuid_to_string()\n")); + return -1; + } + memcpy(header->uuid, uu, UUID_STRING_L); + free(uu); log_dbg("Data offset %d, UUID %s, digest iterations %" PRIu32, header->payloadOffset, header->uuid, header->mkDigestIterations); diff --git a/contrib/cryptsetup/luks/pbkdf.c b/contrib/cryptsetup/luks/pbkdf.c index 5e9e0104b7..31e5da4d51 100644 --- a/contrib/cryptsetup/luks/pbkdf.c +++ b/contrib/cryptsetup/luks/pbkdf.c @@ -266,7 +266,6 @@ int PBKDF2_performance_check(const char *hash, uint64_t *iter) } r = pkcs5_pbkdf2(hash, "foo", 3, "bar", 3, ~(0U), 1, &buf, 1); - printf("foo4: %d\n", r); *iter = __PBKDF2_performance; __PBKDF2_global_j = 0; __PBKDF2_performance = 0; -- 2.41.0