]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
crypt.c: Plug memory leak in get_public_key().
authorAndre Noll <maan@tuebingen.mpg.de>
Thu, 16 Nov 2017 01:18:50 +0000 (02:18 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Thu, 28 Dec 2017 23:27:07 +0000 (00:27 +0100)
If server.users refers to an existing file which is not a ssh public
key, we leak 4 bytes of memory:

==27302== 4 bytes in 1 blocks are definitely lost in loss record 1 of 8
==27302==    at 0x402C201: malloc (vg_replace_malloc.c:299)
==27302==    by 0x8052FF3: para_malloc (string.c:63)
==27302==    by 0x8066532: get_public_key (crypt.c:151)
==27302==    by 0x80569D1: user_list_init (user_list.c:90)
==27302==    by 0x804D74D: parse_config_or_die (server.c:279)
==27302==    by 0x804C719: server_init (server.c:554)
==27302==    by 0x804C719: main (server.c:655)

Furtunately, this issue is trivial to fix.

crypt.c

diff --git a/crypt.c b/crypt.c
index 2af3fd7e1c17a03ce715e950e2b82d7fae1277c1..b8a587cd0e55114f1ced030d5284adcd2d4a96b4 100644 (file)
--- a/crypt.c
+++ b/crypt.c
@@ -154,8 +154,8 @@ int get_public_key(const char *key_file, struct asymmetric_key **result)
                goto out;
        ret = is_ssh_rsa_key(map, map_size);
        if (!ret) {
                goto out;
        ret = is_ssh_rsa_key(map, map_size);
        if (!ret) {
-               para_munmap(map, map_size);
-               return -E_SSH_PARSE;
+               ret = -E_SSH_PARSE;
+               goto out_unmap;
        }
        cp = map + ret;
        encoded_size = map_size - ret;
        }
        cp = map + ret;
        encoded_size = map_size - ret;