From 48645b83502a5add5429b6cbb19cf3a083f1adf4 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 18 Apr 2019 09:48:13 +0100 Subject: ash: prevent error in backquotes in PS1 from exiting shell Setting PS1 to: PS1='`xxx(`' causes the shell to terminate with the error: sh: syntax error: unexpected end of file (expecting ")") This happens because old-style backquotes require the input to be reread and thus call setinputstring() a second time. Prevent the problem by unwinding all recently opened files in expandstr(). function old new delta unwindfiles - 22 +22 expandstr 247 262 +15 forkchild 631 625 -6 evalcommand 1694 1685 -9 ash_main 1346 1336 -10 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/3 up/down: 37/-25) Total: 12 bytes Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- shell/ash.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index b707d00d0..f3a2c6952 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -13042,6 +13042,7 @@ expandstr(const char *ps, int syntax_type) { union node n; int saveprompt; + struct parsefile *file_stop = g_parsefile; /* XXX Fix (char *) cast. */ setinputstring((char *)ps); @@ -13068,7 +13069,8 @@ expandstr(const char *ps, int syntax_type) doprompt = saveprompt; - popfile(); + /* Try: PS1='`xxx(`' */ + unwindfiles(file_stop); n.narg.type = NARG; n.narg.next = NULL; -- cgit v1.2.3-55-g6feb From d1a2fa2a4e013960bf56dfef8a71ed2d08fc756b Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 18 Apr 2019 09:49:13 +0100 Subject: ash: catch error in arithmetic expansion in PS1 Setting PS1 to: PS1='$((123+))' causes the shell to enter an infinite error loop: sh: arithmetic syntax error Catch any exception raised by expandarg() in expandstr() and allow processing to continue. function old new delta expandstr 262 344 +82 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 82/0) Total: 82 bytes Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- shell/ash.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index f3a2c6952..924e17f32 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -13043,6 +13043,9 @@ expandstr(const char *ps, int syntax_type) union node n; int saveprompt; struct parsefile *file_stop = g_parsefile; + volatile int saveint; + struct jmploc *volatile savehandler = exception_handler; + struct jmploc jmploc; /* XXX Fix (char *) cast. */ setinputstring((char *)ps); @@ -13054,18 +13057,13 @@ expandstr(const char *ps, int syntax_type) * Try a prompt with syntactically wrong command: * PS1='$(date "+%H:%M:%S) > ' */ - { - volatile int saveint; - struct jmploc *volatile savehandler = exception_handler; - struct jmploc jmploc; - SAVE_INT(saveint); - if (setjmp(jmploc.loc) == 0) { - exception_handler = &jmploc; - readtoken1(pgetc(), syntax_type, FAKEEOFMARK, 0); - } - exception_handler = savehandler; - RESTORE_INT(saveint); + SAVE_INT(saveint); + if (setjmp(jmploc.loc) == 0) { + exception_handler = &jmploc; + readtoken1(pgetc(), syntax_type, FAKEEOFMARK, 0); } + exception_handler = savehandler; + RESTORE_INT(saveint); doprompt = saveprompt; @@ -13077,7 +13075,17 @@ expandstr(const char *ps, int syntax_type) n.narg.text = wordtext; n.narg.backquote = backquotelist; - expandarg(&n, NULL, EXP_QUOTED); + /* expandarg() might fail too: + * PS1='$((123+))' + */ + SAVE_INT(saveint); + if (setjmp(jmploc.loc) == 0) { + exception_handler = &jmploc; + expandarg(&n, NULL, EXP_QUOTED); + } + exception_handler = savehandler; + RESTORE_INT(saveint); + return stackblock(); } -- cgit v1.2.3-55-g6feb From 1c356948f137d46872d6af17d586960517cf100a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 19 Apr 2019 14:19:41 +0200 Subject: httpd: use full size of iobuf[] when piping CGI data Signed-off-by: Denys Vlasenko --- networking/httpd.c | 15 ++++----------- shell/hush.c | 3 --- 2 files changed, 4 insertions(+), 14 deletions(-) (limited to 'shell') diff --git a/networking/httpd.c b/networking/httpd.c index aa8ce8dcb..d44ec271a 100644 --- a/networking/httpd.c +++ b/networking/httpd.c @@ -259,18 +259,11 @@ #if ENABLE_FEATURE_USE_SENDFILE # include #endif -/* amount of buffering in a pipe */ -#ifndef PIPE_BUF -# define PIPE_BUF 4096 -#endif #define DEBUG 0 #define IOBUF_SIZE 8192 -#define MAX_HTTP_HEADERS_SIZE ((8*1024) - 16) -#if PIPE_BUF >= IOBUF_SIZE -# error "PIPE_BUF >= IOBUF_SIZE" -#endif +#define MAX_HTTP_HEADERS_SIZE (32*1024) #define HEADER_READ_TIMEOUT 60 @@ -1413,10 +1406,10 @@ static NOINLINE void cgi_io_loop_and_exit(int fromCgi_rd, int toCgi_wr, int post * CGI may output a few first bytes and then wait * for POSTDATA without closing stdout. * With full_read we may wait here forever. */ - count = safe_read(fromCgi_rd, rbuf + out_cnt, PIPE_BUF - 8); + count = safe_read(fromCgi_rd, rbuf + out_cnt, IOBUF_SIZE - 8); if (count <= 0) { /* eof (or error) and there was no "HTTP", - * so write it, then write received data */ + * send "HTTP/1.0 200 OK\r\n", then send received data */ if (out_cnt) { full_write(STDOUT_FILENO, HTTP_200, sizeof(HTTP_200)-1); full_write(STDOUT_FILENO, rbuf, out_cnt); @@ -1454,7 +1447,7 @@ static NOINLINE void cgi_io_loop_and_exit(int fromCgi_rd, int toCgi_wr, int post out_cnt = -1; /* buffering off */ } } else { - count = safe_read(fromCgi_rd, rbuf, PIPE_BUF); + count = safe_read(fromCgi_rd, rbuf, IOBUF_SIZE); if (count <= 0) break; /* eof (or error) */ } diff --git a/shell/hush.c b/shell/hush.c index d745148f4..b3ae73b9b 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -363,9 +363,6 @@ #ifndef F_DUPFD_CLOEXEC # define F_DUPFD_CLOEXEC F_DUPFD #endif -#ifndef PIPE_BUF -# define PIPE_BUF 4096 /* amount of buffering in a pipe */ -#endif #if ENABLE_FEATURE_SH_EMBEDDED_SCRIPTS && !(ENABLE_ASH || ENABLE_SH_IS_ASH || ENABLE_BASH_IS_ASH) # include "embedded_scripts.h" -- cgit v1.2.3-55-g6feb