Compare commits

...
10 Commits
17 changed files with 142 additions and 98 deletions

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
VERSION = 1
PATCHLEVEL = 4
SUBLEVEL = 0
SUBLEVEL = 2
EXTRAVERSION =
NAME = Unnamed
+2 -2
View File
@@ -38,9 +38,9 @@ ifneq ($(strip $(DO_INSTALL_LIBS)),n)
done
endif
check test: busybox
check test: busybox busybox.links
bindir=$(objtree) srcdir=$(srctree)/testsuite SED="$(SED)" \
$(SHELL) $(srctree)/testsuite/runtest $(if $(KBUILD_VERBOSE:1=),-v)
$(SHELL) $(srctree)/testsuite/runtest $(if $(KBUILD_VERBOSE:0=),-v)
.PHONY: release
release: distclean
+15 -9
View File
@@ -320,7 +320,7 @@ static void parse_config_file(void)
}
#else
#define parse_config_file()
#define parse_config_file() ((void)0)
#endif /* CONFIG_FEATURE_SUID_CONFIG */
#ifdef CONFIG_FEATURE_SUID
@@ -340,20 +340,26 @@ static void check_suid(struct BB_applet *applet)
if (sct) {
mode_t m = sct->m_mode;
if (sct->m_uid == ruid) /* same uid */
if (sct->m_uid == ruid)
/* same uid */
m >>= 6;
else if ((sct->m_gid == rgid) || ingroup(ruid, sct->m_gid)) /* same group / in group */
else if ((sct->m_gid == rgid) || ingroup(ruid, sct->m_gid))
/* same group / in group */
m >>= 3;
if (!(m & S_IXOTH)) /* is x bit not set ? */
bb_error_msg_and_die("you have no permission to run this applet!");
if ((sct->m_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) { /* *both* have to be set for sgid */
xsetgid(sct->m_gid);
} else xsetgid(rgid); /* no sgid -> drop */
if (sct->m_mode & S_ISUID) xsetuid(sct->m_uid);
else xsetuid(ruid); /* no suid -> drop */
if (sct->m_gid != 0) {
/* _both_ have to be set for sgid */
if ((sct->m_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
xsetgid(sct->m_gid);
} else xsetgid(rgid); /* no sgid -> drop */
}
if (sct->m_uid != 0) {
if (sct->m_mode & S_ISUID) xsetuid(sct->m_uid);
else xsetuid(ruid); /* no suid -> drop */
}
} else {
/* default: drop all privileges */
xsetgid(rgid);
+39 -32
View File
@@ -23,10 +23,10 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
#include "busybox.h"
#include "unarchive.h"
#include <fnmatch.h>
#include <getopt.h>
#include "busybox.h"
#include "unarchive.h"
#if ENABLE_FEATURE_TAR_CREATE
@@ -37,6 +37,7 @@
/* POSIX tar Header Block, from POSIX 1003.1-1990 */
#define NAME_SIZE 100
#define NAME_SIZE_STR "100"
typedef struct TarHeader TarHeader;
struct TarHeader { /* byte offset */
char name[NAME_SIZE]; /* 0-99 */
char mode[8]; /* 100-107 */
@@ -56,7 +57,6 @@ struct TarHeader { /* byte offset */
char prefix[155]; /* 345-499 */
char padding[12]; /* 500-512 (pad to exactly the TAR_BLOCK_SIZE) */
};
typedef struct TarHeader TarHeader;
/*
** writeTarFile(), writeFileToTarball(), and writeTarHeader() are
@@ -73,6 +73,7 @@ struct HardLinkInfo {
};
/* Some info to be carried along when creating a new tarball */
typedef struct TarBallInfo TarBallInfo;
struct TarBallInfo {
int tarFd; /* Open-for-write file descriptor
for the tarball */
@@ -85,7 +86,6 @@ struct TarBallInfo {
HardLinkInfo *hlInfoHead; /* Hard Link Tracking Information */
HardLinkInfo *hlInfo; /* Hard Link Info for the current file */
};
typedef struct TarBallInfo TarBallInfo;
/* A nice enum with all the possible tar file content types */
enum TarFileType {
@@ -348,7 +348,7 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
return TRUE;
}
# if ENABLE_FEATURE_TAR_FROM
#if ENABLE_FEATURE_TAR_FROM
static int exclude_file(const llist_t *excluded_files, const char *file)
{
while (excluded_files) {
@@ -371,12 +371,12 @@ static int exclude_file(const llist_t *excluded_files, const char *file)
return 0;
}
# else
#else
#define exclude_file(excluded_files, file) 0
# endif
#endif
static int writeFileToTarball(const char *fileName, struct stat *statbuf,
void *userData, int depth)
void *userData, int depth ATTRIBUTE_UNUSED)
{
struct TarBallInfo *tbInfo = (struct TarBallInfo *) userData;
const char *header_name;
@@ -509,14 +509,14 @@ static int writeTarFile(const int tar_fd, const int verboseFlag,
if (pipe(gzipDataPipe) < 0 || pipe(gzipStatusPipe) < 0)
bb_perror_msg_and_die("pipe");
signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
# if __GNUC__
#if defined(__GNUC__) && __GNUC__
/* Avoid vfork clobbering */
(void) &include;
(void) &errorFlag;
(void) &zip_exec;
# endif
#endif
gzipPid = vfork();
@@ -600,7 +600,7 @@ static int writeTarFile(const int tar_fd, const int verboseFlag,
int writeTarFile(const int tar_fd, const int verboseFlag,
const unsigned long dereferenceFlag, const llist_t *include,
const llist_t *exclude, const int gzip);
#endif /* tar_create */
#endif /* FEATURE_TAR_CREATE */
#if ENABLE_FEATURE_TAR_FROM
static llist_t *append_file_list_to_list(llist_t *list)
@@ -628,7 +628,7 @@ static llist_t *append_file_list_to_list(llist_t *list)
return newlist;
}
#else
#define append_file_list_to_list(x) 0
#define append_file_list_to_list(x) 0
#endif
#if ENABLE_FEATURE_TAR_COMPRESS
@@ -653,7 +653,7 @@ static char get_header_tar_Z(archive_handle_t *archive_handle)
return EXIT_FAILURE;
}
#else
#define get_header_tar_Z 0
#define get_header_tar_Z NULL
#endif
#ifdef CHECK_FOR_CHILD_EXITCODE
@@ -760,7 +760,9 @@ int tar_main(int argc, char **argv)
const char *tar_filename = "-";
unsigned opt;
int verboseFlag = 0;
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
llist_t *excludes = NULL;
#endif
/* Initialise default values */
tar_handle = init_handle();
@@ -773,7 +775,9 @@ int tar_main(int argc, char **argv)
"tt:vv:" // count -t,-v
"?:" // bail out with usage instead of error return
"X::T::" // cumulative lists
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
"\xff::" // cumulative lists for --exclude
#endif
USE_FEATURE_TAR_CREATE("c:") "t:x:" // at least one of these is reqd
USE_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive
SKIP_FEATURE_TAR_CREATE("t--x:x--t"); // mutually exclusive
@@ -788,14 +792,15 @@ int tar_main(int argc, char **argv)
USE_FEATURE_TAR_FROM( "T:X:")
USE_FEATURE_TAR_GZIP( "z" )
USE_FEATURE_TAR_COMPRESS("Z" )
,
&base_dir, // -C dir
&tar_filename, // -f filename
USE_FEATURE_TAR_FROM(&(tar_handle->accept),) // T
USE_FEATURE_TAR_FROM(&(tar_handle->reject),) // X
USE_FEATURE_TAR_FROM(&excludes ,) // --exclude
&verboseFlag, // combined count for -t and -v
&verboseFlag // combined count for -t and -v
, &base_dir // -C dir
, &tar_filename // -f filename
USE_FEATURE_TAR_FROM(, &(tar_handle->accept)) // T
USE_FEATURE_TAR_FROM(, &(tar_handle->reject)) // X
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
, &excludes // --exclude
#endif
, &verboseFlag // combined count for -t and -v
, &verboseFlag // combined count for -t and -v
);
if (verboseFlag) tar_handle->action_header = header_verbose_list;
@@ -828,17 +833,19 @@ int tar_main(int argc, char **argv)
if (opt & OPT_COMPRESS)
get_header_ptr = get_header_tar_Z;
if (ENABLE_FEATURE_TAR_FROM) {
tar_handle->reject = append_file_list_to_list(tar_handle->reject);
/* Append excludes to reject */
while (excludes) {
llist_t *temp = excludes->link;
excludes->link = tar_handle->reject;
tar_handle->reject = excludes;
excludes = temp;
}
tar_handle->accept = append_file_list_to_list(tar_handle->accept);
#if ENABLE_FEATURE_TAR_FROM
tar_handle->reject = append_file_list_to_list(tar_handle->reject);
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
/* Append excludes to reject */
while (excludes) {
llist_t *next = excludes->link;
excludes->link = tar_handle->reject;
tar_handle->reject = excludes;
excludes = next;
}
#endif
tar_handle->accept = append_file_list_to_list(tar_handle->accept);
#endif
/* Check if we are reading from stdin */
if (argv[optind] && *argv[optind] == '-') {
+5 -4
View File
@@ -568,10 +568,11 @@ static int find_param(const char * const name)
NULL
};
int i = index_in_str_array(params, name);
if (i) {
if (!(i == 4 || i == 5))
i |= 0x80;
}
if (i < 0)
return 0;
if (!(i == 4 || i == 5))
i |= 0x80;
return i;
}
+2 -2
View File
@@ -290,7 +290,7 @@ extern int setsockopt_broadcast(int fd);
/* "new" (ipv4+ipv6) API */
typedef struct len_and_sockaddr {
int len;
socklen_t len;
union {
struct sockaddr sa;
struct sockaddr_in sin;
@@ -690,7 +690,7 @@ extern const char bb_msg_standard_input[];
extern const char bb_msg_standard_output[];
extern const char bb_str_default[];
/* NB: (bb_hexdigits_upcase[i] | 0x10) -> lowercase hex digit */
/* NB: (bb_hexdigits_upcase[i] | 0x20) -> lowercase hex digit */
extern const char bb_hexdigits_upcase[];
extern const char bb_path_mtab_file[];
-4
View File
@@ -7,12 +7,8 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
#include <stdio.h>
#include <unistd.h>
#include "libbb.h"
#if defined(__GLIBC__) && __GLIBC__ < 2
int vdprintf(int d, const char *format, va_list ap)
{
+6 -5
View File
@@ -81,13 +81,14 @@ char * xstrndup(const char *s, int n)
t = (char*) s;
while (m) {
if (!*t) break;
m--; t++;
m--;
t++;
}
n = n - m;
n -= m;
t = xmalloc(n + 1);
t[n] = '\0';
return memcpy(t,s,n);
return memcpy(t, s, n);
}
// Die if we can't open a file and return a FILE * to it.
@@ -339,8 +340,8 @@ char *bin2hex(char *p, const char *cp, int count)
while (count) {
unsigned char c = *cp++;
/* put lowercase hex digits */
*p++ = 0x10 | bb_hexdigits_upcase[c >> 4];
*p++ = 0x10 | bb_hexdigits_upcase[c & 0xf];
*p++ = 0x20 | bb_hexdigits_upcase[c >> 4];
*p++ = 0x20 | bb_hexdigits_upcase[c & 0xf];
count--;
}
return p;
+1 -1
View File
@@ -36,7 +36,7 @@ char *xreadlink(const char *path)
char *xmalloc_realpath(const char *path)
{
#ifdef __GLIBC__
#if defined(__GLIBC__) && !defined(__UCLIBC__)
/* glibc provides a non-standard extension */
return realpath(path, NULL);
#else
+1
View File
@@ -299,6 +299,7 @@ config RAIDAUTORUN
config READAHEAD
bool "readahead"
default n
depends on LFS
help
Preload the files listed on the command line into RAM cache so that
subsequent reads on these files will not block on disk I/O.
+3 -2
View File
@@ -33,8 +33,9 @@ int ip_main(int argc, char **argv)
if (ENABLE_FEATURE_IP_LINK && matches(argv[1], "link") == 0) {
ret = do_iplink(argc-2, argv+2);
}
if (ENABLE_FEATURE_IP_TUNNEL &&
(matches(argv[1], "tunnel") == 0 || strcmp(argv[1], "tunl") == 0)) {
if (ENABLE_FEATURE_IP_TUNNEL
&& (matches(argv[1], "tunnel") == 0 || strcmp(argv[1], "tunl") == 0)
) {
ret = do_iptunnel(argc-2, argv+2);
}
if (ENABLE_FEATURE_IP_RULE && matches(argv[1], "rule") == 0) {
+13 -12
View File
@@ -835,9 +835,11 @@ static int iproute_get(int argc, char **argv)
int do_iproute(int argc, char **argv)
{
static const char * const ip_route_commands[] =
{ "add", "append", "change", "chg", "delete", "get",
"list", "show", "prepend", "replace", "test", "flush", 0 };
static const char * const ip_route_commands[] = {
/*0-3*/ "add", "append", "change", "chg",
/*4-7*/ "delete", "get", "list", "show",
/*8..*/ "prepend", "replace", "test", "flush", 0
};
int command_num = 6;
unsigned int flags = 0;
int cmd = RTM_NEWROUTE;
@@ -848,7 +850,7 @@ int do_iproute(int argc, char **argv)
command_num = index_in_substr_array(ip_route_commands, *argv);
}
switch (command_num) {
case 0: /* add*/
case 0: /* add */
flags = NLM_F_CREATE|NLM_F_EXCL;
break;
case 1: /* append */
@@ -859,21 +861,20 @@ int do_iproute(int argc, char **argv)
flags = NLM_F_REPLACE;
break;
case 4: /* delete */
case 5: /* del */
cmd = RTM_DELROUTE;
break;
case 6: /* get */
case 5: /* get */
return iproute_get(argc-1, argv+1);
case 7: /* list */
case 8: /* show */
case 6: /* list */
case 7: /* show */
return iproute_list_or_flush(argc-1, argv+1, 0);
case 9: /* prepend */
case 8: /* prepend */
flags = NLM_F_CREATE;
case 10: /* replace */
case 9: /* replace */
flags = NLM_F_CREATE|NLM_F_REPLACE;
case 11: /* test */
case 10: /* test */
flags = NLM_F_EXCL;
case 12: /* flush */
case 11: /* flush */
return iproute_list_or_flush(argc-1, argv+1, 1);
default:
bb_error_msg_and_die("unknown command %s", *argv);
+3 -2
View File
@@ -2,6 +2,9 @@
#ifndef __LIBNETLINK_H__
#define __LIBNETLINK_H__ 1
#include <linux/types.h>
/* We need linux/types.h because older kernels use __u32 etc
* in linux/[rt]netlink.h. 2.6.19 seems to be ok, though */
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
@@ -37,6 +40,4 @@ extern int rta_addattr_l(struct rtattr *rta, int maxlen, int type, void *data, i
extern int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len);
#endif /* __LIBNETLINK_H__ */
+22 -19
View File
@@ -132,7 +132,7 @@ static int tftp(
#if ENABLE_FEATURE_TFTP_GET && ENABLE_FEATURE_TFTP_PUT
const int cmd,
#endif
const len_and_sockaddr *peer_lsa,
len_and_sockaddr *peer_lsa,
const char *remotefile, const int localfd,
unsigned port, int tftp_bufsize)
{
@@ -149,6 +149,9 @@ static int tftp(
USE_FEATURE_TFTP_BLOCKSIZE(int want_option_ack = 0;)
unsigned org_port;
len_and_sockaddr *const from = alloca(offsetof(len_and_sockaddr, sa) + peer_lsa->len);
/* Can't use RESERVE_CONFIG_BUFFER here since the allocation
* size varies meaning BUFFERS_GO_ON_STACK would fail */
/* We must keep the transmit and receive buffers seperate */
@@ -156,7 +159,7 @@ static int tftp(
char *xbuf = xmalloc(tftp_bufsize += 4);
char *rbuf = xmalloc(tftp_bufsize);
port = htons(port);
port = org_port = htons(port);
socketfd = xsocket(peer_lsa->sa.sa_family, SOCK_DGRAM, 0);
@@ -167,10 +170,10 @@ static int tftp(
}
while (1) {
cp = xbuf;
/* first create the opcode part */
/* (this 16bit store is aligned) */
*((uint16_t*)cp) = htons(opcode);
cp += 2;
@@ -222,6 +225,7 @@ static int tftp(
/* add ack and data */
if (CMD_GET(cmd) ? (opcode == TFTP_ACK) : (opcode == TFTP_DATA)) {
/* TODO: unaligned access! */
*((uint16_t*)cp) = htons(block_nr);
cp += 2;
block_nr++;
@@ -273,28 +277,26 @@ static int tftp(
FD_SET(socketfd, &rfds);
switch (select(socketfd + 1, &rfds, NULL, NULL, &tv)) {
struct sockaddr *from;
socklen_t fromlen;
unsigned from_port;
case 1:
fromlen = peer_lsa->len;
from = alloca(fromlen);
memset(from, 0, fromlen);
from->len = peer_lsa->len;
memset(&from->sa, 0, peer_lsa->len);
len = recvfrom(socketfd, rbuf, tftp_bufsize, 0,
from, &fromlen);
&from->sa, &from->len);
if (len < 0) {
bb_perror_msg("recvfrom");
break;
}
#if ENABLE_FEATURE_IPV6
if (from->sa_family == AF_INET6)
if (((struct sockaddr_in6*)from)->sin6_port != port)
goto recv_again;
#endif
if (from->sa_family == AF_INET)
if (((struct sockaddr_in*)from)->sin_port != port)
goto recv_again;
from_port = get_nport(from);
if (port == org_port) {
/* Our first query went to port 69
* but reply will come from different one.
* Remember and use this new port */
port = from_port;
set_nport(peer_lsa, from_port);
}
if (port != from_port)
goto recv_again;
timeout = 0;
break;
case 0:
@@ -317,6 +319,7 @@ static int tftp(
}
/* process received packet */
/* (both accesses seems to be aligned) */
opcode = ntohs( ((uint16_t*)rbuf)[0] );
tmp = ntohs( ((uint16_t*)rbuf)[1] );
+3 -1
View File
@@ -543,7 +543,9 @@ static void parse_url(char *src_url, struct host_info *h)
p = strchr(h->host, '?'); if (!sp || (p && sp > p)) sp = p;
p = strchr(h->host, '#'); if (!sp || (p && sp > p)) sp = p;
if (!sp) {
h->path = "";
/* must be writable because of bb_get_last_path_component() */
static char nullstr[] = "";
h->path = nullstr;
} else if (*sp == '/') {
*sp = '\0';
h->path = sp + 1;
+2 -2
View File
@@ -569,7 +569,7 @@ int syslogd_main(int argc, char **argv)
//if (option_mask32 & OPT_locallog) // -L
#endif
#if ENABLE_FEATURE_IPC_SYSLOG
if ((option_mask32 & OPT_circularlog) && opt_C) // -C
if (opt_C) // -Cn
shm_size = xatoul_range(opt_C, 4, INT_MAX/1024) * 1024;
#endif
@@ -588,7 +588,7 @@ int syslogd_main(int argc, char **argv)
#ifdef BB_NOMMU
vfork_daemon_rexec(0, 1, argc, argv, "-n");
#else
xdaemon(0, 1);
bb_daemonize();
#endif
}
umask(0);
+24
View File
@@ -0,0 +1,24 @@
#!/bin/sh
# unit test for sum.
# Copyright 2007 by Bernhard Fischer
# Licensed under GPL v2 or later, see file LICENSE for details.
# AUDIT: Unit tests for sum
. testing.sh
# testing "test name" "options" "expected result" "file input" "stdin"
# file input will be file called "input"
# test can create a file "actual" instead of writing to stdout
testing "sum -r file doesn't print file's name" \
"sum -r $0 | grep -c $0 && echo wrongly_printed_filename || echo yes" \
"0\nyes\n" "" ""
testing "sum -r file file does print both names" \
"sum -r $0 $0 | grep -c $0 && echo yes || echo wrongly_omitted_filename" \
"2\nyes\n" "" ""
testing "sum -s file does print file's name" \
"sum -s $0 | grep -c $0 && echo yes || echo wrongly_omitted_filename" \
"1\nyes\n" "" ""
exit $FAILCOUNT