cryptsetup - Fix uuid bug, cleanup
authorAlex Hornung <ahornung@gmail.com>
Sun, 22 Aug 2010 11:16:23 +0000 (12:16 +0100)
committerAlex Hornung <ahornung@gmail.com>
Sun, 22 Aug 2010 11:16:23 +0000 (12:16 +0100)
* 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
contrib/cryptsetup/lib/utils.c
contrib/cryptsetup/luks/keymanage.c
contrib/cryptsetup/luks/pbkdf.c

index 5c59aec..5c46a0b 100644 (file)
@@ -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);
                }
        }
 
index 5999a06..b898b08 100644 (file)
@@ -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;
                }
index 5bc8996..954ff7b 100644 (file)
@@ -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);
index 5e9e010..31e5da4 100644 (file)
@@ -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;