diff options
author | Ron Yorston <rmy@pobox.com> | 2021-02-05 11:24:06 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2021-02-05 11:24:06 +0000 |
commit | 32e19e7ae8b0d76d69871ba234e8f0af31baff4e (patch) | |
tree | 6fdc833a444e0dd6fd359b21a8d463856917a387 /libbb | |
parent | 4fb71406b884c6ac0a9a4d2acf7a32b544611f70 (diff) | |
parent | cad3fc743aa7c7744e4fcf044371f0fda50fa51f (diff) | |
download | busybox-w32-32e19e7ae8b0d76d69871ba234e8f0af31baff4e.tar.gz busybox-w32-32e19e7ae8b0d76d69871ba234e8f0af31baff4e.tar.bz2 busybox-w32-32e19e7ae8b0d76d69871ba234e8f0af31baff4e.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/appletlib.c | 96 | ||||
-rw-r--r-- | libbb/bb_askpass.c | 2 | ||||
-rw-r--r-- | libbb/compare_string_array.c | 14 | ||||
-rw-r--r-- | libbb/dump.c | 2 | ||||
-rw-r--r-- | libbb/fgets_str.c | 17 | ||||
-rw-r--r-- | libbb/lineedit.c | 8 | ||||
-rw-r--r-- | libbb/login.c | 6 | ||||
-rw-r--r-- | libbb/print_numbered_lines.c | 5 | ||||
-rw-r--r-- | libbb/update_passwd.c | 2 | ||||
-rw-r--r-- | libbb/xfuncs_printf.c | 5 |
10 files changed, 50 insertions, 107 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index ecee45ae2..320cb5b13 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
@@ -191,7 +191,7 @@ void FAST_FUNC bb_show_usage(void) | |||
191 | 191 | ||
192 | int FAST_FUNC find_applet_by_name(const char *name) | 192 | int FAST_FUNC find_applet_by_name(const char *name) |
193 | { | 193 | { |
194 | unsigned i, max; | 194 | unsigned i; |
195 | int j; | 195 | int j; |
196 | const char *p; | 196 | const char *p; |
197 | 197 | ||
@@ -215,105 +215,43 @@ int FAST_FUNC find_applet_by_name(const char *name) | |||
215 | #endif | 215 | #endif |
216 | 216 | ||
217 | p = applet_names; | 217 | p = applet_names; |
218 | i = 0; | ||
219 | #if KNOWN_APPNAME_OFFSETS <= 0 | 218 | #if KNOWN_APPNAME_OFFSETS <= 0 |
220 | max = NUM_APPLETS; | 219 | i = 0; |
221 | #else | 220 | #else |
222 | max = NUM_APPLETS * KNOWN_APPNAME_OFFSETS; | 221 | i = NUM_APPLETS * (KNOWN_APPNAME_OFFSETS - 1); |
223 | for (j = ARRAY_SIZE(applet_nameofs)-1; j >= 0; j--) { | 222 | for (j = ARRAY_SIZE(applet_nameofs)-1; j >= 0; j--) { |
224 | const char *pp = applet_names + applet_nameofs[j]; | 223 | const char *pp = applet_names + applet_nameofs[j]; |
225 | if (strcmp(name, pp) >= 0) { | 224 | if (strcmp(name, pp) >= 0) { |
226 | //bb_error_msg("name:'%s' >= pp:'%s'", name, pp); | 225 | //bb_error_msg("name:'%s' >= pp:'%s'", name, pp); |
227 | p = pp; | 226 | p = pp; |
228 | i = max - NUM_APPLETS; | ||
229 | break; | 227 | break; |
230 | } | 228 | } |
231 | max -= NUM_APPLETS; | 229 | i -= NUM_APPLETS; |
232 | } | 230 | } |
233 | max /= (unsigned)KNOWN_APPNAME_OFFSETS; | ||
234 | i /= (unsigned)KNOWN_APPNAME_OFFSETS; | 231 | i /= (unsigned)KNOWN_APPNAME_OFFSETS; |
235 | //bb_error_msg("name:'%s' starting from:'%s' i:%u max:%u", name, p, i, max); | 232 | //bb_error_msg("name:'%s' starting from:'%s' i:%u", name, p, i); |
236 | #endif | 233 | #endif |
237 | 234 | ||
238 | /* Open-coded linear search without strcmp/strlen calls for speed */ | 235 | /* Open-coded linear search without strcmp/strlen calls for speed */ |
239 | 236 | while (*p) { | |
240 | #if 0 /*BB_UNALIGNED_MEMACCESS_OK && BB_LITTLE_ENDIAN*/ | 237 | /* Do we see "name\0" at current position in applet_names? */ |
241 | /* skip "[\0" name, it's surely not it */ | 238 | for (j = 0; *p == name[j]; ++j) { |
242 | if (ENABLE_TEST && LONE_CHAR(p, '[')) | 239 | if (*p++ == '\0') { |
243 | i++, p += 2; | ||
244 | /* All remaining applet names in p[] are at least 2 chars long */ | ||
245 | /* name[] is also at least 2 chars long */ | ||
246 | |||
247 | n32 = (name[0] << 0) | (name[1] << 8) | (name[2] << 16); | ||
248 | while (i < max) { | ||
249 | uint32_t p32; | ||
250 | char ch; | ||
251 | |||
252 | /* Quickly check match of the first 3 bytes */ | ||
253 | move_from_unaligned32(p32, p); | ||
254 | p += 3; | ||
255 | if ((p32 & 0x00ffffff) != n32) { | ||
256 | /* Most likely case: 3 first bytes do not match */ | ||
257 | i++; | ||
258 | if ((p32 & 0x00ff0000) == '\0') | ||
259 | continue; // p[2] was NUL | ||
260 | p++; | ||
261 | if ((p32 & 0xff000000) == '\0') | ||
262 | continue; // p[3] was NUL | ||
263 | /* p[0..3] aren't matching and none is NUL, check the rest */ | ||
264 | while (*p++ != '\0') | ||
265 | continue; | ||
266 | continue; | ||
267 | } | ||
268 | |||
269 | /* Unlikely branch: first 3 bytes ([0..2]) match */ | ||
270 | if ((p32 & 0x00ff0000) == '\0') { | ||
271 | /* name is 2-byte long, it is full match */ | ||
272 | //bb_error_msg("found:'%s' i:%u", name, i); | ||
273 | return i; | ||
274 | } | ||
275 | /* Check remaining bytes [3..NUL] */ | ||
276 | ch = (p32 >> 24); | ||
277 | j = 3; | ||
278 | while (ch == name[j]) { | ||
279 | if (ch == '\0') { | ||
280 | //bb_error_msg("found:'%s' i:%u", name, i); | ||
281 | return i; | ||
282 | } | ||
283 | ch = *++p; | ||
284 | j++; | ||
285 | } | ||
286 | /* Not a match. Skip it, including NUL */ | ||
287 | while (ch != '\0') | ||
288 | ch = *++p; | ||
289 | p++; | ||
290 | i++; | ||
291 | } | ||
292 | return -1; | ||
293 | #else | ||
294 | while (i < max) { | ||
295 | char ch; | ||
296 | j = 0; | ||
297 | /* Do we see "name\0" in applet_names[p] position? */ | ||
298 | while ((ch = *p) == name[j]) { | ||
299 | if (ch == '\0') { | ||
300 | //bb_error_msg("found:'%s' i:%u", name, i); | 240 | //bb_error_msg("found:'%s' i:%u", name, i); |
301 | return i; /* yes */ | 241 | return i; /* yes */ |
302 | } | 242 | } |
303 | p++; | ||
304 | j++; | ||
305 | } | 243 | } |
306 | /* No. | 244 | /* No. Have we gone too far, alphabetically? */ |
307 | * p => 1st non-matching char in applet_names[], | 245 | if (*p > name[j]) { |
308 | * skip to and including NUL. | 246 | //bb_error_msg("break:'%s' i:%u", name, i); |
309 | */ | 247 | break; |
310 | while (ch != '\0') | 248 | } |
311 | ch = *++p; | 249 | /* No. Move to the start of the next applet name. */ |
312 | p++; | 250 | while (*p++ != '\0') |
251 | continue; | ||
313 | i++; | 252 | i++; |
314 | } | 253 | } |
315 | return -1; | 254 | return -1; |
316 | #endif | ||
317 | } | 255 | } |
318 | 256 | ||
319 | 257 | ||
diff --git a/libbb/bb_askpass.c b/libbb/bb_askpass.c index 2dcead35a..66d6a479e 100644 --- a/libbb/bb_askpass.c +++ b/libbb/bb_askpass.c | |||
@@ -25,7 +25,7 @@ char* FAST_FUNC bb_ask_noecho(int fd, int timeout, const char *prompt) | |||
25 | /* Was buggy: was printing prompt *before* flushing input, | 25 | /* Was buggy: was printing prompt *before* flushing input, |
26 | * which was upsetting "expect" based scripts of some users. | 26 | * which was upsetting "expect" based scripts of some users. |
27 | */ | 27 | */ |
28 | fputs(prompt, stdout); | 28 | fputs_stdout(prompt); |
29 | fflush_all(); | 29 | fflush_all(); |
30 | 30 | ||
31 | tcgetattr(fd, &oldtio); | 31 | tcgetattr(fd, &oldtio); |
diff --git a/libbb/compare_string_array.c b/libbb/compare_string_array.c index ede5a97e3..70a4c29cf 100644 --- a/libbb/compare_string_array.c +++ b/libbb/compare_string_array.c | |||
@@ -104,13 +104,19 @@ int FAST_FUNC index_in_str_array(const char *const string_array[], const char *k | |||
104 | 104 | ||
105 | int FAST_FUNC index_in_strings(const char *strings, const char *key) | 105 | int FAST_FUNC index_in_strings(const char *strings, const char *key) |
106 | { | 106 | { |
107 | int idx = 0; | 107 | int j, idx = 0; |
108 | 108 | ||
109 | while (*strings) { | 109 | while (*strings) { |
110 | if (strcmp(strings, key) == 0) { | 110 | /* Do we see "key\0" at current position in strings? */ |
111 | return idx; | 111 | for (j = 0; *strings == key[j]; ++j) { |
112 | if (*strings++ == '\0') { | ||
113 | //bb_error_msg("found:'%s' i:%u", key, idx); | ||
114 | return idx; /* yes */ | ||
115 | } | ||
112 | } | 116 | } |
113 | strings += strlen(strings) + 1; /* skip NUL */ | 117 | /* No. Move to the start of the next string. */ |
118 | while (*strings++ != '\0') | ||
119 | continue; | ||
114 | idx++; | 120 | idx++; |
115 | } | 121 | } |
116 | return -1; | 122 | return -1; |
diff --git a/libbb/dump.c b/libbb/dump.c index 1ba1132b3..fb7849e7d 100644 --- a/libbb/dump.c +++ b/libbb/dump.c | |||
@@ -560,7 +560,7 @@ static void display(priv_dumper_t* dumper) | |||
560 | ) { | 560 | ) { |
561 | if (dumper->pub.eofstring) { | 561 | if (dumper->pub.eofstring) { |
562 | /* xxd support: requested to not pad incomplete blocks */ | 562 | /* xxd support: requested to not pad incomplete blocks */ |
563 | fputs(dumper->pub.eofstring, stdout); | 563 | fputs_stdout(dumper->pub.eofstring); |
564 | return; | 564 | return; |
565 | } | 565 | } |
566 | if (!(pr->flags & (F_TEXT | F_BPAD))) | 566 | if (!(pr->flags & (F_TEXT | F_BPAD))) |
diff --git a/libbb/fgets_str.c b/libbb/fgets_str.c index 1a7f2e9e0..c884ef8af 100644 --- a/libbb/fgets_str.c +++ b/libbb/fgets_str.c | |||
@@ -17,7 +17,7 @@ static char *xmalloc_fgets_internal(FILE *file, const char *terminating_string, | |||
17 | int linebufsz = 0; | 17 | int linebufsz = 0; |
18 | int idx = 0; | 18 | int idx = 0; |
19 | int ch; | 19 | int ch; |
20 | size_t maxsz = *maxsz_p; | 20 | size_t maxsz = maxsz_p ? *maxsz_p : INT_MAX - 4095; |
21 | 21 | ||
22 | while (1) { | 22 | while (1) { |
23 | ch = fgetc(file); | 23 | ch = fgetc(file); |
@@ -53,7 +53,8 @@ static char *xmalloc_fgets_internal(FILE *file, const char *terminating_string, | |||
53 | /* Grow/shrink *first*, then store NUL */ | 53 | /* Grow/shrink *first*, then store NUL */ |
54 | linebuf = xrealloc(linebuf, idx + 1); | 54 | linebuf = xrealloc(linebuf, idx + 1); |
55 | linebuf[idx] = '\0'; | 55 | linebuf[idx] = '\0'; |
56 | *maxsz_p = idx; | 56 | if (maxsz_p) |
57 | *maxsz_p = idx; | ||
57 | return linebuf; | 58 | return linebuf; |
58 | } | 59 | } |
59 | 60 | ||
@@ -63,23 +64,15 @@ static char *xmalloc_fgets_internal(FILE *file, const char *terminating_string, | |||
63 | * Return NULL if EOF is reached immediately. */ | 64 | * Return NULL if EOF is reached immediately. */ |
64 | char* FAST_FUNC xmalloc_fgets_str(FILE *file, const char *terminating_string) | 65 | char* FAST_FUNC xmalloc_fgets_str(FILE *file, const char *terminating_string) |
65 | { | 66 | { |
66 | size_t maxsz = INT_MAX - 4095; | 67 | return xmalloc_fgets_internal(file, terminating_string, 0, NULL); |
67 | return xmalloc_fgets_internal(file, terminating_string, 0, &maxsz); | ||
68 | } | 68 | } |
69 | 69 | ||
70 | char* FAST_FUNC xmalloc_fgets_str_len(FILE *file, const char *terminating_string, size_t *maxsz_p) | 70 | char* FAST_FUNC xmalloc_fgets_str_len(FILE *file, const char *terminating_string, size_t *maxsz_p) |
71 | { | 71 | { |
72 | size_t maxsz; | ||
73 | |||
74 | if (!maxsz_p) { | ||
75 | maxsz = INT_MAX - 4095; | ||
76 | maxsz_p = &maxsz; | ||
77 | } | ||
78 | return xmalloc_fgets_internal(file, terminating_string, 0, maxsz_p); | 72 | return xmalloc_fgets_internal(file, terminating_string, 0, maxsz_p); |
79 | } | 73 | } |
80 | 74 | ||
81 | char* FAST_FUNC xmalloc_fgetline_str(FILE *file, const char *terminating_string) | 75 | char* FAST_FUNC xmalloc_fgetline_str(FILE *file, const char *terminating_string) |
82 | { | 76 | { |
83 | size_t maxsz = INT_MAX - 4095; | 77 | return xmalloc_fgets_internal(file, terminating_string, 1, NULL); |
84 | return xmalloc_fgets_internal(file, terminating_string, 1, &maxsz); | ||
85 | } | 78 | } |
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index f3cbc512c..27c1f3a74 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -312,7 +312,7 @@ static void BB_PUTCHAR(wchar_t c) | |||
312 | ssize_t len = wcrtomb(buf, c, &mbst); | 312 | ssize_t len = wcrtomb(buf, c, &mbst); |
313 | if (len > 0) { | 313 | if (len > 0) { |
314 | buf[len] = '\0'; | 314 | buf[len] = '\0'; |
315 | fputs(buf, stdout); | 315 | fputs_stdout(buf); |
316 | } | 316 | } |
317 | } else { | 317 | } else { |
318 | /* In this case, c is always one byte */ | 318 | /* In this case, c is always one byte */ |
@@ -496,7 +496,7 @@ static void beep(void) | |||
496 | */ | 496 | */ |
497 | static void put_prompt_custom(bool is_full) | 497 | static void put_prompt_custom(bool is_full) |
498 | { | 498 | { |
499 | fputs((is_full ? cmdedit_prompt : prompt_last_line), stdout); | 499 | fputs_stdout((is_full ? cmdedit_prompt : prompt_last_line)); |
500 | cursor = 0; | 500 | cursor = 0; |
501 | cmdedit_y = cmdedit_prmt_len / cmdedit_termw; /* new quasireal y */ | 501 | cmdedit_y = cmdedit_prmt_len / cmdedit_termw; /* new quasireal y */ |
502 | cmdedit_x = cmdedit_prmt_len % cmdedit_termw; | 502 | cmdedit_x = cmdedit_prmt_len % cmdedit_termw; |
@@ -1955,7 +1955,7 @@ static void ask_terminal(void) | |||
1955 | pfd.events = POLLIN; | 1955 | pfd.events = POLLIN; |
1956 | if (safe_poll(&pfd, 1, 0) == 0) { | 1956 | if (safe_poll(&pfd, 1, 0) == 0) { |
1957 | S.sent_ESC_br6n = 1; | 1957 | S.sent_ESC_br6n = 1; |
1958 | fputs(ESC"[6n", stdout); | 1958 | fputs_stdout(ESC"[6n"); |
1959 | fflush_all(); /* make terminal see it ASAP! */ | 1959 | fflush_all(); /* make terminal see it ASAP! */ |
1960 | } | 1960 | } |
1961 | } | 1961 | } |
@@ -3085,7 +3085,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman | |||
3085 | #undef read_line_input | 3085 | #undef read_line_input |
3086 | int FAST_FUNC read_line_input(const char* prompt, char* command, int maxsize) | 3086 | int FAST_FUNC read_line_input(const char* prompt, char* command, int maxsize) |
3087 | { | 3087 | { |
3088 | fputs(prompt, stdout); | 3088 | fputs_stdout(prompt); |
3089 | fflush_all(); | 3089 | fflush_all(); |
3090 | if (!fgets(command, maxsize, stdin)) | 3090 | if (!fgets(command, maxsize, stdin)) |
3091 | return -1; | 3091 | return -1; |
diff --git a/libbb/login.c b/libbb/login.c index 7f593d80d..af860c277 100644 --- a/libbb/login.c +++ b/libbb/login.c | |||
@@ -120,7 +120,7 @@ void FAST_FUNC print_login_issue(const char *issue_file, const char *tty) | |||
120 | buf[0] = c; | 120 | buf[0] = c; |
121 | } | 121 | } |
122 | } | 122 | } |
123 | fputs(outbuf, stdout); | 123 | fputs_stdout(outbuf); |
124 | } | 124 | } |
125 | fclose(fp); | 125 | fclose(fp); |
126 | fflush_all(); | 126 | fflush_all(); |
@@ -130,8 +130,8 @@ void FAST_FUNC print_login_prompt(void) | |||
130 | { | 130 | { |
131 | char *hostname = safe_gethostname(); | 131 | char *hostname = safe_gethostname(); |
132 | 132 | ||
133 | fputs(hostname, stdout); | 133 | fputs_stdout(hostname); |
134 | fputs(LOGIN, stdout); | 134 | fputs_stdout(LOGIN); |
135 | fflush_all(); | 135 | fflush_all(); |
136 | free(hostname); | 136 | free(hostname); |
137 | } | 137 | } |
diff --git a/libbb/print_numbered_lines.c b/libbb/print_numbered_lines.c index d6459d7c3..b64f85597 100644 --- a/libbb/print_numbered_lines.c +++ b/libbb/print_numbered_lines.c | |||
@@ -22,10 +22,11 @@ int FAST_FUNC print_numbered_lines(struct number_state *ns, const char *filename | |||
22 | if (ns->all | 22 | if (ns->all |
23 | || (ns->nonempty && line[0]) | 23 | || (ns->nonempty && line[0]) |
24 | ) { | 24 | ) { |
25 | printf("%*u%s%s\n", ns->width, N, ns->sep, line); | 25 | printf("%*u%s", ns->width, N, ns->sep); |
26 | N += ns->inc; | 26 | N += ns->inc; |
27 | } else if (ns->empty_str) | 27 | } else if (ns->empty_str) |
28 | fputs(ns->empty_str, stdout); | 28 | fputs_stdout(ns->empty_str); |
29 | puts(line); | ||
29 | free(line); | 30 | free(line); |
30 | } | 31 | } |
31 | ns->start = N; | 32 | ns->start = N; |
diff --git a/libbb/update_passwd.c b/libbb/update_passwd.c index 7b67f30cd..a228075cc 100644 --- a/libbb/update_passwd.c +++ b/libbb/update_passwd.c | |||
@@ -48,7 +48,7 @@ static void check_selinux_update_passwd(const char *username) | |||
48 | bb_simple_error_msg_and_die("SELinux: access denied"); | 48 | bb_simple_error_msg_and_die("SELinux: access denied"); |
49 | } | 49 | } |
50 | if (ENABLE_FEATURE_CLEAN_UP) | 50 | if (ENABLE_FEATURE_CLEAN_UP) |
51 | freecon(context); | 51 | freecon(seuser); |
52 | } | 52 | } |
53 | #else | 53 | #else |
54 | # define check_selinux_update_passwd(username) ((void)0) | 54 | # define check_selinux_update_passwd(username) ((void)0) |
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c index 4bd19d471..d672e43e5 100644 --- a/libbb/xfuncs_printf.c +++ b/libbb/xfuncs_printf.c | |||
@@ -320,6 +320,11 @@ int FAST_FUNC bb_putchar(int ch) | |||
320 | return putchar(ch); | 320 | return putchar(ch); |
321 | } | 321 | } |
322 | 322 | ||
323 | int FAST_FUNC fputs_stdout(const char *s) | ||
324 | { | ||
325 | return fputs(s, stdout); | ||
326 | } | ||
327 | |||
323 | /* Die with an error message if we can't copy an entire FILE* to stdout, | 328 | /* Die with an error message if we can't copy an entire FILE* to stdout, |
324 | * then close that file. */ | 329 | * then close that file. */ |
325 | void FAST_FUNC xprint_and_close_file(FILE *file) | 330 | void FAST_FUNC xprint_and_close_file(FILE *file) |