Util-Linux Archive mirror
 help / color / mirror / Atom feed
From: Tanish Yadav <devtany@gmail.com>
To: util-linux@vger.kernel.org
Subject: [PATCH] su: fix use after free in run_shell
Date: Tue, 5 Mar 2024 00:51:41 +0530	[thread overview]
Message-ID: <479fd0b8-bf67-4370-8250-bfd136a08195@gmail.com> (raw)

Do not free tmp for non login branch as basename may return a pointer to
some part of it.

Signed-off-by: Tanish Yadav <devtany@gmail.com>
---
  login-utils/su-common.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/login-utils/su-common.c b/login-utils/su-common.c
index 242b6ce4e..8cb54e1c1 100644
--- a/login-utils/su-common.c
+++ b/login-utils/su-common.c
@@ -851,10 +851,10 @@ static void run_shell(
		arg0[0] = '-';
		strcpy(arg0 + 1, shell_basename);
		args[0] = arg0;
+		free(tmp);
	} else {
-    args[0] = basename(tmp);
-  }
-  free(tmp);
+		args[0] = basename(tmp);
+	}

	if (su->fast_startup)
		args[argno++] = "-f";
--
2.44.0


             reply	other threads:[~2024-03-04 19:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-04 19:21 Tanish Yadav [this message]
2024-03-05  9:15 ` [PATCH] su: fix use after free in run_shell Karel Zak

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=479fd0b8-bf67-4370-8250-bfd136a08195@gmail.com \
    --to=devtany@gmail.com \
    --cc=util-linux@vger.kernel.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).