Fix a memory leak in pkey_add() error path. All current callers fatal
authorjsg <jsg@openbsd.org>
Wed, 31 May 2017 04:14:34 +0000 (04:14 +0000)
committerjsg <jsg@openbsd.org>
Wed, 31 May 2017 04:14:34 +0000 (04:14 +0000)
if pkey_add() fails.

usr.sbin/relayd/relayd.c

index a6472af..7583da7 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: relayd.c,v 1.168 2017/05/28 10:39:15 benno Exp $      */
+/*     $OpenBSD: relayd.c,v 1.169 2017/05/31 04:14:34 jsg Exp $        */
 
 /*
  * Copyright (c) 2007 - 2016 Reyk Floeter <reyk@openbsd.org>
@@ -1185,8 +1185,10 @@ pkey_add(struct relayd *env, EVP_PKEY *pkey, char *hash)
 
        ca_pkey->pkey = pkey;
        if (strlcpy(ca_pkey->pkey_hash, hash, sizeof(ca_pkey->pkey_hash)) >=
-           sizeof(ca_pkey->pkey_hash))
+           sizeof(ca_pkey->pkey_hash)) {
+               free(ca_pkey);
                return (NULL);
+       }
 
        TAILQ_INSERT_TAIL(env->sc_pkeys, ca_pkey, pkey_entry);