diff options
author | Ron Yorston <rmy@pobox.com> | 2020-06-01 08:42:56 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2020-06-01 08:42:56 +0100 |
commit | f81fcc84134ab2f29816dbfaf2e5af9ee62d2691 (patch) | |
tree | 56d6f964a438329652d9c0c8149f95174019ae27 | |
parent | 5dad29558e403acabe26711c0d2324d9f0333be5 (diff) | |
download | busybox-w32-f81fcc84134ab2f29816dbfaf2e5af9ee62d2691.tar.gz busybox-w32-f81fcc84134ab2f29816dbfaf2e5af9ee62d2691.tar.bz2 busybox-w32-f81fcc84134ab2f29816dbfaf2e5af9ee62d2691.zip |
ash: minor changes to forkshell error handling
forkshell_prepare() now returns NULL if it fails to map its view of
the data block. Detect and report this error in spawn_forkshell().
If forkshell_init() fails it now returns to ash_main() where a generic
error is reported.
-rw-r--r-- | shell/ash.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/shell/ash.c b/shell/ash.c index 241846380..951e241ad 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -15314,7 +15314,7 @@ int ash_main(int argc UNUSED_PARAM, char **argv) | |||
15314 | if (argc == 3 && !strcmp(argv[1], "--fs")) { | 15314 | if (argc == 3 && !strcmp(argv[1], "--fs")) { |
15315 | forkshell_init(argv[2]); | 15315 | forkshell_init(argv[2]); |
15316 | 15316 | ||
15317 | /* NOTREACHED */ | 15317 | /* only reached in case of error */ |
15318 | bb_error_msg_and_die("forkshell failed"); | 15318 | bb_error_msg_and_die("forkshell failed"); |
15319 | } | 15319 | } |
15320 | #endif | 15320 | #endif |
@@ -15620,6 +15620,9 @@ spawn_forkshell(struct forkshell *fs, struct job *jp, union node *n, int mode) | |||
15620 | intptr_t ret; | 15620 | intptr_t ret; |
15621 | 15621 | ||
15622 | new = forkshell_prepare(fs); | 15622 | new = forkshell_prepare(fs); |
15623 | if (new == NULL) | ||
15624 | goto fail; | ||
15625 | |||
15623 | new->mode = mode; | 15626 | new->mode = mode; |
15624 | new->nprocs = jp == NULL ? 0 : jp->nprocs; | 15627 | new->nprocs = jp == NULL ? 0 : jp->nprocs; |
15625 | sprintf(buf, "%p", new->hMapFile); | 15628 | sprintf(buf, "%p", new->hMapFile); |
@@ -15628,6 +15631,7 @@ spawn_forkshell(struct forkshell *fs, struct job *jp, union node *n, int mode) | |||
15628 | CloseHandle(new->hMapFile); | 15631 | CloseHandle(new->hMapFile); |
15629 | UnmapViewOfFile(new); | 15632 | UnmapViewOfFile(new); |
15630 | if (ret == -1) { | 15633 | if (ret == -1) { |
15634 | fail: | ||
15631 | if (jp) | 15635 | if (jp) |
15632 | freejob(jp); | 15636 | freejob(jp); |
15633 | ash_msg_and_raise_error("unable to spawn shell"); | 15637 | ash_msg_and_raise_error("unable to spawn shell"); |
@@ -16233,6 +16237,8 @@ forkshell_prepare(struct forkshell *fs) | |||
16233 | 16237 | ||
16234 | /* Initialise pointers */ | 16238 | /* Initialise pointers */ |
16235 | new = (struct forkshell *)MapViewOfFile(h, FILE_MAP_WRITE, 0,0, 0); | 16239 | new = (struct forkshell *)MapViewOfFile(h, FILE_MAP_WRITE, 0,0, 0); |
16240 | if (new == NULL) | ||
16241 | return NULL; | ||
16236 | fs_size = size; | 16242 | fs_size = size; |
16237 | funcblock = (char *)(new + 1); | 16243 | funcblock = (char *)(new + 1); |
16238 | funcstring_end = (char *)new + size; | 16244 | funcstring_end = (char *)new + size; |
@@ -16305,12 +16311,12 @@ forkshell_init(const char *idstr) | |||
16305 | char *lrelocate; | 16311 | char *lrelocate; |
16306 | 16312 | ||
16307 | if (sscanf(idstr, "%p", &map_handle) != 1) | 16313 | if (sscanf(idstr, "%p", &map_handle) != 1) |
16308 | bb_error_msg_and_die("invalid forkshell ID"); | 16314 | return; |
16309 | 16315 | ||
16310 | h = (HANDLE)map_handle; | 16316 | h = (HANDLE)map_handle; |
16311 | fs = (struct forkshell *)MapViewOfFile(h, FILE_MAP_WRITE, 0,0, 0); | 16317 | fs = (struct forkshell *)MapViewOfFile(h, FILE_MAP_WRITE, 0,0, 0); |
16312 | if (!fs) | 16318 | if (!fs) |
16313 | bb_error_msg_and_die("Invalid forkshell memory"); | 16319 | return; |
16314 | 16320 | ||
16315 | /* this memory can't be freed */ | 16321 | /* this memory can't be freed */ |
16316 | sticky_mem_start = fs; | 16322 | sticky_mem_start = fs; |