All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Hatle <mark.hatle@kernel.crashing.org>
To: yocto-patches@lists.yoctoproject.org
Cc: richard.purdie@linuxfoundation.org, frezidok1@gmail.com
Subject: [pseudo][PATCH 19/23] pseudo_util: Clean up memory handling for setupenvp results
Date: Thu,  2 Jul 2026 19:46:14 -0500	[thread overview]
Message-ID: <1783039578-31531-20-git-send-email-mark.hatle@kernel.crashing.org> (raw)
In-Reply-To: <1783039578-31531-1-git-send-email-mark.hatle@kernel.crashing.org>

From: Richard Purdie <richard.purdie@linuxfoundation.org>

Currently, the environment array allocated by pseudo_setupenvp is never
freed. Fix this (and the copy created by dropenvp).

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Message-ID: <20260701131336.3578279-5-richard.purdie@linuxfoundation.org>
Signed-off-by: Mark Hatle <mark.hatle@kernel.crashing.org>
---
 ports/common/guts/execve.c       | 4 +++-
 ports/common/guts/posix_spawn.c  | 4 +++-
 ports/common/guts/posix_spawnp.c | 4 +++-
 pseudo.h                         | 2 +-
 pseudo_util.c                    | 3 ++-
 5 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/ports/common/guts/execve.c b/ports/common/guts/execve.c
index 1144f7c..c2be66e 100644
--- a/ports/common/guts/execve.c
+++ b/ports/common/guts/execve.c
@@ -8,7 +8,7 @@
  * wrap_execve(const char *file, char *const *argv, char *const *envp) {
  *	int rc = -1;
  */
-	char * const *new_environ;
+	char **new_environ;
 	/* note:  we don't canonicalize this, because we are intentionally
 	 * NOT redirecting execs into the chroot environment.  If you try
 	 * to execute /bin/sh, you get the actual /bin/sh, not
@@ -30,6 +30,8 @@
 	sigprocmask(SIG_SETMASK, &pseudo_saved_sigmask, NULL);
 	rc = real_execve(file, argv, new_environ);
 
+	free(new_environ);
+
 /*	return rc;
  * }
  */
diff --git a/ports/common/guts/posix_spawn.c b/ports/common/guts/posix_spawn.c
index e15e68f..5896893 100644
--- a/ports/common/guts/posix_spawn.c
+++ b/ports/common/guts/posix_spawn.c
@@ -7,7 +7,7 @@
  * wrap_posix_spawn(pid_t *pid, const char *path, const posix_spawn_file_actions_t *file_actions, const posix_spawnattr_t *attrp, char *const *argv, char *const *envp) {
  *	int rc = -1;
  */
-	char * const *new_environ;
+	char **new_environ;
 	/* note:  we don't canonicalize this, because we are intentionally
 	 * NOT redirecting execs into the chroot environment.  If you try
 	 * to execute /bin/sh, you get the actual /bin/sh, not
@@ -29,6 +29,8 @@
 	sigprocmask(SIG_SETMASK, &pseudo_saved_sigmask, NULL);
 	rc = real_posix_spawn(pid, path, file_actions, attrp, argv, new_environ);
 
+	free(new_environ);
+
 /*	return rc;
  * }
  */
diff --git a/ports/common/guts/posix_spawnp.c b/ports/common/guts/posix_spawnp.c
index b2e1fc8..f3dc16b 100644
--- a/ports/common/guts/posix_spawnp.c
+++ b/ports/common/guts/posix_spawnp.c
@@ -7,7 +7,7 @@
  * wrap_posix_spawnp(pid_t *pid, const char *file, const posix_spawn_file_actions_t *file_actions, const posix_spawnattr_t *attrp, char *const *argv, char *const *envp) {
  *	int rc = -1;
  */
-	char * const *new_environ;
+	char **new_environ;
 	/* note:  we don't canonicalize this, because we are intentionally
 	 * NOT redirecting execs into the chroot environment.  If you try
 	 * to execute /bin/sh, you get the actual /bin/sh, not
@@ -29,6 +29,8 @@
 	sigprocmask(SIG_SETMASK, &pseudo_saved_sigmask, NULL);
 	rc = real_posix_spawnp(pid, file, file_actions, attrp, argv, new_environ);
 
+	free(new_environ);
+
 /*	return rc;
  * }
  */
diff --git a/pseudo.h b/pseudo.h
index ae1fe0d..e1129fa 100644
--- a/pseudo.h
+++ b/pseudo.h
@@ -86,7 +86,7 @@ void pseudo_new_pid(void);
 #define PSEUDO_MAX_LINK_RECURSION 16
 extern char *pseudo_fix_path(const char *, const char *, size_t, size_t, size_t *, int);
 extern void pseudo_dropenv(void);
-extern char **pseudo_dropenvp(char * const *);
+extern char **pseudo_dropenvp(char **);
 extern void pseudo_setupenv(void);
 extern char **pseudo_setupenvp(char * const *);
 extern char *pseudo_prefix_path(char *);
diff --git a/pseudo_util.c b/pseudo_util.c
index 10274b8..61d47e4 100644
--- a/pseudo_util.c
+++ b/pseudo_util.c
@@ -1050,7 +1050,7 @@ void pseudo_dropenv() {
 }
 
 char **
-pseudo_dropenvp(char * const *envp) {
+pseudo_dropenvp(char **envp) {
 	char **new_envp;
 	int i, j;
 
@@ -1081,6 +1081,7 @@ pseudo_dropenvp(char * const *envp) {
 		}
 	}
 	new_envp[j++] = NULL;
+	free(envp);
 	return new_envp;
 }
 
-- 
2.53.0



  parent reply	other threads:[~2026-07-03  0:46 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-03  0:45 [pseudo][PATCH 00/23] Create new pseudo 1.99.0 version Mark Hatle
2026-07-03  0:45 ` [pseudo][PATCH 01/23] Makefile.in: Move version to 1.99.0 to prep for 2.0 development Mark Hatle
2026-07-03  0:45 ` [pseudo][PATCH 02/23] pseudo_util: Add log severity flags Mark Hatle
2026-07-03  0:45 ` [pseudo][PATCH 03/23] pseudo: Add new logging macros Mark Hatle
2026-07-03  0:45 ` [pseudo][PATCH 04/23] pseudo_util: Change pseudo_diag() calls to appropriate " Mark Hatle
2026-07-03  0:46 ` [pseudo][PATCH 05/23] pseudo_db: Change pseudo_diag() calls to appropriate macros Mark Hatle
2026-07-03  0:46 ` [pseudo][PATCH 06/23] pseudo_client: " Mark Hatle
2026-07-03  0:46 ` [pseudo][PATCH 07/23] pseudo_server: " Mark Hatle
2026-07-03  0:46 ` [pseudo][PATCH 08/23] pseudo.c: " Mark Hatle
2026-07-03  0:46 ` [pseudo][PATCH 09/23] pseudolog.c: " Mark Hatle
2026-07-03  0:46 ` [pseudo][PATCH 10/23] wrappers: " Mark Hatle
2026-07-03  0:46 ` [pseudo][PATCH 11/23] pseudo: Change pseudo_diag() name to pseudo_log() Mark Hatle
2026-07-03  0:46 ` [pseudo][PATCH 12/23] pseudo_util: Add default log severity values Mark Hatle
2026-07-03 10:43   ` [yocto-patches] " Paul Barker
2026-07-03 12:44     ` Dmitry Sakhonchik
2026-07-03  0:46 ` [pseudo][PATCH 13/23] pseudo_util.c: strchr now returns const char Mark Hatle
2026-07-03  0:46 ` [pseudo][PATCH 14/23] test/test-openat2-func.c: Remove unusuaed saved_errno Mark Hatle
2026-07-03 10:44   ` [yocto-patches] " Paul Barker
2026-07-03  0:46 ` [pseudo][PATCH 15/23] pseudo.h: Avoid accessing unallocated memory Mark Hatle
2026-07-03  0:46 ` [pseudo][PATCH 16/23] pseudo_util: Avoid accidental free calls for without_libpseudo() Mark Hatle
2026-07-03  0:46 ` [pseudo][PATCH 17/23] pseudo_util: Ensure pseudo_setupenvp handles memory consistently Mark Hatle
2026-07-03  0:46 ` [pseudo][PATCH 18/23] pseudo_util: Avoid a memory leak in pseudo_dropenv() Mark Hatle
2026-07-03  0:46 ` Mark Hatle [this message]
2026-07-03  0:46 ` [pseudo][PATCH 20/23] exec*: Replace bash workaround to avoid memory corruption Mark Hatle
2026-07-03  0:46 ` [pseudo][PATCH 21/23] pseudo_util: Correctly free memory allocated by pseudo_setupenvp Mark Hatle
2026-07-03  0:46 ` [pseudo][PATCH 22/23] test-bash-exec-env: Add bash env test case Mark Hatle
2026-07-03 11:13   ` [yocto-patches] " Paul Barker
2026-07-03  0:46 ` [pseudo][PATCH 23/23] test: various: Move to makefile compilation Mark Hatle

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=1783039578-31531-20-git-send-email-mark.hatle@kernel.crashing.org \
    --to=mark.hatle@kernel.crashing.org \
    --cc=frezidok1@gmail.com \
    --cc=richard.purdie@linuxfoundation.org \
    --cc=yocto-patches@lists.yoctoproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.