mirror of
https://github.com/apache/nuttx.git
synced 2025-12-16 17:56:38 +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:
@@ -55,6 +55,8 @@
|
||||
* 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
|
||||
@@ -69,8 +71,8 @@
|
||||
****************************************************************************/
|
||||
|
||||
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)
|
||||
{
|
||||
FAR struct binary_s *bin;
|
||||
int pid;
|
||||
@@ -121,7 +123,7 @@ int exec_spawn(FAR const char *filename, FAR char * const *argv,
|
||||
|
||||
/* Then start the module */
|
||||
|
||||
pid = exec_module(bin, filename, argv);
|
||||
pid = exec_module(bin, filename, argv, envp);
|
||||
if (pid < 0)
|
||||
{
|
||||
ret = pid;
|
||||
@@ -228,7 +230,7 @@ int exec(FAR const char *filename, FAR char * const *argv,
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = exec_spawn(filename, argv, exports, nexports, NULL);
|
||||
ret = exec_spawn(filename, argv, NULL, exports, nexports, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
set_errno(-ret);
|
||||
|
||||
Reference in New Issue
Block a user