@@ -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;
* }
*/
@@ -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;
* }
*/
@@ -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;
* }
*/
@@ -66,7 +66,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 *);
@@ -1005,7 +1005,7 @@ void pseudo_dropenv() {
}
char **
-pseudo_dropenvp(char * const *envp) {
+pseudo_dropenvp(char **envp) {
char **new_envp;
int i, j;
@@ -1036,6 +1036,7 @@ pseudo_dropenvp(char * const *envp) {
}
}
new_envp[j++] = NULL;
+ free(envp);
return new_envp;
}
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> --- 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(-)