Fix some problems found by Coverity scan.
authorMilan Broz <gmazyland@gmail.com>
Mon, 10 Dec 2012 16:28:52 +0000 (17:28 +0100)
committerMilan Broz <gmazyland@gmail.com>
Mon, 10 Dec 2012 16:28:52 +0000 (17:28 +0100)
lib/crypto_backend/pbkdf_check.c
lib/setup.c
lib/tcrypt/tcrypt.c
lib/utils_benchmark.c
src/cryptsetup.c

index 69f6bfb..ce5bd1e 100644 (file)
@@ -82,10 +82,6 @@ int crypt_pbkdf_check(const char *kdf, const char *hash,
                        return -EINVAL;
        }
 
-       /* Safety check if anything went wrong */
-       if (ms < 10)
-               return -EINVAL;
-
        if (iter_secs)
                *iter_secs = (iterations * 1000) / ms;
        return r;
index 5e01f99..5914f9d 100644 (file)
@@ -1679,7 +1679,7 @@ int crypt_keyslot_change_by_passphrase(struct crypt_device *cd,
        r = LUKS_open_key_with_hdr(keyslot_old, passphrase, passphrase_size,
                                   &cd->u.luks1.hdr, &vk, cd);
        if (r < 0)
-               return r;
+               goto out;
 
        if (keyslot_old != CRYPT_ANY_SLOT && keyslot_old != r) {
                log_dbg("Keyslot mismatch.");
index b1ebd05..1672c71 100644 (file)
@@ -471,12 +471,16 @@ static int TCRYPT_init_hdr(struct crypt_device *cd,
                           struct crypt_params_tcrypt *params)
 {
        unsigned char pwd[TCRYPT_KEY_POOL_LEN] = {};
-       size_t passphrase_size;
+       size_t passphrase_size, alignment;
        char *key;
        unsigned int i, skipped = 0;
        int r = -EINVAL, legacy_modes;
 
-       if (posix_memalign((void*)&key, crypt_getpagesize(), TCRYPT_HDR_KEY_LEN))
+       alignment = crypt_getpagesize();
+       if (alignment < 0)
+               return -EINVAL;
+
+       if (posix_memalign((void*)&key, alignment, TCRYPT_HDR_KEY_LEN))
                return -ENOMEM;
 
        if (params->keyfiles_count)
index 4ee0c03..f392382 100644 (file)
@@ -128,9 +128,14 @@ static int cipher_perf(struct cipher_perf *cp,
 {
        long ms_enc, ms_dec, ms;
        int repeat_enc, repeat_dec;
+       size_t alignment;
        void *buf = NULL;
 
-       if (posix_memalign(&buf, crypt_getpagesize(), cp->buffer_size))
+       alignment = crypt_getpagesize();
+       if (alignment < 0)
+               return -EINVAL;
+
+       if (posix_memalign(&buf, alignment, cp->buffer_size))
                return -ENOMEM;
 
        ms_enc = 0;
index d652bad..4592897 100644 (file)
@@ -491,10 +491,8 @@ static int action_benchmark(void)
                                    &enc_mbr, &dec_mbr);
                if (!r) {
                        log_std("#  Algorithm | Key | Encryption | Decryption\n");
-                       strncat(cipher, "-", MAX_CIPHER_LEN);
-                       strncat(cipher, cipher_mode, MAX_CIPHER_LEN);
-                       log_std("%12s  %4db  %5.1f MiB/s  %5.1f MiB/s\n",
-                               cipher, key_size, enc_mbr, dec_mbr);
+                       log_std("%8s-%s  %4db  %5.1f MiB/s  %5.1f MiB/s\n",
+                               cipher, cipher_mode, key_size, enc_mbr, dec_mbr);
                } else if (r == -ENOENT)
                        log_err(_("Cipher %s is not available.\n"), opt_cipher);
        } else {