From patchwork Tue May 16 09:35:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Lichtenheld X-Patchwork-Id: 3218 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7300:7b9a:b0:c3:1364:a2a2 with SMTP id j26csp347258dyk; Tue, 16 May 2023 02:36:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6KETAwMOI3o0R34o0WuFjSvWXLt32VLcE3i6kc79Fr/FVopz9NfmHkgVPYcuFl1Osjvzc2 X-Received: by 2002:a5d:9901:0:b0:76c:76ea:3e8d with SMTP id x1-20020a5d9901000000b0076c76ea3e8dmr1690745iol.7.1684229807159; Tue, 16 May 2023 02:36:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684229807; cv=none; d=google.com; s=arc-20160816; b=0x+29YbHY2Cmz0miLcjecJ4YDEJeJY9JNuOWGR8Z54WZNzF5V1rGEbx21bbZ2kwair idb8zB0VrDE8pKIoVfzXkYMsk5k3QvGmvdDmSZCbBkUXC7n9I7Sn85OAT9uOsDNcePae qlC9LZGlo/ClNV/UZeGqmT9q68BS7Ksb+KKJSTphCIkl62EaYgePGhgqzerqb8EP1y6Y rvbXDEnVT0QFfytOlgP3Y0fW2My0i3kcJ6qc9Czh3zsENSHhbxyP3Ty3I94WC7j99lin tmxGgad2uofls636BrabHT51PnLRhuev8NNRHospNnZRvsCHX9xPSGHpzhxLbPtEBsXN dv3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature; bh=IZ6H3TnKtPXZdWAI+Xlf8OQciiaFREb33ZHU7fI2vZ0=; b=ASGTui80+DUEb9zXTK94tHWNl+cBCv4jOc3egzifjLNaDZhnl9aGH3rjbT8XlOIVTa notdwXeqOFcX8pTdjCiDw4e/eMyNIECjv9GtpTxNQx32KHvJb4kyXHzNBPIhPzya9+AA OCF4RlZylDZyCsFH4ucmaMTdbKwboWQqjATDUd5EfaA5/hwZ9xcoG0iwOwLbxd3XiOvg slOqQEkKVMi0c9RKiVq61KZaz+/MSKW7oeXJddmFn8cLobZa12vGMeyFH/otjmYwjWkN 96B4luhysZVgb4aRt6Xh8LQA97ynGW8t86exg7zettHHvZ9s71gEoTKxq7CCAIfeT8TC pTUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b="PWjmi/W/"; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=YlaLWVuT; dkim=neutral (body hash did not verify) header.i=@lichtenheld.com header.s=MBO0001 header.b=rU4NnsbW; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id z23-20020a5d84d7000000b0076c8841cc11si6190879ior.60.2023.05.16.02.36.46 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 May 2023 02:36:47 -0700 (PDT) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b="PWjmi/W/"; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=YlaLWVuT; dkim=neutral (body hash did not verify) header.i=@lichtenheld.com header.s=MBO0001 header.b=rU4NnsbW; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1pyr5z-00055K-Lu; Tue, 16 May 2023 09:35:52 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pyr5x-00055D-MR for openvpn-devel@lists.sourceforge.net; Tue, 16 May 2023 09:35:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=34DQ9MU59MbPscFDJFmKBo+89RJ2M7e1rq2zm2L3UZk=; b=PWjmi/W/K8dbfimaaRDKzYe1OD db9YbqlZLhtmQ0oAw04ZoP1px0RgtoEDItxVVNgb7N56xyBREXp6lqV+oV+jrSern0qKkf62UTfDy xPNBIcAmGF9jNWFzCK+Veec/nPYPbTXSI7ArlsctVBmSsoRTWri7/xJlEmZ/hFXeFSkA=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=34DQ9MU59MbPscFDJFmKBo+89RJ2M7e1rq2zm2L3UZk=; b=YlaLWVuTgfVhP4iwgYMaQAS1n1 HR+ONrWmAZOg3KEaptlzsLFLgmczDdrwQ211Clx2K2uclWyancF9udalFKJWU8z2PplLoEG9EIBZK 4cBPGMQ9vkXgSEx3US2JUOF8C2amol5a783bQf/U3R29SvDkEbqUTSgZ5RCM8xAlyxro=; Received: from mout-p-102.mailbox.org ([80.241.56.152]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1pyr5v-009NhJ-HW for openvpn-devel@lists.sourceforge.net; Tue, 16 May 2023 09:35:50 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4QLB1M1KyTz9stZ for ; Tue, 16 May 2023 11:35:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lichtenheld.com; s=MBO0001; t=1684229736; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=34DQ9MU59MbPscFDJFmKBo+89RJ2M7e1rq2zm2L3UZk=; b=rU4NnsbWvqWxAKmuOG4hyhWwklSfjV2ppo/hRukdCziJAnWYIX480I399h7QeQCJC+FNd7 aw3oMneupoMtO0RJhbCO3B+dW8M/yz5c/NIMXAmeClqtgdOXPyZ4ENsNmp2jxMVkrbu3mN HuX1ntmMnVoVMhxMEV67DLn77FUFEJ6IILlL692gGWk7+AdAI//lbhFERk4zAAHKWSb8E6 bLznlbs9eV1uzOvNwEGK0VDLPbg8RGrjoz3lNJ/lY0Jt7tGeieL5yXzHjFbO2tbT1HIVlQ t6muTfCb1nBX+gCg2E7DfcFbc/eZDtFDtl33UpIBFzztP9318KRzGfzcq6eI0w== From: Frank Lichtenheld To: openvpn-devel@lists.sourceforge.net Date: Tue, 16 May 2023 11:35:34 +0200 Message-Id: <20230516093534.26384-1-frank@lichtenheld.com> In-Reply-To: <20230515155339.38600-1-frank@lichtenheld.com> References: <20230515155339.38600-1-frank@lichtenheld.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4QLB1M1KyTz9stZ X-Spam-Score: -0.9 (/) X-Spam-Report: Spam detection software, running on the system "util-spamd-1.v13.lw.sourceforge.com", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: I was looking for memleaks in the code and found this one with cppcheck. Only an example, but no need to leave this bug in it. Also fix fortify problem in keying-material-exporter-demo so I can actually test the compilation of the sample plugins. Content analysis details: (-0.9 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [80.241.56.152 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-Headers-End: 1pyr5v-009NhJ-HW Subject: [Openvpn-devel] [PATCH v2] sample-plugins: Fix memleak in client-connect example plugin X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1765976116540822797?= X-GMAIL-MSGID: =?utf-8?q?1766042954330054563?= I was looking for memleaks in the code and found this one with cppcheck. Only an example, but no need to leave this bug in it. Also fix fortify problem in keying-material-exporter-demo so I can actually test the compilation of the sample plugins. v2: - remove unneccessary usages of snprintf, replace with strncpy. Change-Id: Ibd1b282afc4a28768be3f165f84ab60ca4d24a9b Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering --- .../sample-plugins/client-connect/sample-client-connect.c | 6 ++++++ .../keying-material-exporter-demo/keyingmaterialexporter.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/sample/sample-plugins/client-connect/sample-client-connect.c b/sample/sample-plugins/client-connect/sample-client-connect.c index 391de344..eb242126 100644 --- a/sample/sample-plugins/client-connect/sample-client-connect.c +++ b/sample/sample-plugins/client-connect/sample-client-connect.c @@ -454,6 +454,9 @@ openvpn_plugin_client_connect_v2(struct plugin_context *context, if (!rl->name || !rl->value) { plugin_log(PLOG_ERR, MODULE, "malloc(return_list->xx) failed"); + free(rl->name); + free(rl->value); + free(rl); return OPENVPN_PLUGIN_FUNC_ERROR; } @@ -509,6 +512,9 @@ openvpn_plugin_client_connect_defer_v2(struct plugin_context *context, if (!rl->name || !rl->value) { plugin_log(PLOG_ERR, MODULE, "malloc(return_list->xx) failed"); + free(rl->name); + free(rl->value); + free(rl); return OPENVPN_PLUGIN_FUNC_ERROR; } diff --git a/sample/sample-plugins/keying-material-exporter-demo/keyingmaterialexporter.c b/sample/sample-plugins/keying-material-exporter-demo/keyingmaterialexporter.c index 6a0a1f69..71badf2c 100644 --- a/sample/sample-plugins/keying-material-exporter-demo/keyingmaterialexporter.c +++ b/sample/sample-plugins/keying-material-exporter-demo/keyingmaterialexporter.c @@ -155,7 +155,7 @@ session_user_set(struct session *sess, X509 *x509) if (!strncasecmp(objbuf, "CN", 2)) { - snprintf(sess->user, sizeof(sess->user) - 1, (char *)buf); + strncpy(sess->user, (char *)buf, sizeof(sess->user) - 1); } OPENSSL_free(buf); @@ -234,7 +234,7 @@ tls_final(struct openvpn_plugin_args_func_in const *args, return OPENVPN_PLUGIN_FUNC_ERROR; } - snprintf(sess->key, sizeof(sess->key) - 1, "%s", key); + strncpy(sess->key, key, sizeof(sess->key) - 1); ovpn_note("app session key: %s", sess->key); switch (plugin->type)