From patchwork Wed Sep 9 00:48:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 1429 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director9.mail.ord1d.rsapps.net ([172.27.255.58]) by backend30.mail.ord1d.rsapps.net with LMTP id EGwPBk2zWF/LCAAAIUCqbw (envelope-from ) for ; Wed, 09 Sep 2020 06:49:49 -0400 Received: from proxy19.mail.iad3a.rsapps.net ([172.27.255.58]) by director9.mail.ord1d.rsapps.net with LMTP id 2IPVBU2zWF/jHAAAalYnBA (envelope-from ) for ; Wed, 09 Sep 2020 06:49:49 -0400 Received: from smtp29.gate.iad3a ([172.27.255.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy19.mail.iad3a.rsapps.net with LMTPS id QD5+OkyzWF8jAwAAXy6Yeg (envelope-from ) for ; Wed, 09 Sep 2020 06:49:48 -0400 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.105.38.7] Authentication-Results: smtp29.gate.iad3a.rsapps.net; iprev=pass policy.iprev="216.105.38.7"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dmarc=none (p=nil; dis=none) header.from=greenie.muc.de X-Suspicious-Flag: YES X-Classification-ID: 2db8919c-f28a-11ea-ab5b-52540071c87c-1-1 Received: from [216.105.38.7] ([216.105.38.7:42324] helo=lists.sourceforge.net) by smtp29.gate.iad3a.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id B6/F2-19217-B43B85F5; Wed, 09 Sep 2020 06:49:48 -0400 Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1kFxeo-0005Dv-7Y; Wed, 09 Sep 2020 10:48:54 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kFxek-0005Dl-Uo for openvpn-devel@lists.sourceforge.net; Wed, 09 Sep 2020 10:48:50 +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: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:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=4ea1z5XHSCx9Xf83IwIYUVZQOudy0t/nr690hX3HbOk=; b=NeRw2v+Tc7sVutYOXyXB627+bn zXTMcZFPTaFOdm/0bO6C2i8z8twppxcA+lqjcEepd8x5NBjSI3xLE7U6kfLrWh+Lurm+3PsM6Wg+d cVDsrPtRTu7mrBX5p/d2GhuSlWZ5MwuzehkVqrhqO9HDCXq/Uc76WzNlseZDvI0g9yeo=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version: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:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=4ea1z5XHSCx9Xf83IwIYUVZQOudy0t/nr690hX3HbOk=; b=M 4w7XiR/F4cptGWzspUx5K2dg6mPajX0Sto7tKnl+FrjB/MwT3l2WftDpqwgCUS6WIXGChHe2MRmw9 BbrXENAFHkl1V12Y4MfaHhKksT49xmwrDdYxB9JzSVRJUprbanByO5lhUoUFGqjkBJAhHHjA66l/W cqyfFQ0uDy3CFefQ=; Received: from dhcp-174.greenie.muc.de ([193.149.48.174] helo=blue.greenie.muc.de) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1kFxef-000Qwz-Jb for openvpn-devel@lists.sourceforge.net; Wed, 09 Sep 2020 10:48:50 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.14.9/8.14.9) with ESMTP id 089Ambrx006175 for ; Wed, 9 Sep 2020 12:48:38 +0200 Received: (from gert@localhost) by blue.greenie.muc.de (8.15.2/8.14.9/Submit) id 089AmbpT006174 for openvpn-devel@lists.sourceforge.net; Wed, 9 Sep 2020 12:48:37 +0200 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Wed, 9 Sep 2020 12:48:37 +0200 Message-Id: <20200909104837.6123-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URIs: muc.de] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record X-Headers-End: 1kFxef-000Qwz-Jb Subject: [Openvpn-devel] [PATCH] Handle NULL returns from calloc() in sample plugins. 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 This is basic housekeeping, adding NULL checks to context initialization of the sample plugin collection which are missing it. Realistically, this can never happen, but since these are supposed to be "good examples", not checking calloc() return isn't one. Trac: #587 Reported-By: Dogbert (in Trac) Signed-off-by: Gert Doering Acked-By: David Sommerseth --- sample/sample-plugins/defer/simple.c | 5 +++++ .../keying-material-exporter-demo/keyingmaterialexporter.c | 6 ++++++ sample/sample-plugins/log/log.c | 5 +++++ sample/sample-plugins/log/log_v3.c | 5 +++++ sample/sample-plugins/simple/simple.c | 5 +++++ 5 files changed, 26 insertions(+) diff --git a/sample/sample-plugins/defer/simple.c b/sample/sample-plugins/defer/simple.c index d18695b5..64338b4a 100644 --- a/sample/sample-plugins/defer/simple.c +++ b/sample/sample-plugins/defer/simple.c @@ -141,6 +141,11 @@ openvpn_plugin_open_v1(unsigned int *type_mask, const char *argv[], const char * * Allocate our context */ context = (struct plugin_context *) calloc(1, sizeof(struct plugin_context)); + if (context == NULL) + { + printf("PLUGIN: allocating memory for context failed\n"); + return NULL; + } context->test_deferred_auth = atoi_null0(get_env("test_deferred_auth", envp)); printf("TEST_DEFERRED_AUTH %d\n", context->test_deferred_auth); diff --git a/sample/sample-plugins/keying-material-exporter-demo/keyingmaterialexporter.c b/sample/sample-plugins/keying-material-exporter-demo/keyingmaterialexporter.c index b53f13f6..27275f33 100644 --- a/sample/sample-plugins/keying-material-exporter-demo/keyingmaterialexporter.c +++ b/sample/sample-plugins/keying-material-exporter-demo/keyingmaterialexporter.c @@ -92,6 +92,12 @@ openvpn_plugin_open_v3(const int version, { struct plugin *plugin = calloc(1, sizeof(*plugin)); + if (plugin == NULL) + { + printf("PLUGIN: allocating memory for context failed\n"); + return OPENVPN_PLUGIN_FUNC_ERROR; + } + plugin->type = get_env("remote_1", args->envp) ? CLIENT : SERVER; plugin->log = args->callbacks->plugin_log; diff --git a/sample/sample-plugins/log/log.c b/sample/sample-plugins/log/log.c index b5c1c3be..a782aa97 100644 --- a/sample/sample-plugins/log/log.c +++ b/sample/sample-plugins/log/log.c @@ -78,6 +78,11 @@ openvpn_plugin_open_v1(unsigned int *type_mask, const char *argv[], const char * * Allocate our context */ context = (struct plugin_context *) calloc(1, sizeof(struct plugin_context)); + if (context == NULL) + { + printf("PLUGIN: allocating memory for context failed\n"); + return NULL; + } /* * Set the username/password we will require. diff --git a/sample/sample-plugins/log/log_v3.c b/sample/sample-plugins/log/log_v3.c index 17b83f3f..13444997 100644 --- a/sample/sample-plugins/log/log_v3.c +++ b/sample/sample-plugins/log/log_v3.c @@ -113,6 +113,11 @@ openvpn_plugin_open_v3(const int v3structver, /* Allocate our context */ context = (struct plugin_context *) calloc(1, sizeof(struct plugin_context)); + if (context == NULL) + { + printf("PLUGIN: allocating memory for context failed\n"); + return OPENVPN_PLUGIN_FUNC_ERROR; + } /* Set the username/password we will require. */ context->username = "foo"; diff --git a/sample/sample-plugins/simple/simple.c b/sample/sample-plugins/simple/simple.c index 950c547e..60cfea4f 100644 --- a/sample/sample-plugins/simple/simple.c +++ b/sample/sample-plugins/simple/simple.c @@ -80,6 +80,11 @@ openvpn_plugin_open_v1(unsigned int *type_mask, const char *argv[], const char * * Allocate our context */ context = (struct plugin_context *) calloc(1, sizeof(struct plugin_context)); + if (context == NULL) + { + printf("PLUGIN: allocating memory for context failed\n"); + return NULL; + } /* * Set the username/password we will require.