diff options
author | Ron Yorston <rmy@pobox.com> | 2018-04-09 08:50:34 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2018-04-09 08:50:34 +0100 |
commit | 921c1ab66bad54d4ad8591bb74e41ac985248496 (patch) | |
tree | 552a04c691e78e78570e4ec2c83fbc0e59953924 /libbb | |
parent | 5b6f06f5eb8628955262508d153627fe6f2d1c8b (diff) | |
parent | a1870f4807a75663a085c9f5e92870fa7554f0ad (diff) | |
download | busybox-w32-921c1ab66bad54d4ad8591bb74e41ac985248496.tar.gz busybox-w32-921c1ab66bad54d4ad8591bb74e41ac985248496.tar.bz2 busybox-w32-921c1ab66bad54d4ad8591bb74e41ac985248496.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/appletlib.c | 17 | ||||
-rw-r--r-- | libbb/ask_confirmation.c | 14 | ||||
-rw-r--r-- | libbb/bb_askpass.c | 55 | ||||
-rw-r--r-- | libbb/copy_file.c | 2 | ||||
-rw-r--r-- | libbb/correct_password.c | 2 | ||||
-rw-r--r-- | libbb/dump.c | 6 | ||||
-rw-r--r-- | libbb/lineedit.c | 3 | ||||
-rw-r--r-- | libbb/remove_file.c | 13 |
8 files changed, 67 insertions, 45 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 8fae11998..6a189a8c9 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
@@ -110,14 +110,21 @@ static const char *unpack_usage_messages(void) | |||
110 | char *outbuf = NULL; | 110 | char *outbuf = NULL; |
111 | bunzip_data *bd; | 111 | bunzip_data *bd; |
112 | int i; | 112 | int i; |
113 | jmp_buf jmpbuf; | ||
113 | 114 | ||
114 | i = start_bunzip(&bd, | 115 | /* Setup for I/O error handling via longjmp */ |
116 | i = setjmp(jmpbuf); | ||
117 | if (i == 0) { | ||
118 | i = start_bunzip(&jmpbuf, | ||
119 | &bd, | ||
115 | /* src_fd: */ -1, | 120 | /* src_fd: */ -1, |
116 | /* inbuf: */ packed_usage, | 121 | /* inbuf: */ packed_usage, |
117 | /* len: */ sizeof(packed_usage)); | 122 | /* len: */ sizeof(packed_usage) |
118 | /* read_bunzip can longjmp to start_bunzip, and ultimately | 123 | ); |
119 | * end up here with i != 0 on read data errors! Not trivial */ | 124 | } |
120 | if (!i) { | 125 | /* read_bunzip can longjmp and end up here with i != 0 |
126 | * on read data errors! Not trivial */ | ||
127 | if (i == 0) { | ||
121 | /* Cannot use xmalloc: will leak bd in NOFORK case! */ | 128 | /* Cannot use xmalloc: will leak bd in NOFORK case! */ |
122 | outbuf = malloc_or_warn(sizeof(UNPACKED_USAGE)); | 129 | outbuf = malloc_or_warn(sizeof(UNPACKED_USAGE)); |
123 | if (outbuf) | 130 | if (outbuf) |
diff --git a/libbb/ask_confirmation.c b/libbb/ask_confirmation.c index 6fbed89f4..e4814e215 100644 --- a/libbb/ask_confirmation.c +++ b/libbb/ask_confirmation.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | 2 | /* |
3 | * bb_ask_confirmation implementation for busybox | 3 | * bb_ask_y_confirmation implementation for busybox |
4 | * | 4 | * |
5 | * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org> | 5 | * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org> |
6 | * | 6 | * |
@@ -8,15 +8,16 @@ | |||
8 | */ | 8 | */ |
9 | #include "libbb.h" | 9 | #include "libbb.h" |
10 | 10 | ||
11 | /* Read a line from stdin. If the first non-whitespace char is 'y' or 'Y', | 11 | /* Read a line from fp. If the first non-whitespace char is 'y' or 'Y', |
12 | * return 1. Otherwise return 0. | 12 | * return 1. Otherwise return 0. |
13 | */ | 13 | */ |
14 | int FAST_FUNC bb_ask_confirmation(void) | 14 | int FAST_FUNC bb_ask_y_confirmation_FILE(FILE *fp) |
15 | { | 15 | { |
16 | char first = 0; | 16 | char first = 0; |
17 | int c; | 17 | int c; |
18 | 18 | ||
19 | while (((c = getchar()) != EOF) && (c != '\n')) { | 19 | fflush_all(); |
20 | while (((c = fgetc(fp)) != EOF) && (c != '\n')) { | ||
20 | if (first == 0 && !isblank(c)) { | 21 | if (first == 0 && !isblank(c)) { |
21 | first = c|0x20; | 22 | first = c|0x20; |
22 | } | 23 | } |
@@ -24,3 +25,8 @@ int FAST_FUNC bb_ask_confirmation(void) | |||
24 | 25 | ||
25 | return first == 'y'; | 26 | return first == 'y'; |
26 | } | 27 | } |
28 | |||
29 | int FAST_FUNC bb_ask_y_confirmation(void) | ||
30 | { | ||
31 | return bb_ask_y_confirmation_FILE(stdin); | ||
32 | } | ||
diff --git a/libbb/bb_askpass.c b/libbb/bb_askpass.c index aae35ec41..2dcead35a 100644 --- a/libbb/bb_askpass.c +++ b/libbb/bb_askpass.c | |||
@@ -13,16 +13,9 @@ static void askpass_timeout(int UNUSED_PARAM ignore) | |||
13 | { | 13 | { |
14 | } | 14 | } |
15 | 15 | ||
16 | char* FAST_FUNC bb_ask_stdin(const char *prompt) | 16 | char* FAST_FUNC bb_ask_noecho(int fd, int timeout, const char *prompt) |
17 | { | 17 | { |
18 | return bb_ask(STDIN_FILENO, 0, prompt); | 18 | #define MAX_LINE 0xfff |
19 | } | ||
20 | char* FAST_FUNC bb_ask(const int fd, int timeout, const char *prompt) | ||
21 | { | ||
22 | /* Was static char[BIGNUM] */ | ||
23 | enum { sizeof_passwd = 128 }; | ||
24 | |||
25 | char *passwd; | ||
26 | char *ret; | 19 | char *ret; |
27 | int i; | 20 | int i; |
28 | struct sigaction sa, oldsa; | 21 | struct sigaction sa, oldsa; |
@@ -37,16 +30,17 @@ char* FAST_FUNC bb_ask(const int fd, int timeout, const char *prompt) | |||
37 | 30 | ||
38 | tcgetattr(fd, &oldtio); | 31 | tcgetattr(fd, &oldtio); |
39 | tio = oldtio; | 32 | tio = oldtio; |
40 | #if 0 | 33 | /* Switch off echo. ECHOxyz meaning: |
41 | /* Switch off UPPERCASE->lowercase conversion (never used since 198x) | 34 | * ECHO echo input chars |
42 | * and XON/XOFF (why we want to mess with this??) | 35 | * ECHOE echo BS-SP-BS on erase character |
36 | * ECHOK echo kill char specially, not as ^c (ECHOKE controls how exactly) | ||
37 | * ECHOKE erase all input via BS-SP-BS on kill char (else go to next line) | ||
38 | * ECHOCTL Echo ctrl chars as ^c (else echo verbatim: | ||
39 | * e.g. up arrow emits "ESC-something" and thus moves cursor up!) | ||
40 | * ECHONL Echo NL even if ECHO is not set | ||
41 | * ECHOPRT On erase, echo erased chars | ||
42 | * [qwe<BS><BS><BS> input looks like "qwe\ewq/" on screen] | ||
43 | */ | 43 | */ |
44 | # ifndef IUCLC | ||
45 | # define IUCLC 0 | ||
46 | # endif | ||
47 | tio.c_iflag &= ~(IUCLC|IXON|IXOFF|IXANY); | ||
48 | #endif | ||
49 | /* Switch off echo */ | ||
50 | tio.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL); | 44 | tio.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL); |
51 | tcsetattr(fd, TCSANOW, &tio); | 45 | tcsetattr(fd, TCSANOW, &tio); |
52 | 46 | ||
@@ -60,21 +54,30 @@ char* FAST_FUNC bb_ask(const int fd, int timeout, const char *prompt) | |||
60 | alarm(timeout); | 54 | alarm(timeout); |
61 | } | 55 | } |
62 | 56 | ||
63 | passwd = auto_string(xmalloc(sizeof_passwd)); | 57 | ret = NULL; |
64 | ret = passwd; | ||
65 | i = 0; | 58 | i = 0; |
66 | while (1) { | 59 | while (1) { |
67 | int r = read(fd, &ret[i], 1); | 60 | int r; |
61 | |||
62 | /* User input is uber-slow, no need to optimize reallocs. | ||
63 | * Grow it on every char. | ||
64 | */ | ||
65 | ret = xrealloc(ret, i + 2); | ||
66 | r = read(fd, &ret[i], 1); | ||
67 | |||
68 | if ((i == 0 && r == 0) /* EOF (^D) with no password */ | 68 | if ((i == 0 && r == 0) /* EOF (^D) with no password */ |
69 | || r < 0 | 69 | || r < 0 /* read is interrupted by timeout or ^C */ |
70 | ) { | 70 | ) { |
71 | /* read is interrupted by timeout or ^C */ | 71 | ret[i] = '\0'; /* paranoia */ |
72 | nuke_str(ret); /* paranoia */ | ||
73 | free(ret); | ||
72 | ret = NULL; | 74 | ret = NULL; |
73 | break; | 75 | break; |
74 | } | 76 | } |
77 | |||
75 | if (r == 0 /* EOF */ | 78 | if (r == 0 /* EOF */ |
76 | || ret[i] == '\r' || ret[i] == '\n' /* EOL */ | 79 | || ret[i] == '\r' || ret[i] == '\n' /* EOL */ |
77 | || ++i == sizeof_passwd-1 /* line limit */ | 80 | || ++i == MAX_LINE /* line limit */ |
78 | ) { | 81 | ) { |
79 | ret[i] = '\0'; | 82 | ret[i] = '\0'; |
80 | break; | 83 | break; |
@@ -90,3 +93,7 @@ char* FAST_FUNC bb_ask(const int fd, int timeout, const char *prompt) | |||
90 | fflush_all(); | 93 | fflush_all(); |
91 | return ret; | 94 | return ret; |
92 | } | 95 | } |
96 | char* FAST_FUNC bb_ask_noecho_stdin(const char *prompt) | ||
97 | { | ||
98 | return bb_ask_noecho(STDIN_FILENO, 0, prompt); | ||
99 | } | ||
diff --git a/libbb/copy_file.c b/libbb/copy_file.c index 5372d8680..c60765d95 100644 --- a/libbb/copy_file.c +++ b/libbb/copy_file.c | |||
@@ -48,7 +48,7 @@ static int ask_and_unlink(const char *dest, int flags) | |||
48 | // (No "opening without O_EXCL", no "unlink only if -f") | 48 | // (No "opening without O_EXCL", no "unlink only if -f") |
49 | // Or else we will end up having 3 open()s! | 49 | // Or else we will end up having 3 open()s! |
50 | fprintf(stderr, "%s: overwrite '%s'? ", applet_name, dest); | 50 | fprintf(stderr, "%s: overwrite '%s'? ", applet_name, dest); |
51 | if (!bb_ask_confirmation()) | 51 | if (!bb_ask_y_confirmation()) |
52 | return 0; /* not allowed to overwrite */ | 52 | return 0; /* not allowed to overwrite */ |
53 | } | 53 | } |
54 | if (unlink(dest) < 0) { | 54 | if (unlink(dest) < 0) { |
diff --git a/libbb/correct_password.c b/libbb/correct_password.c index a6f7d9b3d..cbe6cb387 100644 --- a/libbb/correct_password.c +++ b/libbb/correct_password.c | |||
@@ -106,7 +106,7 @@ int FAST_FUNC ask_and_check_password_extended(const struct passwd *pw, | |||
106 | if (!pw_pass[0]) /* empty password field? */ | 106 | if (!pw_pass[0]) /* empty password field? */ |
107 | return CHECKPASS_PW_HAS_EMPTY_PASSWORD; | 107 | return CHECKPASS_PW_HAS_EMPTY_PASSWORD; |
108 | 108 | ||
109 | plaintext = bb_ask(STDIN_FILENO, timeout, prompt); | 109 | plaintext = bb_ask_noecho(STDIN_FILENO, timeout, prompt); |
110 | if (!plaintext) { | 110 | if (!plaintext) { |
111 | /* EOF (such as ^D) or error (such as ^C) or timeout */ | 111 | /* EOF (such as ^D) or error (such as ^C) or timeout */ |
112 | return -1; | 112 | return -1; |
diff --git a/libbb/dump.c b/libbb/dump.c index db91fcfe7..5941ef902 100644 --- a/libbb/dump.c +++ b/libbb/dump.c | |||
@@ -464,11 +464,9 @@ static const char conv_str[] ALIGN1 = | |||
464 | "\v" "\\""v""\0" | 464 | "\v" "\\""v""\0" |
465 | ; | 465 | ; |
466 | 466 | ||
467 | |||
468 | static void conv_c(PR *pr, unsigned char *p) | 467 | static void conv_c(PR *pr, unsigned char *p) |
469 | { | 468 | { |
470 | const char *str = conv_str; | 469 | const char *str = conv_str; |
471 | char buf[10]; | ||
472 | 470 | ||
473 | do { | 471 | do { |
474 | if (*p == *str) { | 472 | if (*p == *str) { |
@@ -482,7 +480,9 @@ static void conv_c(PR *pr, unsigned char *p) | |||
482 | *pr->cchar = 'c'; | 480 | *pr->cchar = 'c'; |
483 | printf(pr->fmt, *p); | 481 | printf(pr->fmt, *p); |
484 | } else { | 482 | } else { |
485 | sprintf(buf, "%03o", (int) *p); | 483 | char buf[4]; |
484 | /* gcc-8.0.1 needs lots of casts to shut up */ | ||
485 | sprintf(buf, "%03o", (unsigned)(uint8_t)*p); | ||
486 | str = buf; | 486 | str = buf; |
487 | strpr: | 487 | strpr: |
488 | *pr->cchar = 's'; | 488 | *pr->cchar = 's'; |
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 36b6abe2b..431f1c048 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -466,7 +466,8 @@ static void put_till_end_and_adv_cursor(void) | |||
466 | static void goto_new_line(void) | 466 | static void goto_new_line(void) |
467 | { | 467 | { |
468 | put_till_end_and_adv_cursor(); | 468 | put_till_end_and_adv_cursor(); |
469 | if (cmdedit_x != 0) | 469 | /* "cursor == 0" is only if prompt is "" and user input is empty */ |
470 | if (cursor == 0 || cmdedit_x != 0) | ||
470 | bb_putchar('\n'); | 471 | bb_putchar('\n'); |
471 | } | 472 | } |
472 | 473 | ||
diff --git a/libbb/remove_file.c b/libbb/remove_file.c index 8a1324393..86c9a5c56 100644 --- a/libbb/remove_file.c +++ b/libbb/remove_file.c | |||
@@ -39,9 +39,9 @@ int FAST_FUNC remove_file(const char *path, int flags) | |||
39 | if ((!(flags & FILEUTILS_FORCE) && access(path, W_OK) < 0 && isatty(0)) | 39 | if ((!(flags & FILEUTILS_FORCE) && access(path, W_OK) < 0 && isatty(0)) |
40 | || (flags & FILEUTILS_INTERACTIVE) | 40 | || (flags & FILEUTILS_INTERACTIVE) |
41 | ) { | 41 | ) { |
42 | fprintf(stderr, "%s: descend into directory '%s'? ", applet_name, | 42 | fprintf(stderr, "%s: descend into directory '%s'? ", |
43 | path); | 43 | applet_name, path); |
44 | if (!bb_ask_confirmation()) | 44 | if (!bb_ask_y_confirmation()) |
45 | return 0; | 45 | return 0; |
46 | } | 46 | } |
47 | 47 | ||
@@ -67,8 +67,9 @@ int FAST_FUNC remove_file(const char *path, int flags) | |||
67 | } | 67 | } |
68 | 68 | ||
69 | if (flags & FILEUTILS_INTERACTIVE) { | 69 | if (flags & FILEUTILS_INTERACTIVE) { |
70 | fprintf(stderr, "%s: remove directory '%s'? ", applet_name, path); | 70 | fprintf(stderr, "%s: remove directory '%s'? ", |
71 | if (!bb_ask_confirmation()) | 71 | applet_name, path); |
72 | if (!bb_ask_y_confirmation()) | ||
72 | return status; | 73 | return status; |
73 | } | 74 | } |
74 | 75 | ||
@@ -92,7 +93,7 @@ int FAST_FUNC remove_file(const char *path, int flags) | |||
92 | || (flags & FILEUTILS_INTERACTIVE) | 93 | || (flags & FILEUTILS_INTERACTIVE) |
93 | ) { | 94 | ) { |
94 | fprintf(stderr, "%s: remove '%s'? ", applet_name, path); | 95 | fprintf(stderr, "%s: remove '%s'? ", applet_name, path); |
95 | if (!bb_ask_confirmation()) | 96 | if (!bb_ask_y_confirmation()) |
96 | return 0; | 97 | return 0; |
97 | } | 98 | } |
98 | 99 | ||