diff options
| author | Ron Yorston <rmy@pobox.com> | 2020-06-21 12:57:12 +0100 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2020-06-21 12:57:12 +0100 |
| commit | 4f4e9e0d3366ec607d8765278b9753e41bdd544f (patch) | |
| tree | 6cd961798e45b2f891a5bf1541be6cb94f01e410 /shell | |
| parent | 53aca1b56db730b0103f5ec2e692327237a775e2 (diff) | |
| download | busybox-w32-4f4e9e0d3366ec607d8765278b9753e41bdd544f.tar.gz busybox-w32-4f4e9e0d3366ec607d8765278b9753e41bdd544f.tar.bz2 busybox-w32-4f4e9e0d3366ec607d8765278b9753e41bdd544f.zip | |
ash: skip NULL argv during forkshell
Alter argv_size()/argv_copy() to omit argv from the forkshell
block if it's NULL.
Improve forkshell debug code to properly account for parts of
funcblock which aren't being used.
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/ash.c | 111 |
1 files changed, 44 insertions, 67 deletions
diff --git a/shell/ash.c b/shell/ash.c index decd6c0f7..b51a3fb82 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
| @@ -15824,12 +15824,14 @@ atab_copy(struct alias **atabp) | |||
| 15824 | static struct datasize | 15824 | static struct datasize |
| 15825 | argv_size(struct datasize ds, char **p) | 15825 | argv_size(struct datasize ds, char **p) |
| 15826 | { | 15826 | { |
| 15827 | while (p && *p) { | 15827 | if (p) { |
| 15828 | while (*p) { | ||
| 15829 | ds.funcblocksize += sizeof(char *); | ||
| 15830 | ds.funcstringsize += align_len(*p); | ||
| 15831 | p++; | ||
| 15832 | } | ||
| 15828 | ds.funcblocksize += sizeof(char *); | 15833 | ds.funcblocksize += sizeof(char *); |
| 15829 | ds.funcstringsize += align_len(*p); | ||
| 15830 | p++; | ||
| 15831 | } | 15834 | } |
| 15832 | ds.funcblocksize += sizeof(char *); | ||
| 15833 | return ds; | 15835 | return ds; |
| 15834 | } | 15836 | } |
| 15835 | 15837 | ||
| @@ -15841,17 +15843,20 @@ argv_copy(char **p) | |||
| 15841 | int i = 0; | 15843 | int i = 0; |
| 15842 | #endif | 15844 | #endif |
| 15843 | 15845 | ||
| 15844 | while (p && *p) { | 15846 | if (p) { |
| 15847 | while (*p) { | ||
| 15848 | new = funcblock; | ||
| 15849 | funcblock = (char *) funcblock + sizeof(char *); | ||
| 15850 | *new = nodeckstrdup(*p); | ||
| 15851 | SAVE_PTR(*new, xasprintf("argv[%d] '%s'", i++, *p), FREE); | ||
| 15852 | p++; | ||
| 15853 | } | ||
| 15845 | new = funcblock; | 15854 | new = funcblock; |
| 15846 | funcblock = (char *) funcblock + sizeof(char *); | 15855 | funcblock = (char *) funcblock + sizeof(char *); |
| 15847 | *new = nodeckstrdup(*p); | 15856 | *new = NULL; |
| 15848 | SAVE_PTR(*new, xasprintf("argv[%d] '%s'", i++, *p), FREE); | 15857 | return start; |
| 15849 | p++; | ||
| 15850 | } | 15858 | } |
| 15851 | new = funcblock; | 15859 | return NULL; |
| 15852 | funcblock = (char *) funcblock + sizeof(char *); | ||
| 15853 | *new = NULL; | ||
| 15854 | return start; | ||
| 15855 | } | 15860 | } |
| 15856 | 15861 | ||
| 15857 | #if MAX_HISTORY | 15862 | #if MAX_HISTORY |
| @@ -16069,6 +16074,7 @@ forkshell_copy(struct forkshell *fs, struct forkshell *new) | |||
| 16069 | 16074 | ||
| 16070 | #if FORKSHELL_DEBUG | 16075 | #if FORKSHELL_DEBUG |
| 16071 | /* fp and notes can each be NULL */ | 16076 | /* fp and notes can each be NULL */ |
| 16077 | #define NUM_BLOCKS 7 | ||
| 16072 | static void | 16078 | static void |
| 16073 | forkshell_print(FILE *fp0, struct forkshell *fs, const char **notes) | 16079 | forkshell_print(FILE *fp0, struct forkshell *fs, const char **notes) |
| 16074 | { | 16080 | { |
| @@ -16077,8 +16083,10 @@ forkshell_print(FILE *fp0, struct forkshell *fs, const char **notes) | |||
| 16077 | char *lfuncstring; | 16083 | char *lfuncstring; |
| 16078 | char *lrelocate; | 16084 | char *lrelocate; |
| 16079 | char *s; | 16085 | char *s; |
| 16080 | int count, i; | 16086 | int count, i, total; |
| 16081 | int size_gvp, size_gmp, size_cmdtable, size_atab, size_history, total; | 16087 | int size[NUM_BLOCKS]; |
| 16088 | char *lptr[NUM_BLOCKS+1]; | ||
| 16089 | enum {GVP, GMP, CMDTABLE, NODE, ARGV, ATAB, HISTORY, FUNCSTRING}; | ||
| 16082 | const char *fsname[] = { | 16090 | const char *fsname[] = { |
| 16083 | "FS_OPENHERE", | 16091 | "FS_OPENHERE", |
| 16084 | "FS_EVALBACKCMD", | 16092 | "FS_EVALBACKCMD", |
| @@ -16112,60 +16120,29 @@ forkshell_print(FILE *fp0, struct forkshell *fs, const char **notes) | |||
| 16112 | 16120 | ||
| 16113 | /* funcblocksize is zero for FS_OPENHERE */ | 16121 | /* funcblocksize is zero for FS_OPENHERE */ |
| 16114 | if (fs->funcblocksize != 0) { | 16122 | if (fs->funcblocksize != 0) { |
| 16115 | size_gvp = (int)((char *)fs->gmp-(char *)fs->gvp); | 16123 | /* Depending on the configuration and the type of forkshell |
| 16116 | size_gmp = (int)((char *)fs->cmdtable-(char *)fs->gmp); | 16124 | * some items may not be present. */ |
| 16117 | #if ENABLE_ASH_ALIAS && MAX_HISTORY | 16125 | lptr[FUNCSTRING] = lfuncstring; |
| 16118 | if (fs->atab) { | 16126 | #if MAX_HISTORY |
| 16119 | size_cmdtable = (int)((char *)fs->atab-(char *)fs->cmdtable); | 16127 | lptr[HISTORY] = fs->history ? (char *)fs->history : lptr[FUNCSTRING]; |
| 16120 | if (fs->history) { | ||
| 16121 | size_atab = (int)((char *)fs->history-(char *)fs->atab); | ||
| 16122 | size_history = (int)(lfuncstring-(char *)fs->history); | ||
| 16123 | } | ||
| 16124 | else { | ||
| 16125 | size_atab = (int)(lfuncstring-(char *)fs->atab); | ||
| 16126 | size_history = 0; | ||
| 16127 | } | ||
| 16128 | } | ||
| 16129 | else { | ||
| 16130 | size_atab = 0; | ||
| 16131 | if (fs->history) { | ||
| 16132 | size_cmdtable = (int)((char *)fs->history-(char *)fs->cmdtable); | ||
| 16133 | size_history = (int)(lfuncstring-(char *)fs->history); | ||
| 16134 | } | ||
| 16135 | else { | ||
| 16136 | size_cmdtable = (int)(lfuncstring-(char *)fs->cmdtable); | ||
| 16137 | size_history = 0; | ||
| 16138 | } | ||
| 16139 | } | ||
| 16140 | #elif ENABLE_ASH_ALIAS | ||
| 16141 | size_history = 0; | ||
| 16142 | if (fs->atab) { | ||
| 16143 | size_cmdtable = (int)((char *)fs->atab-(char *)fs->cmdtable); | ||
| 16144 | size_atab = (int)(lfuncstring-(char *)fs->atab); | ||
| 16145 | } | ||
| 16146 | else { | ||
| 16147 | size_cmdtable = (int)(lfuncstring-(char *)fs->cmdtable); | ||
| 16148 | size_atab = 0; | ||
| 16149 | } | ||
| 16150 | #elif MAX_HISTORY | ||
| 16151 | size_atab = 0; | ||
| 16152 | if (fs->history) { | ||
| 16153 | size_cmdtable = (int)((char *)fs->history-(char *)fs->cmdtable); | ||
| 16154 | size_history = (int)(lfuncstring-(char *)fs->history); | ||
| 16155 | } | ||
| 16156 | else { | ||
| 16157 | size_cmdtable = (int)(lfuncstring-(char *)fs->cmdtable); | ||
| 16158 | size_history = 0; | ||
| 16159 | } | ||
| 16160 | #else | 16128 | #else |
| 16161 | size_cmdtable = (int)(lfuncstring-(char *)fs->cmdtable); | 16129 | lptr[HISTORY] = lptr[FUNCSTRING]; |
| 16162 | size_atab = 0; | 16130 | #endif |
| 16163 | size_history = 0; | 16131 | lptr[ATAB] = IF_ASH_ALIAS(fs->atab ? (char *)fs->atab :) lptr[HISTORY]; |
| 16164 | #endif | 16132 | lptr[ARGV] = fs->argv ? (char *)fs->argv : lptr[ATAB]; |
| 16165 | total = size_gvp + size_gmp + size_cmdtable + size_atab + size_history; | 16133 | lptr[NODE] = fs->n ? (char *)fs->n : lptr[ARGV]; |
| 16166 | fprintf(fp, "funcblocksize %6d = %d + %d + %d + %d + %d = %d\n\n", | 16134 | lptr[CMDTABLE] = (char *)fs->cmdtable; |
| 16167 | fs->funcblocksize, size_gvp, size_gmp, size_cmdtable, | 16135 | lptr[GMP] = (char *)fs->gmp; |
| 16168 | size_atab, size_history, total); | 16136 | lptr[GVP] = (char *)fs->gvp; |
| 16137 | |||
| 16138 | fprintf(fp, "funcblocksize %6d = ", fs->funcblocksize); | ||
| 16139 | total = 0; | ||
| 16140 | for (i=0; i<NUM_BLOCKS; ++i) { | ||
| 16141 | size[i] = (int)(lptr[i+1] - lptr[i]); | ||
| 16142 | total += size[i]; | ||
| 16143 | fprintf(fp, "%d %c ", size[i], i == NUM_BLOCKS - 1 ? '=' : '+'); | ||
| 16144 | } | ||
| 16145 | fprintf(fp, "%d\n\n", total); | ||
| 16169 | } | 16146 | } |
| 16170 | else { | 16147 | else { |
| 16171 | fprintf(fp, "\n"); | 16148 | fprintf(fp, "\n"); |
