diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-05-11 16:58:46 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-05-11 16:58:46 +0000 |
commit | 5f265b755a92e7efdbd0d18694913209dfd9e055 (patch) | |
tree | e6644e9f97dab0198ad771e1d330e02a7cce8553 | |
parent | 9d94deabd398634c6d1c601ba276f5afd97b2050 (diff) | |
download | busybox-w32-5f265b755a92e7efdbd0d18694913209dfd9e055.tar.gz busybox-w32-5f265b755a92e7efdbd0d18694913209dfd9e055.tar.bz2 busybox-w32-5f265b755a92e7efdbd0d18694913209dfd9e055.zip |
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
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | cmdedit.c | 4 | ||||
-rw-r--r-- | hush.c | 6 | ||||
-rw-r--r-- | include/libbb.h | 1 | ||||
-rw-r--r-- | lash.c | 9 | ||||
-rw-r--r-- | libbb/libbb.h | 1 | ||||
-rw-r--r-- | libbb/messages.c | 3 | ||||
-rw-r--r-- | shell/cmdedit.c | 4 | ||||
-rw-r--r-- | shell/hush.c | 6 | ||||
-rw-r--r-- | shell/lash.c | 9 |
10 files changed, 40 insertions, 5 deletions
@@ -259,7 +259,7 @@ endif | |||
259 | LIBBB_MSRC=libbb/messages.c | 259 | LIBBB_MSRC=libbb/messages.c |
260 | LIBBB_MESSAGES= full_version name_too_long omitting_directory not_a_directory \ | 260 | LIBBB_MESSAGES= full_version name_too_long omitting_directory not_a_directory \ |
261 | memory_exhausted invalid_date invalid_option io_error dash_dash_help \ | 261 | memory_exhausted invalid_date invalid_option io_error dash_dash_help \ |
262 | write_error too_few_args name_longer_than_foo | 262 | write_error too_few_args name_longer_than_foo unknown |
263 | LIBBB_MOBJ=$(patsubst %,$(LIBBB)/%.o, $(LIBBB_MESSAGES)) | 263 | LIBBB_MOBJ=$(patsubst %,$(LIBBB)/%.o, $(LIBBB_MESSAGES)) |
264 | 264 | ||
265 | 265 | ||
@@ -355,6 +355,10 @@ static void parse_prompt(const char *prmt_ptr) | |||
355 | char c; | 355 | char c; |
356 | char *pbuf; | 356 | char *pbuf; |
357 | 357 | ||
358 | if (!pwd_buf) { | ||
359 | pwd_buf=unknown; | ||
360 | } | ||
361 | |||
358 | while (*prmt_ptr) { | 362 | while (*prmt_ptr) { |
359 | pbuf = buf; | 363 | pbuf = buf; |
360 | pbuf[1] = 0; | 364 | pbuf[1] = 0; |
@@ -429,6 +429,8 @@ static int builtin_cd(struct child_prog *child) | |||
429 | return EXIT_FAILURE; | 429 | return EXIT_FAILURE; |
430 | } | 430 | } |
431 | cwd = xgetcwd(cwd); | 431 | cwd = xgetcwd(cwd); |
432 | if (!cwd) | ||
433 | cwd = unknown; | ||
432 | return EXIT_SUCCESS; | 434 | return EXIT_SUCCESS; |
433 | } | 435 | } |
434 | 436 | ||
@@ -568,6 +570,8 @@ static int builtin_jobs(struct child_prog *child) | |||
568 | static int builtin_pwd(struct child_prog *dummy) | 570 | static int builtin_pwd(struct child_prog *dummy) |
569 | { | 571 | { |
570 | cwd = xgetcwd(cwd); | 572 | cwd = xgetcwd(cwd); |
573 | if (!cwd) | ||
574 | cwd = unknown; | ||
571 | puts(cwd); | 575 | puts(cwd); |
572 | return EXIT_SUCCESS; | 576 | return EXIT_SUCCESS; |
573 | } | 577 | } |
@@ -2307,6 +2311,8 @@ int shell_main(int argc, char **argv) | |||
2307 | 2311 | ||
2308 | /* initialize the cwd -- this is never freed...*/ | 2312 | /* initialize the cwd -- this is never freed...*/ |
2309 | cwd = xgetcwd(0); | 2313 | cwd = xgetcwd(0); |
2314 | if (!cwd) | ||
2315 | cwd = unknown; | ||
2310 | #ifdef BB_FEATURE_COMMAND_EDITING | 2316 | #ifdef BB_FEATURE_COMMAND_EDITING |
2311 | cmdedit_set_initial_prompt(); | 2317 | cmdedit_set_initial_prompt(); |
2312 | #else | 2318 | #else |
diff --git a/include/libbb.h b/include/libbb.h index 21af5688a..fde58b0a6 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -282,5 +282,6 @@ extern const char * const dash_dash_help; | |||
282 | extern const char * const write_error; | 282 | extern const char * const write_error; |
283 | extern const char * const too_few_args; | 283 | extern const char * const too_few_args; |
284 | extern const char * const name_longer_than_foo; | 284 | extern const char * const name_longer_than_foo; |
285 | extern const char * const unknown; | ||
285 | 286 | ||
286 | #endif /* __LIBBB_H__ */ | 287 | #endif /* __LIBBB_H__ */ |
@@ -297,7 +297,8 @@ static int builtin_cd(struct child_prog *child) | |||
297 | return EXIT_FAILURE; | 297 | return EXIT_FAILURE; |
298 | } | 298 | } |
299 | cwd = xgetcwd(cwd); | 299 | cwd = xgetcwd(cwd); |
300 | 300 | if (!cwd) | |
301 | cwd = unknown; | ||
301 | return EXIT_SUCCESS; | 302 | return EXIT_SUCCESS; |
302 | } | 303 | } |
303 | 304 | ||
@@ -412,6 +413,9 @@ static int builtin_jobs(struct child_prog *child) | |||
412 | /* built-in 'pwd' handler */ | 413 | /* built-in 'pwd' handler */ |
413 | static int builtin_pwd(struct child_prog *dummy) | 414 | static int builtin_pwd(struct child_prog *dummy) |
414 | { | 415 | { |
416 | cwd = xgetcwd(cwd); | ||
417 | if (!cwd) | ||
418 | cwd = unknown; | ||
415 | printf( "%s\n", cwd); | 419 | printf( "%s\n", cwd); |
416 | return EXIT_SUCCESS; | 420 | return EXIT_SUCCESS; |
417 | } | 421 | } |
@@ -1827,7 +1831,6 @@ void free_memory(void) | |||
1827 | { | 1831 | { |
1828 | if (cwd) { | 1832 | if (cwd) { |
1829 | free(cwd); | 1833 | free(cwd); |
1830 | cwd = NULL; | ||
1831 | } | 1834 | } |
1832 | if (local_pending_command) | 1835 | if (local_pending_command) |
1833 | free(local_pending_command); | 1836 | free(local_pending_command); |
@@ -1919,6 +1922,8 @@ int shell_main(int argc_l, char **argv_l) | |||
1919 | 1922 | ||
1920 | /* initialize the cwd -- this is never freed...*/ | 1923 | /* initialize the cwd -- this is never freed...*/ |
1921 | cwd = xgetcwd(0); | 1924 | cwd = xgetcwd(0); |
1925 | if (!cwd) | ||
1926 | cwd = unknown; | ||
1922 | 1927 | ||
1923 | #ifdef BB_FEATURE_CLEAN_UP | 1928 | #ifdef BB_FEATURE_CLEAN_UP |
1924 | atexit(free_memory); | 1929 | atexit(free_memory); |
diff --git a/libbb/libbb.h b/libbb/libbb.h index 21af5688a..fde58b0a6 100644 --- a/libbb/libbb.h +++ b/libbb/libbb.h | |||
@@ -282,5 +282,6 @@ extern const char * const dash_dash_help; | |||
282 | extern const char * const write_error; | 282 | extern const char * const write_error; |
283 | extern const char * const too_few_args; | 283 | extern const char * const too_few_args; |
284 | extern const char * const name_longer_than_foo; | 284 | extern const char * const name_longer_than_foo; |
285 | extern const char * const unknown; | ||
285 | 286 | ||
286 | #endif /* __LIBBB_H__ */ | 287 | #endif /* __LIBBB_H__ */ |
diff --git a/libbb/messages.c b/libbb/messages.c index 99c2bc9d5..910cb8fa2 100644 --- a/libbb/messages.c +++ b/libbb/messages.c | |||
@@ -58,4 +58,7 @@ | |||
58 | #ifdef L_name_longer_than_foo | 58 | #ifdef L_name_longer_than_foo |
59 | const char * const name_longer_than_foo = "Names longer than %d chars not supported."; | 59 | const char * const name_longer_than_foo = "Names longer than %d chars not supported."; |
60 | #endif | 60 | #endif |
61 | #ifdef L_unknown | ||
62 | const char * const unknown = "(unknown)"; | ||
63 | #endif | ||
61 | 64 | ||
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) | |||
355 | char c; | 355 | char c; |
356 | char *pbuf; | 356 | char *pbuf; |
357 | 357 | ||
358 | if (!pwd_buf) { | ||
359 | pwd_buf=unknown; | ||
360 | } | ||
361 | |||
358 | while (*prmt_ptr) { | 362 | while (*prmt_ptr) { |
359 | pbuf = buf; | 363 | pbuf = buf; |
360 | pbuf[1] = 0; | 364 | 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) | |||
429 | return EXIT_FAILURE; | 429 | return EXIT_FAILURE; |
430 | } | 430 | } |
431 | cwd = xgetcwd(cwd); | 431 | cwd = xgetcwd(cwd); |
432 | if (!cwd) | ||
433 | cwd = unknown; | ||
432 | return EXIT_SUCCESS; | 434 | return EXIT_SUCCESS; |
433 | } | 435 | } |
434 | 436 | ||
@@ -568,6 +570,8 @@ static int builtin_jobs(struct child_prog *child) | |||
568 | static int builtin_pwd(struct child_prog *dummy) | 570 | static int builtin_pwd(struct child_prog *dummy) |
569 | { | 571 | { |
570 | cwd = xgetcwd(cwd); | 572 | cwd = xgetcwd(cwd); |
573 | if (!cwd) | ||
574 | cwd = unknown; | ||
571 | puts(cwd); | 575 | puts(cwd); |
572 | return EXIT_SUCCESS; | 576 | return EXIT_SUCCESS; |
573 | } | 577 | } |
@@ -2307,6 +2311,8 @@ int shell_main(int argc, char **argv) | |||
2307 | 2311 | ||
2308 | /* initialize the cwd -- this is never freed...*/ | 2312 | /* initialize the cwd -- this is never freed...*/ |
2309 | cwd = xgetcwd(0); | 2313 | cwd = xgetcwd(0); |
2314 | if (!cwd) | ||
2315 | cwd = unknown; | ||
2310 | #ifdef BB_FEATURE_COMMAND_EDITING | 2316 | #ifdef BB_FEATURE_COMMAND_EDITING |
2311 | cmdedit_set_initial_prompt(); | 2317 | cmdedit_set_initial_prompt(); |
2312 | #else | 2318 | #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) | |||
297 | return EXIT_FAILURE; | 297 | return EXIT_FAILURE; |
298 | } | 298 | } |
299 | cwd = xgetcwd(cwd); | 299 | cwd = xgetcwd(cwd); |
300 | 300 | if (!cwd) | |
301 | cwd = unknown; | ||
301 | return EXIT_SUCCESS; | 302 | return EXIT_SUCCESS; |
302 | } | 303 | } |
303 | 304 | ||
@@ -412,6 +413,9 @@ static int builtin_jobs(struct child_prog *child) | |||
412 | /* built-in 'pwd' handler */ | 413 | /* built-in 'pwd' handler */ |
413 | static int builtin_pwd(struct child_prog *dummy) | 414 | static int builtin_pwd(struct child_prog *dummy) |
414 | { | 415 | { |
416 | cwd = xgetcwd(cwd); | ||
417 | if (!cwd) | ||
418 | cwd = unknown; | ||
415 | printf( "%s\n", cwd); | 419 | printf( "%s\n", cwd); |
416 | return EXIT_SUCCESS; | 420 | return EXIT_SUCCESS; |
417 | } | 421 | } |
@@ -1827,7 +1831,6 @@ void free_memory(void) | |||
1827 | { | 1831 | { |
1828 | if (cwd) { | 1832 | if (cwd) { |
1829 | free(cwd); | 1833 | free(cwd); |
1830 | cwd = NULL; | ||
1831 | } | 1834 | } |
1832 | if (local_pending_command) | 1835 | if (local_pending_command) |
1833 | free(local_pending_command); | 1836 | free(local_pending_command); |
@@ -1919,6 +1922,8 @@ int shell_main(int argc_l, char **argv_l) | |||
1919 | 1922 | ||
1920 | /* initialize the cwd -- this is never freed...*/ | 1923 | /* initialize the cwd -- this is never freed...*/ |
1921 | cwd = xgetcwd(0); | 1924 | cwd = xgetcwd(0); |
1925 | if (!cwd) | ||
1926 | cwd = unknown; | ||
1922 | 1927 | ||
1923 | #ifdef BB_FEATURE_CLEAN_UP | 1928 | #ifdef BB_FEATURE_CLEAN_UP |
1924 | atexit(free_memory); | 1929 | atexit(free_memory); |