LUKS header and Type needs to be set in context before crypt_check_data_device_size...
authorMilan Broz <gmazyland@gmail.com>
Mon, 22 Aug 2011 21:53:38 +0000 (21:53 +0000)
committerMilan Broz <gmazyland@gmail.com>
Mon, 22 Aug 2011 21:53:38 +0000 (21:53 +0000)
(Thanks to okozina@redhat.com)

git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@600 36d66b0a-2a48-0410-832c-cd162a569da5

ChangeLog
lib/setup.c

index eefd967..90ee04f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
 2011-08-22  Milan Broz  <mbroz@redhat.com>
        * Add more paranoid checks for LUKS header and keyslot attributes.
+       * Fix crypt_load to properly check device size.
 
 2011-07-25  Milan Broz  <mbroz@redhat.com>
        * Remove hash/hmac restart from crypto backend and make it part of hash/hmac final.
index 0682027..e91bf49 100644 (file)
@@ -913,15 +913,17 @@ int crypt_load(struct crypt_device *cd,
        if (r < 0)
                return r;
 
-       r = crypt_check_data_device_size(cd);
-       if (r < 0)
-               return r;
+       if (!cd->type && !(cd->type = strdup(CRYPT_LUKS1)))
+               return -ENOMEM;
 
        memcpy(&cd->hdr, &hdr, sizeof(hdr));
-       free(cd->type);
-       cd->type = strdup(CRYPT_LUKS1);
-       if (!cd->type)
-               r = -ENOMEM;
+
+       /* cd->type and header must be set in context */
+       r = crypt_check_data_device_size(cd);
+       if (r < 0) {
+               free(cd->type);
+               cd->type = NULL;
+       }
 
        return r;
 }