Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/crypto/external/bsd/netpgp/dist/src/lib plug some memory lea...



details:   https://anonhg.NetBSD.org/src/rev/8e95e5a2e66c
branches:  trunk
changeset: 767874:8e95e5a2e66c
user:      agc <agc%NetBSD.org@localhost>
date:      Tue Aug 02 07:16:56 2011 +0000

description:
plug some memory leaks in error paths

diffstat:

 crypto/external/bsd/netpgp/dist/src/lib/netpgp.c |  27 ++++++++++++++++-------
 1 files changed, 19 insertions(+), 8 deletions(-)

diffs (83 lines):

diff -r 0f9735545ee3 -r 8e95e5a2e66c crypto/external/bsd/netpgp/dist/src/lib/netpgp.c
--- a/crypto/external/bsd/netpgp/dist/src/lib/netpgp.c  Tue Aug 02 05:36:45 2011 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/lib/netpgp.c  Tue Aug 02 07:16:56 2011 +0000
@@ -34,7 +34,7 @@
 
 #if defined(__NetBSD__)
 __COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: netpgp.c,v 1.93 2011/08/02 05:36:45 agc Exp $");
+__RCSID("$NetBSD: netpgp.c,v 1.94 2011/08/02 07:16:56 agc Exp $");
 #endif
 
 #include <sys/types.h>
@@ -314,10 +314,13 @@
                        filename = f;
                }
                if ((secring = calloc(1, sizeof(*secring))) == NULL) {
+                       free(pubring);
                        (void) fprintf(stderr, "readsshkeys: bad alloc\n");
                        return 0;
                }
                if (!pgp_ssh2_readkeys(netpgp->io, pubring, secring, NULL, filename, hashtype)) {
+                       free(pubring);
+                       free(secring);
                        (void) fprintf(stderr, "readsshkeys: can't read sec %s\n", filename);
                        return 0;
                }
@@ -1911,9 +1914,12 @@
        size_t           cc;
        char             f[MAXPATHLEN];
 
+       keyring = NULL;
+       io = NULL;
+       cc = 0;
        if ((io = calloc(1, sizeof(pgp_io_t))) == NULL) {
                (void) fprintf(stderr, "netpgp_save_sshpub: bad alloc 1\n");
-               return 0;
+               goto done;
        }
        io->outs = stdout;
        io->errs = stderr;
@@ -1923,23 +1929,23 @@
        savepubkey(s, f, sizeof(f));
        if ((keyring = calloc(1, sizeof(*keyring))) == NULL) {
                (void) fprintf(stderr, "netpgp_save_sshpub: bad alloc 2\n");
-               return 0;
+               goto done;
        }
        if (!pgp_keyring_fileread(netpgp->pubring = keyring, 1, f)) {
                (void) fprintf(stderr, "can't import key\n");
-               return 0;
+               goto done;
        }
        /* get rsa key */
        k = 0;
        key = pgp_getnextkeybyname(netpgp->io, netpgp->pubring, userid, &k);
        if (key == NULL) {
                (void) fprintf(stderr, "no key found for '%s'\n", userid);
-               return 0;
+               goto done;
        }
        if (key->key.pubkey.alg != PGP_PKA_RSA) {
                /* we're not interested in supporting DSA either :-) */
                (void) fprintf(stderr, "key not RSA '%s'\n", userid);
-               return 0;
+               goto done;
        }
        /* XXX - check trust sigs */
        /* XXX - check expiry */
@@ -1950,7 +1956,12 @@
        cc = formatstring((char *)out, (const uint8_t *)"ssh-rsa", 7);
        cc += formatbignum((char *)&out[cc], key->key.pubkey.key.rsa.e);
        cc += formatbignum((char *)&out[cc], key->key.pubkey.key.rsa.n);
-       free(io);
-       free(keyring);
+done:
+       if (io) {
+               free(io);
+       }
+       if (keyring) {
+               free(keyring);
+       }
        return (int)cc;
 }



Home | Main Index | Thread Index | Old Index