mirror of
https://github.com/apache/nuttx.git
synced 2026-09-22 22:55:02 +08:00
env_dup: Fix copying of env between address environments
If address environments are in use, it is not possible to simply memcpy from from one process to another. The current implementation of env_dup does precisely this and thus, it fails at once when it is attempted between two user processes. The solution is to use the kernel's heap as an intermediate buffer. This is a simple, effective and common way to do a fork(). Obviously this is not needed for kernel processes.
This commit is contained in:
@@ -42,7 +42,9 @@ namespace std
|
||||
|
||||
// Environment variable support
|
||||
|
||||
#ifndef CONFIG_DISABLE_ENVIRON
|
||||
using ::get_environ_ptr;
|
||||
#endif
|
||||
using ::getenv;
|
||||
using ::putenv;
|
||||
using ::clearenv;
|
||||
|
||||
@@ -258,7 +258,8 @@ int unload_module(FAR struct binary_s *bin);
|
||||
****************************************************************************/
|
||||
|
||||
int exec_module(FAR const struct binary_s *binp,
|
||||
FAR const char *filename, FAR char * const *argv);
|
||||
FAR const char *filename, FAR char * const *argv,
|
||||
FAR char * const *envp);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: exec
|
||||
@@ -338,6 +339,8 @@ int exec(FAR const char *filename, FAR char * const *argv,
|
||||
* program.
|
||||
* argv - A pointer to an array of string arguments. The end of the
|
||||
* array is indicated with a NULL entry.
|
||||
* envp - A pointer to an array of environment strings. Terminated with
|
||||
* a NULL entry.
|
||||
* exports - The address of the start of the caller-provided symbol
|
||||
* table. This symbol table contains the addresses of symbols
|
||||
* exported by the caller and made available for linking the
|
||||
@@ -353,8 +356,8 @@ int exec(FAR const char *filename, FAR char * const *argv,
|
||||
****************************************************************************/
|
||||
|
||||
int exec_spawn(FAR const char *filename, FAR char * const *argv,
|
||||
FAR const struct symtab_s *exports, int nexports,
|
||||
FAR const posix_spawnattr_t *attr);
|
||||
FAR char * const *envp, FAR const struct symtab_s *exports,
|
||||
int nexports, FAR const posix_spawnattr_t *attr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: binfmt_exit
|
||||
|
||||
@@ -933,6 +933,7 @@ FAR struct streamlist *nxsched_get_streams(void);
|
||||
* argv - A pointer to an array of input parameters. The array
|
||||
* should be terminated with a NULL argv[] value. If no
|
||||
* parameters are required, argv may be NULL.
|
||||
* envp - A pointer to the program's environment, envp may be NULL
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; negative error value on failure appropriately. (See
|
||||
@@ -945,7 +946,7 @@ FAR struct streamlist *nxsched_get_streams(void);
|
||||
|
||||
int nxtask_init(FAR struct task_tcb_s *tcb, const char *name, int priority,
|
||||
FAR void *stack, uint32_t stack_size, main_t entry,
|
||||
FAR char * const argv[]);
|
||||
FAR char * const argv[], FAR char * const envp[]);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxtask_uninit
|
||||
|
||||
@@ -138,7 +138,11 @@ void arc4random_buf(FAR void *bytes, size_t nbytes);
|
||||
|
||||
/* Environment variable support */
|
||||
|
||||
#ifdef CONFIG_DISABLE_ENVIRON
|
||||
# define get_environ_ptr() NULL
|
||||
#else
|
||||
FAR char **get_environ_ptr(void);
|
||||
#endif
|
||||
FAR char *getenv(FAR const char *name);
|
||||
int putenv(FAR const char *string);
|
||||
int clearenv(void);
|
||||
|
||||
Reference in New Issue
Block a user