diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-05-11 20:58:46 +0400 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-05-11 20:58:46 +0400 |
commit | 5f265b755a92e7efdbd0d18694913209dfd9e055 (patch) | |
tree | e6644e9f97dab0198ad771e1d330e02a7cce8553 /shell | |
parent | 9d94deabd398634c6d1c601ba276f5afd97b2050 (diff) |
Fix a segfault in lash, hush, and cmdedit. Each of these used
xgetcwd, but did not check the return for a NULL, and then continued
to call strlen on the NULL when the cwd had been removed from under it.
-Erik
Diffstat (limited to 'shell')
-rw-r--r-- | shell/cmdedit.c | 4 | ||||
-rw-r--r-- | shell/hush.c | 6 | ||||
-rw-r--r-- | shell/lash.c | 9 |
3 files changed, 17 insertions, 2 deletions
diff --git a/shell/cmdedit.c b/shell/cmdedit.c index ce5450032..ec9939312 100644 --- a/shell/cmdedit.c +++ b/shell/cmdedit.c @@ -355,6 +355,10 @@ static void parse_prompt(const char *prmt_ptr) char c; char *pbuf; + if (!pwd_buf) { + pwd_buf=unknown; + } + while (*prmt_ptr) { pbuf = buf; pbuf[1] = 0; diff --git a/shell/hush.c b/shell/hush.c index abc8f6e60..9a2243a89 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -429,6 +429,8 @@ static int builtin_cd(struct child_prog *child) return EXIT_FAILURE; } cwd = xgetcwd(cwd); + if (!cwd) + cwd = unknown; return EXIT_SUCCESS; } @@ -568,6 +570,8 @@ static int builtin_jobs(struct child_prog *child) static int builtin_pwd(struct child_prog *dummy) { cwd = xgetcwd(cwd); + if (!cwd) + cwd = unknown; puts(cwd); return EXIT_SUCCESS; } @@ -2307,6 +2311,8 @@ int shell_main(int argc, char **argv) /* initialize the cwd -- this is never freed...*/ cwd = xgetcwd(0); + if (!cwd) + cwd = unknown; #ifdef BB_FEATURE_COMMAND_EDITING cmdedit_set_initial_prompt(); #else diff --git a/shell/lash.c b/shell/lash.c index 1d128355c..0129d6c02 100644 --- a/shell/lash.c +++ b/shell/lash.c @@ -297,7 +297,8 @@ static int builtin_cd(struct child_prog *child) return EXIT_FAILURE; } cwd = xgetcwd(cwd); - + if (!cwd) + cwd = unknown; return EXIT_SUCCESS; } @@ -412,6 +413,9 @@ static int builtin_jobs(struct child_prog *child) /* built-in 'pwd' handler */ static int builtin_pwd(struct child_prog *dummy) { + cwd = xgetcwd(cwd); + if (!cwd) + cwd = unknown; printf( "%s\n", cwd); return EXIT_SUCCESS; } @@ -1827,7 +1831,6 @@ void free_memory(void) { if (cwd) { free(cwd); - cwd = NULL; } if (local_pending_command) free(local_pending_command); @@ -1919,6 +1922,8 @@ int shell_main(int argc_l, char **argv_l) /* initialize the cwd -- this is never freed...*/ cwd = xgetcwd(0); + if (!cwd) + cwd = unknown; #ifdef BB_FEATURE_CLEAN_UP atexit(free_memory); |