From 8f4d0788dc1517838125f35ec156f8bdc096218b Mon Sep 17 00:00:00 2001 From: tobhe Date: Tue, 7 Sep 2021 14:06:23 +0000 Subject: [PATCH] Fix leak of m if message initialization fails. ok markus@ --- sbin/iked/ikev2_msg.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sbin/iked/ikev2_msg.c b/sbin/iked/ikev2_msg.c index 8e7a1f7ac7a..ee057559b5a 100644 --- a/sbin/iked/ikev2_msg.c +++ b/sbin/iked/ikev2_msg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ikev2_msg.c,v 1.79 2021/09/02 19:28:35 tobhe Exp $ */ +/* $OpenBSD: ikev2_msg.c,v 1.80 2021/09/07 14:06:23 tobhe Exp $ */ /* * Copyright (c) 2019 Tobias Heider @@ -165,12 +165,16 @@ ikev2_msg_copy(struct iked *env, struct iked_message *msg) return (NULL); len = ibuf_size(msg->msg_data) - msg->msg_offset; + if ((m = malloc(sizeof(*m))) == NULL) + return (NULL); + if ((ptr = ibuf_seek(msg->msg_data, msg->msg_offset, len)) == NULL || - (m = malloc(sizeof(*m))) == NULL || (buf = ikev2_msg_init(env, m, &msg->msg_peer, msg->msg_peerlen, &msg->msg_local, msg->msg_locallen, msg->msg_response)) == NULL || - ibuf_add(buf, ptr, len)) + ibuf_add(buf, ptr, len)) { + free(m); return (NULL); + } m->msg_fd = msg->msg_fd; m->msg_msgid = msg->msg_msgid; -- 2.20.1