From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [138.197.159.143]) by gnuweeb.org (Postfix) with ESMTPSA id 37BFD7F720; Fri, 27 May 2022 00:02:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1653609760; bh=ey3OiFt2ClE7HdQV3cUgB99XgxIDqyh7AwjcrFUQHBU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fWTwXD25L/Oeg8F6MkNfy8/yZf/JVXnjtIQlG+b9vqeWwdleOeNAQNa9yl5T4AsSt 1aI66MqoyyHU0cpTjYXDjbi0nzLssl/zjRgGcs+KYtoj6sSe0umflrFY3O3SATMtu8 qOYfDO5BhN5kMdxDWYcghN39bYSoj1/Y7cPyhT8n0IGb+8q/RLYx9Ysu1bsznrbtl5 gXjeL8j3hlXIIeCaz3lpF0/aJcmEx35Fji1qM0cB/7/bKqrjds8VyKg5N1wiLmrMxg cwBkxvXvuD2VHtK2WBtibOLBPA6uTrOx46OyUdmTreqdLSWGz5twSwaH3QUP3GxhkP mMQfXC0TlLiXQ== From: Alviro Iskandar Setiawan To: Ammar Faizi Cc: Alviro Iskandar Setiawan , GNU/Weeb Mailing List , Tea Inside Mailing List , Ammar Faizi , Louvian Lyndal , Michael Arminto Subject: [PATCH teavpn2 2/3] net: iface: Fix a potential NULL pointer dereference Date: Fri, 27 May 2022 00:02:26 +0000 Message-Id: <20220527000227.1253934-3-alviro.iskandar@gnuweeb.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220527000227.1253934-1-alviro.iskandar@gnuweeb.org> References: <20220527000227.1253934-1-alviro.iskandar@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: The malloc() call in escapeshellarg() doesn't have a NULL check. This results in a potential NULL pointer dereference. Fix this by checking the return value of malloc(). Just return NULL directly if we hit the ENOMEM case. Fixes: 0cfd7f8b60a09000a4257015b592e79b0bd8b8bd ("net: rewire iface support for linux") Cc: Ammar Faizi Cc: Louvian Lyndal Cc: Michael Arminto Signed-off-by: Alviro Iskandar Setiawan --- src/teavpn2/net/linux/iface.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/teavpn2/net/linux/iface.c b/src/teavpn2/net/linux/iface.c index 010e195..a77c1c8 100644 --- a/src/teavpn2/net/linux/iface.c +++ b/src/teavpn2/net/linux/iface.c @@ -107,11 +107,14 @@ __cold static noinline char *escapeshellarg(char *alloc, const char *str, size_t x; char *cmd; - if (alloc == NULL) + if (alloc == NULL) { /* Worst case */ cmd = (char *)malloc((sizeof(char) * l * 4) + 1); - else + if (!cmd) + return NULL; + } else { cmd = alloc; + } #ifdef WIN32 cmd[y++] = '"'; -- Alviro Iskandar Setiawan