]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
crypt: Streamline get_asymmetric_key().
authorAndre Noll <maan@systemlinux.org>
Mon, 15 Aug 2011 18:05:11 +0000 (20:05 +0200)
committerAndre Noll <maan@systemlinux.org>
Wed, 21 Sep 2011 09:04:30 +0000 (11:04 +0200)
The clang analyzer says

crypt.c:202:9: warning: Function call argument is an uninitialized value
        ret2 = para_munmap(map, map_size);
               ^                ~~~~~~~~
And right it is. This is not a bug though as map_size is only undefined
if map is NULL and in this case para_munmap does not look at its second
argument. However, this is rather subtle, so introduce a new label out_unmap
and jump there only if we really must unmap the file.

crypt.c

diff --git a/crypt.c b/crypt.c
index 5b7029d32d1aa906b8d5dae49a0e965af9d1c87f..207ad5db4e9f264091076d404adb06e12b95e8e4 100644 (file)
--- a/crypt.c
+++ b/crypt.c
@@ -184,24 +184,25 @@ int get_asymmetric_key(const char *key_file, int private,
        PARA_INFO_LOG("decoding public rsa-ssh key %s\n", key_file);
        ret = -ERRNO_TO_PARA_ERROR(EOVERFLOW);
        if (map_size > INT_MAX / 4)
-               goto out;
+               goto out_unmap;
        blob_size = 2 * map_size;
        blob = para_malloc(blob_size);
        ret = uudecode(cp, blob, blob_size);
        if (ret < 0)
-               goto out;
+               goto out_unmap;
        decoded_size = ret;
        ret = check_ssh_key_header(blob, decoded_size);
        if (ret < 0)
-               goto out;
+               goto out_unmap;
        ret = read_rsa_bignums(blob + ret, decoded_size - ret, &key->rsa);
        if (ret < 0)
-               goto out;
+               goto out_unmap;
        ret = RSA_size(key->rsa);
-out:
+out_unmap:
        ret2 = para_munmap(map, map_size);
        if (ret >= 0 && ret2 < 0)
                ret = ret2;
+out:
        if (ret < 0) {
                free(key);
                *result = NULL;