udhcpc: make hostname sanitization optional. Closes 3979

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
find: add optional support for '-exec ... {} +'

function                                             old     new   delta
do_exec                                                -     309    +309
parse_params                                        1416    1487     +71
find_main                                            342     406     +64
packed_usage                                       29958   30014     +56
func_exec                                            138     127     -11
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/1 up/down: 500/-11)           Total: 489 bytes

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
find: exit code fixes for find -exec

function                                             old     new   delta
func_exec                                            127     100     -27

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
find: use sysconf(_SC_ARG_MAX) to determine the command-line size limit

The find utility uses a hardcoded value of 32 * 1024 as the limit of
the command-line length when calling 'find -exec ... {} +'. This results
in over 4 times more execve() calls than in coreutils' find.

This patch uses the limit defined in system headers.

Based on the patch by  Bartosz Golaszewski <bartekgola@gmail.com>.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
libbb: use a wrapper around sysconf(_SC_CLK_TCK) to save a few bytes

function                                             old     new   delta
bb_sc_clk_tck                                          -      10     +10
timescmd                                             118     113      -5
print_route                                         1763    1758      -5
mpstat_main                                         1288    1283      -5
iostat_main                                         1947    1942      -5
INET_setroute                                        879     871      -8
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/5 up/down: 10/-28)            Total: -18 bytes
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
unit-tests: implement the unit-testing framework

This set of patches adds a simple unit-testing framework to Busybox

unit-tests: add some helper macros for unit-test framework implementation
unit-tests: implement the unit-testing framework
unit-tests: add basic documentation on writing the unit test cases
unit-tests: modify the Makefile 'test' target to run unit-tests too
unit-tests: add two example test cases
unit-tests: modify the existing strrstr test code to use the unit-test framework

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
unlink: new applet

function                                             old     new   delta
unlink_main                                            -      45     +45
packed_usage                                       29667   29686     +19

Signed-off-by: Isaac Dunham <ibid.ag@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
libbb: fix compile failure if both ARG_MAX and _SC_ARG_MAX are defined

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
ftpd: support deprecated XPWD command

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
nanddump: correct rounding to next page (lead to infinite loop)

The rounding to next page formula was wrong:
ex: (len | ~(meminfo->writesize - 1)) + 1;
len=128K
writesize=4K
(len | ~(meminfo->writesize - 1)) + 1 => 4 294 963 201 ?!

correct rounding formula:
((len - 1) | (meminfo->writesize - 1)) + 1 => 128K
len = 130K
((len - 1) | (meminfo->writesize - 1)) + 1 => 132K

modprobe nandsim parts="20,20" badblocks="22,23"

without patch:
nanddump  /dev/mtd1 | wc -c
[...] infinite loop

with the patch:
nanddump /dev/mtd1 | wc -c
327680

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
nanddump: add options --bb=skipbad and padbad

In mtd-utils, the bad block options changed in favor of
--bb=[skipbad|padbad|dumpbad] and omitbad has been removed.

This patch add the --bb=skipbad and padbad methods to busybox' nanddump.
padbad is the current default behaviour.
The difference between skipbad and omitbad is this one:
On a 16K block NAND, if the 1st block of mtd0 is bad, we'll have:
nanddump  -b -l 16384 /dev/mtd0 | wc -c
0
nanddump  --bb=skipbad -l 16384 /dev/mtd0 | wc -c
16384 <- data from 1st good block

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
nanddump: kill -b Omit bad block

since mtd-utils 1.4.7, the omit bad block method has been removed.
(cf commit d8b8f780ec3c916f3990e9227d6bfbb22bf42ef8)

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
nanddump: change default to --bb=skipbad

since mtd-utils 1.4.7, the default behaviour of nanddump is skipbad
(commit 2521d4f1b6b9866a9c89f3c11a4f6a3d763ff1d7)

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
ftpd: optimize writes of LIST results a bit

function                                             old     new   delta
handle_dir_common                                    201     207      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
awk: fix handling of "if ... break ; else ..." - closes 7226

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
ftpd: escape chroot prior to re-executing ls helper

When we merely chdir to saved "real" root fd,
exec("proc/self/exe") works for static executables but not
for dynamic ones (they can't find their interpreter).

With this patch, we also *chroot* to real root.
As a bonus, this gives us proper usernames, timezone conversion
etc.

function                                             old     new   delta
popen_ls                                             203     259     +56
ftpd_main                                           2362    2366      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
ftpd: for LIST, open current directory *in the child*

Last change introduced an open fd leak. This is the fix.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
ftpd: do not use root_fd if we are not in chroot

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
stat: fix printing selinux context and null-dereference

busybox stat tries to always print the selinux context, even if it
is not requested which leads to a segmentation fault due to
dereferencing a null-pointer.

This also changes the format-string used to print the context to
so it actually produces useful output.

Signed-off-by: Michael Gernoth <michael@gernoth.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
lzop: add overflow check

See CVE-2014-4607
http://www.openwall.com/lists/oss-security/2014/06/26/20

function                                             old     new   delta
lzo1x_decompress_safe                               1010    1031     +21

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