oweals/busybox.git
8 years agohush: 'return' should have effect earlier
Denys Vlasenko [Sat, 1 Oct 2016 20:28:03 +0000 (22:28 +0200)]
hush: 'return' should have effect earlier

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: [EXPAND] Optimise nulonly away and just use quoted as before
Denys Vlasenko [Sat, 1 Oct 2016 19:02:06 +0000 (21:02 +0200)]
ash: [EXPAND] Optimise nulonly away and just use quoted as before

Upstream commit:

    Date: Wed, 8 Oct 2014 20:09:56 +0800
    [EXPAND] Optimise nulonly away and just use quoted as before

    This patch makes a small optimisation by using the same value for
    quoted between evalvar and varvalue by eliminating nulonly and
    passing along quoted instead.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: [EXPAND] Do not split quoted VSLENGTH and VSTRIM
Denys Vlasenko [Sat, 1 Oct 2016 18:55:02 +0000 (20:55 +0200)]
ash: [EXPAND] Do not split quoted VSLENGTH and VSTRIM

Upstream patch:

    Date: Wed, 8 Oct 2014 15:42:08 +0800
    [EXPAND] Do not split quoted VSLENGTH and VSTRIM

    Currently VSLENGTH and VSTRIM* are field-split even within quotes.
    This is obviously wrong.  This patch fixes that.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: [EXPAND] Split unquoted $@/$* correctly when IFS is set but empty
Denys Vlasenko [Sat, 1 Oct 2016 18:35:10 +0000 (20:35 +0200)]
ash: [EXPAND] Split unquoted $@/$* correctly when IFS is set but empty

Upstream commit:

    Date: Wed, 8 Oct 2014 15:24:23 +0800
    [EXPAND] Split unquoted $@/$* correctly when IFS is set but empty

    Currently we do not field-split $@/$* when it isn't quoted and IFS
    is set but empty.  This is obviously wrong.  This patch fixes this.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agohush: add func6.tests
Denys Vlasenko [Sat, 1 Oct 2016 18:12:10 +0000 (20:12 +0200)]
hush: add func6.tests

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: fix "return N" not setting $? in loop conditionals
Denys Vlasenko [Sat, 1 Oct 2016 17:56:52 +0000 (19:56 +0200)]
ash: fix "return N" not setting $? in loop conditionals

Upstream commit 1:

    Date: Mon, 6 Oct 2014 20:45:04 +0800
    [EVAL] Move common skipcount logic into skiploop

    The functions evalloop and evalfor share the logic on checking
    and updating skipcount.  This patch moves that into the helper
    function skiploop.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Upstream commit 2:

    Date: Mon, 6 Oct 2014 21:22:43 +0800
    [BUILTIN] Allow return in loop conditional to set exit status

    https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=332954

    When return is used in a loop conditional the exit status will
    be lost because we always set the exit status at the end of the
    loop to that of the last command executed in the body.

    This is counterintuitive and contrary to what most other shells do.

    This patch fixes this by always preserving the exit status of
    return when it is used in a loop conditional.

    The patch was originally written by Gerrit Pape <pape@smarden.org>.

Reported-by: Stephane Chazelas <stephane_chazelas@yahoo.fr>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash testsuite: remove two more inadvertent bashisms
Denys Vlasenko [Sat, 1 Oct 2016 15:43:04 +0000 (17:43 +0200)]
ash testsuite: remove two more inadvertent bashisms

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash testsuite: remove two inadvertent bashisms
Denys Vlasenko [Sat, 1 Oct 2016 15:30:21 +0000 (17:30 +0200)]
ash testsuite: remove two inadvertent bashisms

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: [ERROR] Set exitstatus in onint
Denys Vlasenko [Sat, 1 Oct 2016 14:03:11 +0000 (16:03 +0200)]
ash: [ERROR] Set exitstatus in onint

Partially backported this commit:

    Date: Thu, 2 Oct 2014 21:07:55 +0800
    [ERROR] Set exitstatus in onint

    Currently the exit status when we receive SIGINT is set in evalcommand
    which means that it doesn't always get set.  For example, if you press
    CTRL-C at the prompt of an interactive dash, the exit status is not
    set to 130 as it is in many other Bourne shells.

    This patch fixes this by moving the setting of the exit status into
    onint which also simplifies evalcommand.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
The part after "if (evalbltin(cmdentry.u.cmd, argc, argv, flags))"
causes testsuite failures in signal handling, so left unchanged.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: [EVAL] Revert SKIPEVAL into EXEXIT
Denys Vlasenko [Sat, 1 Oct 2016 13:27:44 +0000 (15:27 +0200)]
ash: [EVAL] Revert SKIPEVAL into EXEXIT

Upstream commit:

    Date:   Tue Aug 11 20:56:53 2009 +1000
    [EVAL] Revert SKIPEVAL into EXEXIT

    Now that eval handles EV_TESTED correctly, we can remove the
    SKIPEVAL hack and simply use EXEXIT for set -e.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: [EVAL] Pass EV_TESTED into evalcmd
Denys Vlasenko [Sat, 1 Oct 2016 13:10:16 +0000 (15:10 +0200)]
ash: [EVAL] Pass EV_TESTED into evalcmd

Upstream commit:

    Date:   Tue Aug 11 20:48:15 2009 +1000
    [EVAL] Pass EV_TESTED into evalcmd

    This patch fixes the case where the eval command is used with
    set -e and as part of a construct that should not cause the
    shell to abort, e.g., as part of the condition of an if statement.

    This is achieved by propagating the EV_TESTED flag into the
    evalstring function through evalcmd.  As this alters the prototype
    of evalcmd it is now invoked explicitly by evalbltin.  The built-in
    infrastructure has been changed to accomodate this special case.

    In order to ensure that the EXIT trap is properly executed this
    patch clears evalskip in exitshell.  This wasn't needed before
    because of the broken way evalstring worked where it always clears
    evalskip when called by minusc.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Although, I failed to create a reproducer for this.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: fix a thinko in the last commit
Denys Vlasenko [Sat, 1 Oct 2016 12:47:52 +0000 (14:47 +0200)]
ash: fix a thinko in the last commit

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: make internal globbing code selectable from config
Denys Vlasenko [Sat, 1 Oct 2016 12:33:08 +0000 (14:33 +0200)]
ash: make internal globbing code selectable from config

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: explain how "command" is handled, and shrink it a bit
Denys Vlasenko [Sat, 1 Oct 2016 01:02:25 +0000 (03:02 +0200)]
ash: explain how "command" is handled, and shrink it a bit

function                                             old     new   delta
getoptscmd                                           641     632      -9
commandcmd                                            79      69     -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-19)             Total: -19 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: [VAR] Initialise OPTIND after importing environment
Denys Vlasenko [Fri, 30 Sep 2016 12:36:59 +0000 (14:36 +0200)]
ash: [VAR] Initialise OPTIND after importing environment

Upstream commit 1:

    Date: Fri, 23 Aug 2013 21:27:42 +1000
    [VAR] Initialise OPTIND after importing environment

    On Sat, Mar 23, 2013 at 01:46:20AM +0000, Chris F.A. Johnson wrote:
    >   According to both the dash man page and the POSIX spec, "When the
    >   shell is invoked, OPTIND is initialized to 1."
    >
    >   However, it actually takes the value of the environment variable
    >   if it exists:
    >
    > $ OPTIND=4 dash -c 'echo "$OPTIND"'
    > 4
    > $ OPTIND=4 bash -c 'echo "$OPTIND"'
    > 1
    > $ OPTIND=4 ksh -c 'echo "$OPTIND"'
    > 1
    > $ OPTIND=4 ksh93 -c 'echo "$OPTIND"'
    > 1

    This patch fixes this by initialising OPTIND after importing the
    environment.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Upstream commit 2:

    Date: Tue, 7 Oct 2014 22:24:42 +0800
    [VAR] Use setvareq to set OPTIND initially

    There is no need to setvarint to set the initial value of OPTIND
    of one.  This patch switchs to setvareq which also lets us avoid
    an unnecessary memory allocation.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: [BUILTIN] Merge SKIPFUNC/SKIPFILE and only clear SKIPFUNC when leaving dotcmd
Denys Vlasenko [Fri, 30 Sep 2016 12:18:34 +0000 (14:18 +0200)]
ash: [BUILTIN] Merge SKIPFUNC/SKIPFILE and only clear SKIPFUNC when leaving dotcmd

Upstream commit:

    Date: Sat, 9 Jul 2011 22:05:22 +0800
    [BUILTIN] Merge SKIPFUNC/SKIPFILE and only clear SKIPFUNC when leaving dotcmd

    Currently upon leaving a dotcmd the evalskip state is reset so
    if a continue/break statement is used within a dot script it would
    have no effect outside of the dot script.

    This is inconsistent with other shells.

    This patch is based on one by Jilles Tjoelker and only clears
    SKIPFUNC when leaving a dot script.  As a result continue/break
    will remain in effect.

    It also merges SKIPFUNC/SKIPFILE as they have no practical difference.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agohush: enable "msh is deprecated" message in msh stub
Denys Vlasenko [Fri, 30 Sep 2016 10:28:37 +0000 (12:28 +0200)]
hush: enable "msh is deprecated" message in msh stub

After giving a few more years for everyone to notice and migrate,
can nuke all remains of msh.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: Avoid overflow for very long variable name
Denys Vlasenko [Fri, 30 Sep 2016 09:35:54 +0000 (11:35 +0200)]
ash: Avoid overflow for very long variable name

Upstream commit:

    Date: Tue, 3 Jul 2012 17:32:33 +0800
    Avoid overflow for very long variable name

    Otherwise, this:
      $ perl -le 'print "v"x(2**31+1) ."=1"' | dash
    provokes integer overflow

Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: [VAR] Sanitise environment variable names on entry
Denys Vlasenko [Fri, 30 Sep 2016 09:33:47 +0000 (11:33 +0200)]
ash: [VAR] Sanitise environment variable names on entry

Upstream commit:

    Date: Sat, 25 Feb 2012 15:35:18 +0800
    [VAR] Sanitise environment variable names on entry

    On Tue, Feb 14, 2012 at 10:48:48AM +0000, harald@redhat.com wrote:
    > "export -p" prints all environment variables, without checking if the
    > environment variable is a valid dash variable name.
    >
    > IMHO, the only valid usecase for "export -p" is to eval the output.
    >
    > $ eval $(export -p); echo OK
    > OK
    >
    > Without this patch the following test does error out with:
    >
    > test.py:
    > import os
    > os.environ["test-test"]="test"
    > os.environ["test_test"]="test"
    > os.execv("./dash", [ './dash', '-c', 'eval $(export -p); echo OK' ])
    >
    > $ python test.py
    > ./dash: 1: export: test-test: bad variable name
    >
    > Of course the results can be more evil, if the environment variable
    > name is crafted, that it injects valid shell code.

    This patch fixes the issue by sanitising all environment variable names
    upon entry into the shell.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: [EVAL] Avoid using undefined handler
Denys Vlasenko [Fri, 30 Sep 2016 09:30:11 +0000 (11:30 +0200)]
ash: [EVAL] Avoid using undefined handler

Upstream commit:

    Date: Fri, 8 Jul 2011 16:41:24 +0800
    [EVAL] Avoid using undefined handler

    * src/eval.c (evalbltin, evalfun): Set savehandler before calling
    setjmp with the possible "goto *done", where savehandler is used.
    Otherwise, clang warns that "Assigned value is garbage or undefined"
    at the point where "savehandler" is used on the RHS.

Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: remove dead stores and unused variables
Denys Vlasenko [Fri, 30 Sep 2016 09:24:12 +0000 (11:24 +0200)]
ash: remove dead stores and unused variables

Upstream commit 1:

    Date: Fri, 8 Jul 2011 16:12:20 +0800
    [MEMALLOC] Avoid gcc warning: variable 'oldstackp' set but not used

    * src/memalloc.c (growstackblock): Remove declaration and set of
    set-but-not-used variable.  Also remove a stray space-before-TAB.

Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Upstream commit 2:

    Date: Fri, 8 Jul 2011 16:16:11 +0800
    [MEMALLOC] Avoid clang warning about dead store to "size"

    * src/memalloc.c (makestrspace): Remove dead store.

Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: [MEMALLOC] Add pushstackmark
Denys Vlasenko [Fri, 30 Sep 2016 09:21:21 +0000 (11:21 +0200)]
ash: [MEMALLOC] Add pushstackmark

Upstream commit:

    Author: Herbert Xu <herbert@gondor.apana.org.au>
    Date:   Sat Oct 6 00:45:52 2007 +0800

    [MEMALLOC] Add pushstackmark

    This patch gets rid of the stack mark tracking hack by allocating a little
    bit of stack memory if we're at risk of planting a stack mark which may be
    grown later.  To do this a new function pushstackmark is added which lets
    the user pick a bigger amount to allocate since some users do that anyway
    after setting a stack mark.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agohush: fix typo in comment
Denys Vlasenko [Fri, 30 Sep 2016 00:02:25 +0000 (02:02 +0200)]
hush: fix typo in comment

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agohush: fix interactive input handling of backslash+newline
Denys Vlasenko [Thu, 29 Sep 2016 23:49:53 +0000 (01:49 +0200)]
hush: fix interactive input handling of backslash+newline

function                                             old     new   delta
fgetc_interactive                                      -     258    +258
i_peek_and_eat_bkslash_nl                             43      93     +50
static_peek2                                           7       -      -7
setup_string_in_str                                   46      39      -7
setup_file_in_str                                     47      40      -7
file_peek                                             72      52     -20
expand_vars_to_list                                 1167    1143     -24
file_peek2                                            74       -     -74
file_get                                             326      65    -261
------------------------------------------------------------------------------
(add/remove: 1/2 grow/shrink: 1/5 up/down: 308/-400)          Total: -92 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agohush: G.user_input_buf[] is needed only if line editing is enabled
Denys Vlasenko [Thu, 29 Sep 2016 18:25:44 +0000 (20:25 +0200)]
hush: G.user_input_buf[] is needed only if line editing is enabled

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoshell testsuite: add trailing newline to var_unbackslash1.tests
Denys Vlasenko [Thu, 29 Sep 2016 18:02:53 +0000 (20:02 +0200)]
shell testsuite: add trailing newline to var_unbackslash1.tests

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agohush: speed optimizations
Denys Vlasenko [Thu, 29 Sep 2016 17:50:55 +0000 (19:50 +0200)]
hush: speed optimizations

Make o_addchr() faster: do not call o_grow_by() each time.
Create i_getch_and_eat_bkslash_nl(), use it instead of peek+getch pair.

function                                             old     new   delta
o_addchr                                              42      54     +12
parse_dollar                                         761     771     +10
o_grow_by                                             48      37     -11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 24/-11)             Total: 11 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agohush: fix handling of by backslash-newline in $((arith)) and $(cmd)
Denys Vlasenko [Thu, 29 Sep 2016 16:07:42 +0000 (18:07 +0200)]
hush: fix handling of by backslash-newline in $((arith)) and $(cmd)

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agohush: rework input char buffering to allow more than one-deep peek
Denys Vlasenko [Thu, 29 Sep 2016 16:02:37 +0000 (18:02 +0200)]
hush: rework input char buffering to allow more than one-deep peek

...this time with actual hush.c changes too :)

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: fix arithmetic closing )) split by backslash-newline
Denys Vlasenko [Thu, 29 Sep 2016 15:58:58 +0000 (17:58 +0200)]
ash: fix arithmetic closing )) split by backslash-newline

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: [PARSER] Handle backslash newlines properly after dollar sign
Denys Vlasenko [Thu, 29 Sep 2016 15:17:04 +0000 (17:17 +0200)]
ash: [PARSER] Handle backslash newlines properly after dollar sign

Fixes var_unbackslash1.tests failure.

Upstream commit:

    [PARSER] Handle backslash newlines properly after dollar sign

    On Tue, Aug 26, 2014 at 12:34:42PM +0000, Eric Blake wrote:
    > On 08/26/2014 06:15 AM, Oleg Bulatov wrote:
    > > While playing with sh generators I found that dash and bash have different
    > > interpretations for <slash><newline> sequence.
    > >
    > > $ dash -c 'EDIT=xxx; echo $EDIT\
    > >> OR'
    > > xxxOR
    >
    > Buggy.
    > >
    > > $ dash -c 'echo "$\
    > > (pwd)"'
    > > $(pwd)
    > >
    > > Is it undefined behaviour in POSIX?
    >
    > No, it's well-defined, and dash is buggy.
    ...

    I agree.  This patch should resolve this problem and similar ones
    affecting blackslash newlines after we encounter a dollar sign.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agohush: rework input char buffering to allow more than one-deep peek
Denys Vlasenko [Thu, 29 Sep 2016 14:59:06 +0000 (16:59 +0200)]
hush: rework input char buffering to allow more than one-deep peek

This fixes backslash+newline continuation in
$VAR\
NAME
construct. (ash has a bug there as well).

function                                             old     new   delta
file_peek2                                             -      74     +74
parse_dollar                                         746     773     +27
expand_vars_to_list                                 1143    1167     +24
setup_string_in_str                                   32      46     +14
setup_file_in_str                                     33      47     +14
file_get                                             264     278     +14
static_peek2                                           -       7      +7
file_peek                                             91      72     -19
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 5/1 up/down: 174/-19)           Total: 155 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: input: Allow two consecutive calls to pungetc
Denys Vlasenko [Thu, 29 Sep 2016 00:11:19 +0000 (02:11 +0200)]
ash: input: Allow two consecutive calls to pungetc

Upstream commit:

    input: Allow two consecutive calls to pungetc

    The commit ef91d3d6a4c39421fd3a391e02cd82f9f3aee4a8 ([PARSER]
    Handle backslash newlines properly after dollar sign) created
    cases where we make two consecutive calls to pungetc.  As we
    don't explicitly support that there are corner cases where you
    end up with garbage input leading to undefined behaviour.

    This patch adds explicit support for two consecutive calls to
    pungetc.

Reported-by: Jilles Tjoelker <jilles@stack.nl>
Reported-by: Juergen Daubert <jue@jue.li>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
In bbox case, bashism >& may need two pungetc() too.

function                                             old     new   delta
pgetc                                                514     555     +41
pushstring                                           114     144     +30
basepf                                                52      76     +24
popstring                                            134     151     +17
parse_command                                       1584    1585      +1
pungetc                                               12       9      -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/1 up/down: 113/-3)            Total: 110 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agohush: fix 'eval ""' handling
Denys Vlasenko [Wed, 28 Sep 2016 23:44:17 +0000 (01:44 +0200)]
hush: fix 'eval ""' handling

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agohush: fix ". EMPTY_LINE" not setting $? to 0
Denys Vlasenko [Wed, 28 Sep 2016 23:27:09 +0000 (01:27 +0200)]
hush: fix ". EMPTY_LINE" not setting $? to 0

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: jobs: Don't attempt to access job table for job %0
Denys Vlasenko [Wed, 28 Sep 2016 23:10:08 +0000 (01:10 +0200)]
ash: jobs: Don't attempt to access job table for job %0

Upstream commit:

    jobs: Don't attempt to access job table for job %0

    If job %0 is (mistakenly) specified, an out-of-bounds access to the
    jobtab occurs in function getjob() if num = 0:

            jp = jobtab + 0 - 1

    Fix this by checking that the job number is larger than 0 before
    accessing the jobtab.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: [EVAL] Make eval with empty arguments return 0
Denys Vlasenko [Wed, 28 Sep 2016 22:30:31 +0000 (00:30 +0200)]
ash: [EVAL] Make eval with empty arguments return 0

This is a backport of upstream commit:

    [EVAL] Make eval with empty arguments return 0

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: [EVAL] Fix use-after-free in dotrap/evalstring
Denys Vlasenko [Wed, 28 Sep 2016 21:02:57 +0000 (23:02 +0200)]
ash: [EVAL] Fix use-after-free in dotrap/evalstring

From upstream:

    [EVAL] Fix use-after-free in dotrap/evalstring

    The function dotrap calls evalstring using the stored trap string.
    If evalstring then unsets that exact trap string then we will end
    up using freed memory.

    This patch fixes it by making evalstring always duplicate the string
    before using it.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: Remove unused EV_BACKCMD flag
Denys Vlasenko [Wed, 28 Sep 2016 17:44:16 +0000 (19:44 +0200)]
ash: Remove unused EV_BACKCMD flag

    The original ash defered forking commands in backquotes so builtins
    could be run in the same context as the shell.  This behavior was
    controlled using the EV_BACKCMD to evaltree.

    Unfortunately, as Matthias Scheler noticed in 1999 (NetBSD PR/7814),
    the result was counterintuitive; for example, echo "`cd /`" would
    change the cwd.  So ash 0.3.5 left out that optimization.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: eval: Return status in eval functions
Denys Vlasenko [Wed, 28 Sep 2016 17:41:57 +0000 (19:41 +0200)]
ash: eval: Return status in eval functions

Backported from dash:

    eval: Return status in eval functions

    The exit status is currently clobbered too early for case statements
    and loops.  This patch fixes it by making the eval functions return
    the current exit status and setting them in one place -- evaltree.

    Harald van Dijk pointed out a number of bugs in the original patch.

function                                             old     new   delta
evalcommand                                         1226    1242     +16
cmdloop                                              383     398     +15
evalfor                                              223     227      +4
evalcase                                             271     275      +4
localcmd                                             348     350      +2
evaltreenr                                           927     928      +1
evaltree                                             927     928      +1
evalsubshell                                         150     151      +1
evalpipe                                             356     357      +1
parse_command                                       1585    1584      -1
evalloop                                             177     164     -13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 9/2 up/down: 45/-14)             Total: 31 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agotraceroute: cleanup and fixes for packet size calculations
Denys Vlasenko [Wed, 28 Sep 2016 16:39:06 +0000 (18:39 +0200)]
traceroute: cleanup and fixes for packet size calculations

Remove FEATURE_TRACEROUTE_SOURCE_ROUTE: it's off by default, and
source routing is not used in real world.

Tested that "traceroute -n ::1 100" and "traceroute -n 127.0.0.1 100"
both send 100 byte IP packets (this matches what traceroute on Fedora
Rawhide is doing).

function                                             old     new   delta
common_traceroute_main                              3731    3738      +7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agovi: fix '' command (goto to prev context)
Denys Vlasenko [Wed, 28 Sep 2016 14:23:05 +0000 (16:23 +0200)]
vi: fix '' command (goto to prev context)

The '' command in vi doesn't currently work because after the first
apostrophe is read, the next character is converted to an integer
between 0 and 25 inclusive (for indexing the array of marks). The
comparison of the converted character with an apostrophe therefore never
succeeds, meaning that '' doesn't do anything.

Based on the patch by Francis Rounds <francis.rounds@4bridgeworks.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agomount: for cifs, dont insert "ip=ADDR" option if user gave it explicitly
Denys Vlasenko [Tue, 27 Sep 2016 19:02:35 +0000 (21:02 +0200)]
mount: for cifs, dont insert "ip=ADDR" option if user gave it explicitly

This makes it possible to use scoped IPv6 addresses:

mount -t cifs -o ip=<ADDR>%<iface_id> //<ADDR>/test test

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoexamples: wpa_supplicant.conf has a wrong field deleted in examples
Denys Vlasenko [Mon, 26 Sep 2016 18:47:17 +0000 (20:47 +0200)]
examples: wpa_supplicant.conf has a wrong field deleted in examples

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agomount: tweak "IPv6 scoped addr" commit
Denys Vlasenko [Mon, 26 Sep 2016 18:36:30 +0000 (20:36 +0200)]
mount: tweak "IPv6 scoped addr" commit

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agolibbb: make xmalloc_sockaddr2dotted use NI_NUMERICSCOPE
Denys Vlasenko [Mon, 26 Sep 2016 17:53:04 +0000 (19:53 +0200)]
libbb: make xmalloc_sockaddr2dotted use NI_NUMERICSCOPE

Gives "mount -t cifs //fe80::6a05:caff:fe3e:dbf5%eth0/test test"
a chance to work: mount must pass "ip=numeric_IPv6%numeric_iface_id"
in the omunt option string. Currently, it does not.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agolibbb/speed_table.c: expand comments
Denys Vlasenko [Mon, 26 Sep 2016 12:37:12 +0000 (14:37 +0200)]
libbb/speed_table.c: expand comments

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agotypo fix in comment
Denys Vlasenko [Mon, 26 Sep 2016 06:52:52 +0000 (08:52 +0200)]
typo fix in comment

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: in heredoc code, fix access past the end of allocated memory. Closes 9276
Denys Vlasenko [Sun, 25 Sep 2016 19:24:04 +0000 (21:24 +0200)]
ash: in heredoc code, fix access past the end of allocated memory. Closes 9276

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: fix handling of NULs in $'abc\000def\x00asd'. Closes 9286
Denys Vlasenko [Sun, 25 Sep 2016 18:54:25 +0000 (20:54 +0200)]
ash: fix handling of NULs in $'abc\000def\x00asd'. Closes 9286

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoifupdown: improve help text, add comment about run-parts error msg
Denys Vlasenko [Sun, 25 Sep 2016 00:05:24 +0000 (02:05 +0200)]
ifupdown: improve help text, add comment about run-parts error msg

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agolibbb: handle \S in /etc/issue
Denys Vlasenko [Sat, 24 Sep 2016 21:50:43 +0000 (23:50 +0200)]
libbb: handle \S in /etc/issue

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoAUTHORS: Add myself to AUTHORS
Linus Walleij [Tue, 20 Sep 2016 21:31:56 +0000 (23:31 +0200)]
AUTHORS: Add myself to AUTHORS

Instead of complaining that my authorship of the rewrite of
the mdev to use /sys/dev is totally gone from the git history
I bravely take credit by adding myself to the AUTHORS file
instead, he he.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: use glob() from libc
Denys Vlasenko [Wed, 21 Sep 2016 14:25:58 +0000 (16:25 +0200)]
ash: use glob() from libc

Adapted from dash.
The "homegrown" glob code is retained (ifdef'ed out).
This changes was inspired by bug 9261, which detected out-of bounds use of heap
for 2098 byte long name in the "homegrown" code. This is still not fixed...

function                                             old     new   delta
expandarg                                            960     982     +22
static.syntax_index_table                             26      25      -1
static.spec_symbls                                    27      26      -1
static.metachars                                       4       -      -4
addfname                                              42       -     -42
msort                                                126       -    -126
expmeta                                              528       -    -528
------------------------------------------------------------------------------
(add/remove: 0/4 grow/shrink: 1/2 up/down: 22/-702)          Total: -680 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoexamples/var_service/supplicant_if: new service example
Denys Vlasenko [Tue, 20 Sep 2016 16:09:00 +0000 (18:09 +0200)]
examples/var_service/supplicant_if: new service example

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoifupdown: when flushing addresses with "ip", add label %label%
Denys Vlasenko [Tue, 20 Sep 2016 15:31:11 +0000 (17:31 +0200)]
ifupdown: when flushing addresses with "ip", add label %label%

User report:

or our board we setup eth0:0 on a 10.10.10.x/29 netwrok.

The problem is ip addr flush dev eth0:0 removes all ip addresses from
eth0.  You can see this if you run
ip -stat -stat addr flush dev eth0:0

2: eth0    inet 172.27.105.10/22 brd 172.27.107.255 scope global eth0
       valid_lft forever preferred_lft forever
2: eth0    inet 10.10.10.9/29 scope global eth0:0
       valid_lft forever preferred_lft forever
2: eth0    inet6 fe80::a2f6:fdff:fe18:2b13/64 scope link
       valid_lft forever preferred_lft forever

*** Round 1, deleting 3 addresses ***
*** Flush is complete after 1 round ***

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: fix handling of bashism $'xxx' with high-bit chars. Closes 9236
Denys Vlasenko [Tue, 20 Sep 2016 15:04:09 +0000 (17:04 +0200)]
ash: fix handling of bashism $'xxx' with high-bit chars. Closes 9236

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agohush: document better where bad redirect syntax is detected
Denys Vlasenko [Tue, 20 Sep 2016 14:22:24 +0000 (16:22 +0200)]
hush: document better where bad redirect syntax is detected

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agolibnetlink: fix alignment of netlink messages
Hauke Mehrtens [Fri, 16 Sep 2016 20:40:28 +0000 (22:40 +0200)]
libnetlink: fix alignment of netlink messages

A padding to align a message should not only be added between
different attributes of a netlink message, but also at the end of the
message to pad it to the correct size.

Without this patch the following command does not work and returns an
error code:
ip link add type nlmon

Without this ip from busybox sends this:

sendmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000},
msg_namelen=12, msg_iov=[{iov_base={{len=45, ...},
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\20\0\22\0\t\0\1nlmon"}, iov_len=45}],
msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 45
return value: 2

The normal ip utile from iproute2 sends this:

sendmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000},
msg_namelen=12, msg_iov=[{iov_base={{len=48, ...},
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\20\0\22\0\t\0\1nlmon\0\0\0"}, iov_len=48}],
msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 48
return value: 0

With this patch ip from busybox sends this:

sendmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000},
msg_namelen=12, msg_iov=[{iov_base={{len=48, ...},
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\20\0\22\0\t\0\1nlmon\0\0\0"}, iov_len=48}],
msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 48
return value: 0

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agolibbb: do not use fflush_unlocked, musl does not like fflush_unlocked(NULL)
Denys Vlasenko [Sun, 18 Sep 2016 19:49:30 +0000 (21:49 +0200)]
libbb: do not use fflush_unlocked, musl does not like fflush_unlocked(NULL)

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: exit after subshell error when errexit option is set
Rostislav Skudnov [Fri, 16 Sep 2016 19:04:02 +0000 (19:04 +0000)]
ash: exit after subshell error when errexit option is set

When "set -e" option is on, shell must exit when any command fails,
including compound commands of the form (compound-list) executed in a
subshell. Bash and dash shells have this behaviour.

Also add a corresponding testcase.

Signed-off-by: Rostislav Skudnov <rostislav@tuxera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agofdisk: fix CONFIG_FEATURE_SUN_LABEL=y build
Denys Vlasenko [Sat, 17 Sep 2016 19:05:06 +0000 (21:05 +0200)]
fdisk: fix CONFIG_FEATURE_SUN_LABEL=y build

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agofix "aloc" -> "alloc" typos
Denys Vlasenko [Sat, 17 Sep 2016 18:58:22 +0000 (20:58 +0200)]
fix "aloc" -> "alloc" typos

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: add a FIXME for bug 9246
Denys Vlasenko [Sat, 17 Sep 2016 18:53:47 +0000 (20:53 +0200)]
ash: add a FIXME for bug 9246

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agosvlogd: strip leading '!' from processor lines
Francis Rounds [Wed, 14 Sep 2016 11:53:51 +0000 (11:53 +0000)]
svlogd: strip leading '!' from processor lines

When using svlogd's processor functionality to run arbitrary commands
on log rotation, the line in the config is executed verbatim, i.e. the
exclamation mark is included.

For example, if the config file contains:

    s100
    !cat

then when it's time to rotate the log files after each 100 bytes, sh -c
"!cat" will be run, instead of sh -c "cat" as intended. The result is
svlogd logging

    /bin/bash: !cat: command not found
    svlogd: warning: processor failed, restart: /tmp/svlogd/

over and over again as it keeps attempting to execute the processor and
failing (unless you happen to have a "!cat" binary around :)).

Skipping the exclamation mark when performing the wstrdup() fixes the
issue.

Signed-off-by: Francis Rounds <francis.rounds@4bridgeworks.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agovi: make "g<key>" error message less likely to show garbage
Denys Vlasenko [Thu, 15 Sep 2016 11:53:42 +0000 (13:53 +0200)]
vi: make "g<key>" error message less likely to show garbage

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agolibbb:/send_to_from: do not require that "to" should have the same AF. Closes 9146
Denys Vlasenko [Thu, 15 Sep 2016 11:20:51 +0000 (13:20 +0200)]
libbb:/send_to_from: do not require that "to" should have the same AF. Closes 9146

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agomodutils: support finit_module syscall
Mike Frysinger [Thu, 15 Sep 2016 10:16:33 +0000 (12:16 +0200)]
modutils: support finit_module syscall

On some systems like Chromium OS, loading modules from non-verified
filesystems is denied.  Only finit_module is allowed because an open
fd is passed which can be checked against a verified location.

Change the module loading code to first attempt finit_module and if
that fails for whatever reason, fall back to the existing logic.

On x86_64, this adds ~80 bytes to modutils/modutils.o and ~68 bytes
to modutils/modprobe-small.o.

Signed-off-by: Mike Frysinger <vapier@chromium.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoless: switch off nonblock on kbd_fd before exit
Denys Vlasenko [Tue, 13 Sep 2016 19:05:48 +0000 (21:05 +0200)]
less: switch off nonblock on kbd_fd before exit

This is only necessary if we use stdout fd.

function                                             old     new   delta
less_exit                                             32      51     +19
less_main                                           2540    2543      +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 22/0)               Total: 22 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoless: fall back to using fd #1 for keyboard reading. Closes 9231
Denys Vlasenko [Tue, 13 Sep 2016 18:53:38 +0000 (20:53 +0200)]
less: fall back to using fd #1 for keyboard reading. Closes 9231

function                                             old     new   delta
less_main                                           2535    2540      +5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agomdev: create devices from /sys/dev
Denys Vlasenko [Wed, 7 Sep 2016 12:09:01 +0000 (14:09 +0200)]
mdev: create devices from /sys/dev

Currently some new devices that have a bus but no class will
be missed by mdev coldplug device creation after boot. This
happens because mdev recursively searches /sys/class which will
by definition only find class devices.

Some important devices such as iio and gpiochip does not have
a class. But users will need them.

This switches from using /sys/class as the place to look for
devices to create to using /sys/dev where all char and block
devices are listed.

The subsystem lookup code that provide the G.subsystem
environment variable is changed from using the directory
name of the class device to instead dereference the
"subsystem" symlink for the device, and look at the last
element of the path of the symlink for the subsystem, which
will work with class devices and bus devices alike. (The new
bus-only devices only symlink to the /sys/bus/* hierarchy.)

We delete the legacy kernel v2.6.2x /sys/block device path
code as part of this change. It's too old to be kept alive.

Tested on kernel v4.6-rc2 with a bunch of devices, including
some IIO and gpiochip devices.

With a print inserted before make_device() the log looks
like so:

Create device from "/sys/dev/char/1:1", subsystem "mem"
Create device from "/sys/dev/char/1:2", subsystem "mem"
Create device from "/sys/dev/char/1:3", subsystem "mem"
Create device from "/sys/dev/char/1:5", subsystem "mem"
(...)
Create device from "/sys/dev/block/179:56", subsystem "block"
Create device from "/sys/dev/block/179:64", subsystem "block"

function                                             old     new   delta
mdev_main                                           1388    1346     -42
dirAction                                            134      14    -120
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-162)           Total: -162 bytes

Cc: Isaac Dunham <ibid.ag@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agosendmail: make it possible to pause after connection helper is started
Denys Vlasenko [Wed, 7 Sep 2016 11:16:33 +0000 (13:16 +0200)]
sendmail: make it possible to pause after connection helper is started

If a non-starttls helper is in use, initial 220 response is processed by us,
not by helper.
Some servers consider us to be a spammer if we don't wait for it.

It is not in protocol, but it is a real-life problem.

The workaround in this patch is a magic envvar, $SMTP_ANTISPAM_DELAY:

...
-H 'PROG ARGS' Run connection helper. Examples:
openssl s_client -quiet -tls1 -starttls smtp -connect smtp.gmail.com:25
openssl s_client -quiet -tls1 -connect smtp.gmail.com:465
$SMTP_ANTISPAM_DELAY: seconds to wait after helper connect
...

By using it, people can tweak sendmail behavior even if sendmail invocation
is buried in some scripts.

function                                             old     new   delta
packed_usage                                       30464   30497     +33
sendmail_main                                       1185    1206     +21
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 54/0)               Total: 54 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agovolume_id: Add support for UBIFS
Serj Kalichev [Mon, 29 Aug 2016 15:28:34 +0000 (18:28 +0300)]
volume_id: Add support for UBIFS

Signed-off-by: Serj Kalichev <serj.kalichev@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agolibbb/xwrite: print errno on "short write" errors
Denys Vlasenko [Mon, 5 Sep 2016 13:20:10 +0000 (15:20 +0200)]
libbb/xwrite: print errno on "short write" errors

Lauri Kasanen:
:: Over at TinyCore, we receive a huge number of questions of the type "I
:: got "short write", what does it mean?". Mostly for the rpi port and when
:: using bb wget.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agolibbb/speed_table.c: survive B115200 and B230400 not fitting into 16 bits
Denys Vlasenko [Thu, 1 Sep 2016 09:44:13 +0000 (11:44 +0200)]
libbb/speed_table.c: survive B115200 and B230400 not fitting into 16 bits

Seen on OSX.
While at it, expand baud table with B500000..B4000000

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years ago*: placate some compile warnings on OSX
Denys Vlasenko [Thu, 1 Sep 2016 09:16:22 +0000 (11:16 +0200)]
*: placate some compile warnings on OSX

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agosed: fix "sed n (flushes pattern space, terminates early)" testcase failure
Denys Vlasenko [Wed, 31 Aug 2016 23:59:11 +0000 (01:59 +0200)]
sed: fix "sed n (flushes pattern space, terminates early)" testcase failure

Patch based on work by Dengke Du <dengke.du@windriver.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agowget: treat 201,202,203 as success codes too. Closes 9211
Denys Vlasenko [Wed, 31 Aug 2016 11:28:53 +0000 (13:28 +0200)]
wget: treat 201,202,203 as success codes too. Closes 9211

This matches "standard" wget.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agosha3sum: fix config text (it's no longer only 512-bit)
Denys Vlasenko [Mon, 29 Aug 2016 13:20:15 +0000 (15:20 +0200)]
sha3sum: fix config text (it's no longer only 512-bit)

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agosha3: fix to conform to final SHA3 padding standard, add -a BITS option
Denys Vlasenko [Mon, 29 Aug 2016 12:05:25 +0000 (14:05 +0200)]
sha3: fix to conform to final SHA3 padding standard, add -a BITS option

function                                             old     new   delta
hash_file                                            331     396     +65
md5_sha1_sum_main                                    485     538     +53
packed_usage                                       30423   30464     +41
sha3_begin                                            17      31     +14
sha3_hash                                            101     110      +9
sha3_end                                              41      49      +8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agohexdump: fix numerous bugs in handling of backslashes
Denys Vlasenko [Fri, 26 Aug 2016 18:14:31 +0000 (20:14 +0200)]
hexdump: fix numerous bugs in handling of backslashes

Was:
t=48\\ t=45\\ t=4c\\ t=4c\\ t=4f\\ t=0a\\
Now:
=48=\n =45=\n =4c=\n =4c=\n =4f=\n =0a=\n

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoudhcpc: Unconditionally call deconfig script, not only if lease is active
Peter Korsgaard [Fri, 26 Aug 2016 16:46:34 +0000 (18:46 +0200)]
udhcpc: Unconditionally call deconfig script, not only if lease is active

The udhcpc script may be used to setup fallback configuration (E.G. IPv4LL,
fixed IP address, ..) that also needs to be cleaned up on release (E.G.
when SIGUSR2 is called or on shutdown with -R), so unconditionally call
deconfig.

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agobuild system: always rewrite NUM_APPLETS.h
Denys Vlasenko [Tue, 23 Aug 2016 18:21:36 +0000 (20:21 +0200)]
build system: always rewrite NUM_APPLETS.h

Conditional rewrite can keep NUM_APPLETS.h mtime old,
this causes make to try to regenerate it at every invocation.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agofdisk: tweak some messages
Denys Vlasenko [Tue, 23 Aug 2016 15:18:45 +0000 (17:18 +0200)]
fdisk: tweak some messages

"Total allocated sectors 2021315 greater than the maximum 2020356"

maximum what?

Turns out, that's the CHS size of the disk.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agofdisk: print much less cryptic partition table
Denys Vlasenko [Tue, 23 Aug 2016 14:13:33 +0000 (16:13 +0200)]
fdisk: print much less cryptic partition table

Before:

   Device Boot      Start         End      Blocks  Id System
/dev/sdb1   *           1         998      255471+  6 FAT16

What are "blocks"? What is that "+"?
How big is this partition?
Is start/end shown came from LBA fields or CHS fields?
Why are we torturing the user??

After:

Device  Boot StartCHS    EndCHS        StartLBA     EndLBA    Sectors  Size Id Type
/dev/sdb1 *  0,1,1       996,15,32           32     510974     510943  249M  6 FAT16

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoman: fix parsing of "DEFINE pager xyz". Closes 8976
Denys Vlasenko [Mon, 22 Aug 2016 19:41:05 +0000 (21:41 +0200)]
man: fix parsing of "DEFINE pager xyz". Closes 8976

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoinit: fix for FreeBSD console opening. Closes 9031
Denys Vlasenko [Mon, 22 Aug 2016 18:56:58 +0000 (20:56 +0200)]
init: fix for FreeBSD console opening. Closes 9031

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agounshare: --network should be --net. Closes 9116
Denys Vlasenko [Mon, 22 Aug 2016 18:19:34 +0000 (20:19 +0200)]
unshare: --network should be --net. Closes 9116

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agodocs: Update filenames in keep_data_small.txt
Kang-Che Sung [Wed, 3 Aug 2016 06:14:04 +0000 (14:14 +0800)]
docs: Update filenames in keep_data_small.txt

The filenames in docs/keep_data_small.txt are a little bit outdated.
It's better to change it to the current name.

decompress_unzip.c -> decompress_gunzip.c
(since commit 774bce8e8ba1e424c953e8f13aee8f0778c8a911)
libbb/messages.c -> libbb/ptr_to_globals.c
(since commit 574f2f43948bb21d6e4187936ba5a5afccba25f6)

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agohush: fix "redirects can close script fd" bug
Denys Vlasenko [Mon, 22 Aug 2016 17:54:12 +0000 (19:54 +0200)]
hush: fix "redirects can close script fd" bug

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agobuild system: different fix for include/applet_tables.h/include/NUM_APPLETS.h
Denys Vlasenko [Sun, 21 Aug 2016 20:00:20 +0000 (22:00 +0200)]
build system: different fix for include/applet_tables.h/include/NUM_APPLETS.h

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agowget/ssl_helper: update to wolfssl-3.9.8
Denys Vlasenko [Sun, 21 Aug 2016 01:39:39 +0000 (03:39 +0200)]
wget/ssl_helper: update to wolfssl-3.9.8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agohush: do not leak script fds into NOEXEC children
Denys Vlasenko [Sat, 20 Aug 2016 13:58:34 +0000 (15:58 +0200)]
hush: do not leak script fds into NOEXEC children

We set all opened script fds to CLOEXEC, thus making then go away
after fork+exec.
Unfortunately, CLOFORK does not exist. NOEXEC children will still see those fds open.

For one, "ls" applet is NOEXEC. Therefore running "ls -l /proc/self/fd"
in a script from standalone shell shows this:

lrwx------    1 root     root            64 Aug 20 15:17 0 -> /dev/pts/3
lrwx------    1 root     root            64 Aug 20 15:17 1 -> /dev/pts/3
lrwx------    1 root     root            64 Aug 20 15:17 2 -> /dev/pts/3
lr-x------    1 root     root            64 Aug 20 15:17 3 -> /path/to/top/level/script
lr-x------    1 root     root            64 Aug 20 15:17 4 -> /path/to/sourced/SCRIPT1
...

with as many open fds as there are ". SCRIPTn" nest levels.
Fix it by closing these fds after fork (only for NOEXEC children).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agohush: bit better comments in redirect code. No logic changes
Denys Vlasenko [Sat, 20 Aug 2016 13:16:00 +0000 (15:16 +0200)]
hush: bit better comments in redirect code. No logic changes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agohush: `cmd` and arithmetic also need the fix for FILE rewind
Denys Vlasenko [Fri, 19 Aug 2016 18:15:26 +0000 (20:15 +0200)]
hush: `cmd` and arithmetic also need the fix for FILE rewind

Discovered by running testsuite with a newest glibc

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agohush: fix a bug in FEATURE_SH_STANDALONE=y config. Closes 9186
Denys Vlasenko [Fri, 19 Aug 2016 16:23:56 +0000 (18:23 +0200)]
hush: fix a bug in FEATURE_SH_STANDALONE=y config. Closes 9186

Run this in a "sh SCRIPT":

sha256sum /dev/null
echo END

sha256sum is a NOEXEC applet. It runs in a forked child. Then child exit()s.
By this time, entire script is read, and buffered in a FILE object
from fopen("SCRIPT"). But fgetc() did not consume entire input.
exit() lseeks back by -9 bytes, from <eof> to 'e' in 'echo'.
(this may be libc-specific).
This change of fd position *is shared with the parent*!

Now parent can read more, and it thinks there is another "echo END".
End result: two "echo END"s are run.

Fix this by _exit()ing instead.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agotop: move free(prev_hist) out of signal path
Denys Vlasenko [Fri, 19 Aug 2016 09:07:31 +0000 (11:07 +0200)]
top: move free(prev_hist) out of signal path

It was seen being called recursively on repeated signals,
leading to double free

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoifplugd: if SIOCSIFFLAGS fails with ENODEV, don't die
Denys Vlasenko [Tue, 16 Aug 2016 18:39:52 +0000 (20:39 +0200)]
ifplugd: if SIOCSIFFLAGS fails with ENODEV, don't die

Some user managed to hit a race where iface is gone between SIOCGIFFLAGS
and SIOCSIFFLAGS (!). If SIOCSIFFLAGS fails, treat it the same as failed
SIOCGIFFLAGS

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoless: fix bracket search to match behavior of less 481
Denys Vlasenko [Tue, 16 Aug 2016 13:27:30 +0000 (15:27 +0200)]
less: fix bracket search to match behavior of less 481

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoless: fix SEGV
Denys Vlasenko [Tue, 16 Aug 2016 13:09:40 +0000 (15:09 +0200)]
less: fix SEGV

testcase: echo "" | less, then press ')' key

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>