public inbox for [email protected]
 help / color / mirror / Atom feed
From: Alviro Iskandar Setiawan <[email protected]>
To: Ammar Faizi <[email protected]>
Cc: Alviro Iskandar Setiawan <[email protected]>,
	GNU/Weeb Mailing List <[email protected]>,
	Tea Inside Mailing List <[email protected]>,
	Ammar Faizi <[email protected]>,
	Louvian Lyndal <[email protected]>,
	Michael Arminto <[email protected]>
Subject: [PATCH teavpn2 2/3] net: iface: Fix a potential NULL pointer dereference
Date: Fri, 27 May 2022 00:02:26 +0000	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

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 <[email protected]>
Cc: Louvian Lyndal <[email protected]>
Cc: Michael Arminto <[email protected]>
Signed-off-by: Alviro Iskandar Setiawan <[email protected]>
---
 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


  parent reply	other threads:[~2022-05-27  0:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-27  0:02 [PATCH teavpn2 0/3] teavpn2 fixes Alviro Iskandar Setiawan
2022-05-27  0:02 ` [PATCH teavpn2 1/3] allocator: Fix `@errno` value when overflow Alviro Iskandar Setiawan
2022-05-27  0:02 ` Alviro Iskandar Setiawan [this message]
2022-05-27  0:02 ` [PATCH teavpn2 3/3] arch/linux: syscall: Fix retval checking in libc syscall Alviro Iskandar Setiawan
2022-05-27  0:14 ` [PATCH teavpn2 0/3] teavpn2 fixes Ammar Faizi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220527000227.1253934-3-alviro.iskandar@gnuweeb.org \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox