From 5f265b755a92e7efdbd0d18694913209dfd9e055 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Fri, 11 May 2001 16:58:46 +0000 Subject: 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 --- lash.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lash.c') diff --git a/lash.c b/lash.c index 1d128355c..0129d6c02 100644 --- a/lash.c +++ b/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); -- cgit v1.2.3