aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2024-08-16 12:48:43 +0100
committerRon Yorston <rmy@pobox.com>2024-08-16 13:21:48 +0100
commit027fb22e28fecc588d9e088a8d7d77fb63c7dc7b (patch)
tree2119a2e1fc4cff76dc0bf4510529e6d5068d19f2
parent2b00b4311ecf4c6f6331f8c969934fa792f7e15c (diff)
downloadbusybox-w32-027fb22e28fecc588d9e088a8d7d77fb63c7dc7b.tar.gz
busybox-w32-027fb22e28fecc588d9e088a8d7d77fb63c7dc7b.tar.bz2
busybox-w32-027fb22e28fecc588d9e088a8d7d77fb63c7dc7b.zip
ash: allow additional element in argv array
tryexec() in ash relies on all callers of shellexec() having an additional unused element before the start of its argv array. In busybox-w32 this was not the case when shellexec() was called from forkshell_shellexec(), as only the actual contents of the argv array were copied into the forkshell data block. In practice argv[-1] is only currently used when the 'which' applet is about to be run, so whatever got overwritten (probably cmdtable[30]) was unlikely to matter. Still, let's be correct and allocate the additional element. Adds 16 bytes.
-rw-r--r--shell/ash.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 340c7ce2f..94aabbc4c 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -16791,7 +16791,8 @@ argv_size(struct datasize ds, char **p)
16791 ds.funcstringsize += align_len(*p); 16791 ds.funcstringsize += align_len(*p);
16792 p++; 16792 p++;
16793 } 16793 }
16794 ds.funcblocksize += sizeof(char *); 16794 // Allow for argv[-1] used by tryexec().
16795 ds.funcblocksize += 2 * sizeof(char *);
16795 } 16796 }
16796 return ds; 16797 return ds;
16797} 16798}
@@ -16805,6 +16806,8 @@ argv_copy(char **p)
16805#endif 16806#endif
16806 16807
16807 if (p) { 16808 if (p) {
16809 // argv[-1] for tryexec()
16810 funcblock = (char *) funcblock + sizeof(char *);
16808 while (*p) { 16811 while (*p) {
16809 new = funcblock; 16812 new = funcblock;
16810 funcblock = (char *) funcblock + sizeof(char *); 16813 funcblock = (char *) funcblock + sizeof(char *);
@@ -16815,7 +16818,7 @@ argv_copy(char **p)
16815 new = funcblock; 16818 new = funcblock;
16816 funcblock = (char *) funcblock + sizeof(char *); 16819 funcblock = (char *) funcblock + sizeof(char *);
16817 *new = NULL; 16820 *new = NULL;
16818 return start; 16821 return start + 1;
16819 } 16822 }
16820 return NULL; 16823 return NULL;
16821} 16824}