From f451b2cfe042e3029b73261758b9ab7e956eaa03 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 9 Jun 2012 02:06:57 +0200 Subject: ash: fix a bug in >${varexp} handling. Closes 5282 Signed-off-by: Denys Vlasenko --- shell/ash.c | 23 +++++++++++++---------- shell/ash_test/ash-redir/redirA.right | 2 ++ shell/ash_test/ash-redir/redirA.tests | 11 +++++++++++ 3 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 shell/ash_test/ash-redir/redirA.right create mode 100755 shell/ash_test/ash-redir/redirA.tests (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index d197fa19a..e23b2034d 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -23,8 +23,9 @@ * define DEBUG=1 to compile in debugging ('set -o debug' to turn on) * define DEBUG=2 to compile in and turn on debugging. * - * When debugging is on, debugging info will be written to ./trace and - * a quit signal will generate a core dump. + * When debugging is on (DEBUG is 1 and "set -o debug" was executed), + * debugging info will be written to ./trace and a quit signal + * will generate a core dump. */ #define DEBUG 0 /* Tweak debug output verbosity here */ @@ -5105,15 +5106,14 @@ openredirect(union node *redir) char *fname; int f; + fname = redir->nfile.expfname; switch (redir->nfile.type) { case NFROM: - fname = redir->nfile.expfname; f = open(fname, O_RDONLY); if (f < 0) goto eopen; break; case NFROMTO: - fname = redir->nfile.expfname; f = open(fname, O_RDWR|O_CREAT, 0666); if (f < 0) goto ecreate; @@ -5124,7 +5124,6 @@ openredirect(union node *redir) #endif /* Take care of noclobber mode. */ if (Cflag) { - fname = redir->nfile.expfname; f = noclobberopen(fname); if (f < 0) goto ecreate; @@ -5132,13 +5131,11 @@ openredirect(union node *redir) } /* FALLTHROUGH */ case NCLOBBER: - fname = redir->nfile.expfname; f = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666); if (f < 0) goto ecreate; break; case NAPPEND: - fname = redir->nfile.expfname; f = open(fname, O_WRONLY|O_CREAT|O_APPEND, 0666); if (f < 0) goto ecreate; @@ -6138,7 +6135,9 @@ argstr(char *p, int flags, struct strlist *var_str_list) length++; goto addquote; case CTLVAR: + TRACE(("argstr: evalvar('%s')\n", p)); p = evalvar(p, flags, var_str_list); + TRACE(("argstr: evalvar:'%s'\n", (char *)stackblock())); goto start; case CTLBACKQ: c = '\0'; @@ -6846,8 +6845,7 @@ evalvar(char *p, int flags, struct strlist *var_str_list) patloc = expdest - (char *)stackblock(); if (NULL == subevalvar(p, /* varname: */ NULL, patloc, subtype, startloc, varflags, -//TODO: | EXP_REDIR too? All other such places do it too - /* quotes: */ flags & (EXP_FULL | EXP_CASE), + /* quotes: */ flags & (EXP_FULL | EXP_CASE | EXP_REDIR), var_str_list) ) { int amount = expdest - ( @@ -7249,6 +7247,7 @@ expandarg(union node *arg, struct arglist *arglist, int flag) STARTSTACKSTR(expdest); ifsfirst.next = NULL; ifslastp = NULL; + TRACE(("expandarg: argstr('%s',flags:%x)\n", arg->narg.text, flag)); argstr(arg->narg.text, flag, /* var_str_list: */ arglist ? arglist->list : NULL); p = _STPUTC('\0', expdest); @@ -7257,6 +7256,7 @@ expandarg(union node *arg, struct arglist *arglist, int flag) return; /* here document expanded */ } p = grabstackstr(p); + TRACE(("expandarg: p:'%s'\n", p)); exparg.lastp = &exparg.list; /* * TODO - EXP_REDIR @@ -7267,8 +7267,10 @@ expandarg(union node *arg, struct arglist *arglist, int flag) exparg.lastp = &exparg.list; expandmeta(exparg.list /*, flag*/); } else { - if (flag & EXP_REDIR) /*XXX - for now, just remove escapes */ + if (flag & EXP_REDIR) { /*XXX - for now, just remove escapes */ rmescapes(p, 0); + TRACE(("expandarg: rmescapes:'%s'\n", p)); + } sp = stzalloc(sizeof(*sp)); sp->text = p; *exparg.lastp = sp; @@ -8665,6 +8667,7 @@ expredir(union node *n) case NCLOBBER: case NAPPEND: expandarg(redir->nfile.fname, &fn, EXP_TILDE | EXP_REDIR); + TRACE(("expredir expanded to '%s'\n", fn.list->text)); #if ENABLE_ASH_BASH_COMPAT store_expfname: #endif diff --git a/shell/ash_test/ash-redir/redirA.right b/shell/ash_test/ash-redir/redirA.right new file mode 100644 index 000000000..31406e336 --- /dev/null +++ b/shell/ash_test/ash-redir/redirA.right @@ -0,0 +1,2 @@ +tmp11 +tmp11 diff --git a/shell/ash_test/ash-redir/redirA.tests b/shell/ash_test/ash-redir/redirA.tests new file mode 100755 index 000000000..56833f938 --- /dev/null +++ b/shell/ash_test/ash-redir/redirA.tests @@ -0,0 +1,11 @@ +x="tmp11:tmp22" + +# Bug was incorrectly expanding variables in >redir +echo "${x%:*}" >"${x%:*}" +echo tmp1* +rm tmp1* + +# Also try unquoted +echo "${x%:*}" >${x%:*} +echo tmp1* +rm tmp1* -- cgit v1.2.3-55-g6feb From c5fe9f7b723f949457263ef8e22ab807d5b549ce Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 5 Jul 2012 23:19:09 -0400 Subject: include sys/resource.h where needed We use functions from sys/resource.h in misc applets, but don't include the header. This breaks building with newer glibc versions, so add the include where needed. Signed-off-by: Mike Frysinger --- loginutils/passwd.c | 1 + miscutils/time.c | 1 + networking/inetd.c | 1 + networking/ntpd.c | 1 + networking/ntpd_simple.c | 1 + runit/chpst.c | 1 + shell/shell_common.c | 1 + 7 files changed, 7 insertions(+) (limited to 'shell') diff --git a/loginutils/passwd.c b/loginutils/passwd.c index b83db0083..a7006f054 100644 --- a/loginutils/passwd.c +++ b/loginutils/passwd.c @@ -15,6 +15,7 @@ #include "libbb.h" #include +#include /* setrlimit */ static void nuke_str(char *str) { diff --git a/miscutils/time.c b/miscutils/time.c index 945f15f0d..ffed38632 100644 --- a/miscutils/time.c +++ b/miscutils/time.c @@ -16,6 +16,7 @@ //usage: "\n -v Verbose" #include "libbb.h" +#include /* getrusage */ /* Information on the resources used by a child process. */ typedef struct { diff --git a/networking/inetd.c b/networking/inetd.c index 1308d74c7..00baf6971 100644 --- a/networking/inetd.c +++ b/networking/inetd.c @@ -165,6 +165,7 @@ //usage: "\n (default: 0 - disabled)" #include +#include /* setrlimit */ #include /* un.h may need this */ #include diff --git a/networking/ntpd.c b/networking/ntpd.c index 72e9d0be2..5b92db6f6 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -46,6 +46,7 @@ #include "libbb.h" #include #include /* For IPTOS_LOWDELAY definition */ +#include /* setpriority */ #include #ifndef IPTOS_LOWDELAY # define IPTOS_LOWDELAY 0x10 diff --git a/networking/ntpd_simple.c b/networking/ntpd_simple.c index 4ad44e4f3..1b7c66b84 100644 --- a/networking/ntpd_simple.c +++ b/networking/ntpd_simple.c @@ -7,6 +7,7 @@ */ #include "libbb.h" #include /* For IPTOS_LOWDELAY definition */ +#include /* setpriority */ #ifndef IPTOS_LOWDELAY # define IPTOS_LOWDELAY 0x10 #endif diff --git a/runit/chpst.c b/runit/chpst.c index ac296babf..ed72c8b8c 100644 --- a/runit/chpst.c +++ b/runit/chpst.c @@ -91,6 +91,7 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. //usage: "\n a SIGXCPU after N seconds" #include "libbb.h" +#include /* getrlimit */ /* Five applets here: chpst, envdir, envuidgid, setuidgid, softlimit. diff --git a/shell/shell_common.c b/shell/shell_common.c index 51c92d60e..780e27ebd 100644 --- a/shell/shell_common.c +++ b/shell/shell_common.c @@ -18,6 +18,7 @@ */ #include "libbb.h" #include "shell_common.h" +#include /* getrlimit */ const char defifsvar[] ALIGN1 = "IFS= \t\n"; -- cgit v1.2.3-55-g6feb From 566a313a7f531d7df28f8ae01d19a4b28134b2e3 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 7 Jul 2012 21:40:35 +0200 Subject: ash: add a comment about VEXPORT Signed-off-by: Denys Vlasenko --- shell/ash.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index e23b2034d..b20c32b89 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -1900,6 +1900,10 @@ static const struct { const char *var_text; void (*var_func)(const char *) FAST_FUNC; } varinit_data[] = { + /* + * Note: VEXPORT would not work correctly here for NOFORK applets: + * some environment strings may be constant. + */ { VSTRFIXED|VTEXTFIXED , defifsvar , NULL }, #if ENABLE_ASH_MAIL { VSTRFIXED|VTEXTFIXED|VUNSET, "MAIL" , changemail }, -- cgit v1.2.3-55-g6feb From 32f774cd344cf12336c22b0947f102274a99ee31 Mon Sep 17 00:00:00 2001 From: Michael Tokarev Date: Tue, 24 Jul 2012 15:56:37 +0200 Subject: *: declare strings with ALIGN1, as appropriate Signed-off-by: Michael Tokarev Signed-off-by: Denys Vlasenko --- include/busybox.h | 4 ++-- networking/udhcp/common.h | 4 ++-- shell/shell_common.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'shell') diff --git a/include/busybox.h b/include/busybox.h index 315ef8f26..b1e31e5ee 100644 --- a/include/busybox.h +++ b/include/busybox.h @@ -13,10 +13,10 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN /* Defined in appletlib.c (by including generated applet_tables.h) */ /* Keep in sync with applets/applet_tables.c! */ -extern const char applet_names[]; +extern const char applet_names[] ALIGN1; extern int (*const applet_main[])(int argc, char **argv); extern const uint16_t applet_nameofs[]; -extern const uint8_t applet_install_loc[]; +extern const uint8_t applet_install_loc[] ALIGN1; #if ENABLE_FEATURE_SUID || ENABLE_FEATURE_PREFER_APPLETS # define APPLET_NAME(i) (applet_names + (applet_nameofs[i] & 0x0fff)) diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h index cfd58679a..4fa0471de 100644 --- a/networking/udhcp/common.h +++ b/networking/udhcp/common.h @@ -187,8 +187,8 @@ struct option_set { }; extern const struct dhcp_optflag dhcp_optflags[]; -extern const char dhcp_option_strings[]; -extern const uint8_t dhcp_option_lengths[]; +extern const char dhcp_option_strings[] ALIGN1; +extern const uint8_t dhcp_option_lengths[] ALIGN1; unsigned FAST_FUNC udhcp_option_idx(const char *name); diff --git a/shell/shell_common.h b/shell/shell_common.h index f06bc4120..993ed5951 100644 --- a/shell/shell_common.h +++ b/shell/shell_common.h @@ -21,7 +21,7 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN -extern const char defifsvar[]; /* "IFS= \t\n" */ +extern const char defifsvar[] ALIGN1; /* "IFS= \t\n" */ #define defifs (defifsvar + 4) int FAST_FUNC is_well_formed_var_name(const char *s, char terminator); -- cgit v1.2.3-55-g6feb From 9e71e3cea59c06d40234d8f3363c3f05112e8d5a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 6 Sep 2012 13:28:10 +0200 Subject: ash: fix "read -s" + ^C. Closes 5504 Signed-off-by: Denys Vlasenko --- shell/ash.c | 5 +++++ shell/shell_common.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index b20c32b89..153bcc057 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -12803,6 +12803,10 @@ readcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) } } + /* "read -s" needs to save/restore termios, can't allow ^C + * to jump out of it. + */ + INT_OFF; r = shell_builtin_read(setvar2, argptr, bltinlookup("IFS"), /* can be NULL */ @@ -12812,6 +12816,7 @@ readcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) opt_t, opt_u ); + INT_ON; if ((uintptr_t)r > 1) ash_msg_and_raise_error(r); diff --git a/shell/shell_common.c b/shell/shell_common.c index 780e27ebd..0051f21d9 100644 --- a/shell/shell_common.c +++ b/shell/shell_common.c @@ -170,7 +170,7 @@ shell_builtin_read(void FAST_FUNC (*setvar)(const char *name, const char *val), int timeout; if ((bufpos & 0xff) == 0) - buffer = xrealloc(buffer, bufpos + 0x100); + buffer = xrealloc(buffer, bufpos + 0x101); timeout = -1; if (end_ms) { -- cgit v1.2.3-55-g6feb