diff options
| author | Ron Yorston <rmy@pobox.com> | 2018-02-13 09:44:44 +0000 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2018-02-13 09:44:44 +0000 |
| commit | dc19a361bd6c6df30338371532691bbc7f7126bb (patch) | |
| tree | 1fb2cd646d54b5f8e425c4f11f3e09fc21d1966b /debianutils | |
| parent | 096aee2bb468d1ab044de36e176ed1f6c7e3674d (diff) | |
| parent | 3459024bf404af814cacfe90a0deb719e282ae62 (diff) | |
| download | busybox-w32-dc19a361bd6c6df30338371532691bbc7f7126bb.tar.gz busybox-w32-dc19a361bd6c6df30338371532691bbc7f7126bb.tar.bz2 busybox-w32-dc19a361bd6c6df30338371532691bbc7f7126bb.zip | |
Merge branch 'busybox' into merge
Diffstat (limited to 'debianutils')
| -rw-r--r-- | debianutils/which.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/debianutils/which.c b/debianutils/which.c index fbfd19cdc..9613c6fc5 100644 --- a/debianutils/which.c +++ b/debianutils/which.c | |||
| @@ -30,12 +30,15 @@ | |||
| 30 | int which_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 30 | int which_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 31 | int which_main(int argc UNUSED_PARAM, char **argv) | 31 | int which_main(int argc UNUSED_PARAM, char **argv) |
| 32 | { | 32 | { |
| 33 | const char *env_path; | 33 | char *env_path; |
| 34 | int status = 0; | 34 | int status = 0; |
| 35 | /* This sizeof(): bb_default_root_path is shorter than BB_PATH_ROOT_PATH */ | ||
| 36 | char buf[sizeof(BB_PATH_ROOT_PATH)]; | ||
| 35 | 37 | ||
| 36 | env_path = getenv("PATH"); | 38 | env_path = getenv("PATH"); |
| 37 | if (!env_path) | 39 | if (!env_path) |
| 38 | env_path = bb_default_root_path; | 40 | /* env_path must be writable, and must not alloc, so... */ |
| 41 | env_path = strcpy(buf, bb_default_root_path); | ||
| 39 | 42 | ||
| 40 | getopt32(argv, "^" "a" "\0" "-1"/*at least one arg*/); | 43 | getopt32(argv, "^" "a" "\0" "-1"/*at least one arg*/); |
| 41 | argv += optind; | 44 | argv += optind; |
| @@ -69,19 +72,16 @@ int which_main(int argc UNUSED_PARAM, char **argv) | |||
| 69 | #endif | 72 | #endif |
| 70 | } else { | 73 | } else { |
| 71 | char *path; | 74 | char *path; |
| 72 | char *tmp; | ||
| 73 | 75 | ||
| 74 | path = tmp = xstrdup(env_path); | 76 | path = env_path; |
| 75 | //NOFORK FIXME: nested xmallocs (one is inside find_executable()) | 77 | /* NOFORK NB: xmalloc inside find_executable(), must have no allocs above! */ |
| 76 | //can leak memory on failure | 78 | while ((p = find_executable(*argv, &path)) != NULL) { |
| 77 | while ((p = find_executable(*argv, &tmp)) != NULL) { | ||
| 78 | missing = 0; | 79 | missing = 0; |
| 79 | puts(p); | 80 | puts(p); |
| 80 | free(p); | 81 | free(p); |
| 81 | if (!option_mask32) /* -a not set */ | 82 | if (!option_mask32) /* -a not set */ |
| 82 | break; | 83 | break; |
| 83 | } | 84 | } |
| 84 | free(path); | ||
| 85 | } | 85 | } |
| 86 | status |= missing; | 86 | status |= missing; |
| 87 | } while (*++argv); | 87 | } while (*++argv); |
