Compare commits
15
Commits
1_28_1
...
1_28_stable
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
509f987e16 | ||
|
|
d591256a5c | ||
|
|
adb69765e5 | ||
|
|
70baf859a6 | ||
|
|
2c5ceb6065 | ||
|
|
e04a38c0c9 | ||
|
|
78ee8fc3e4 | ||
|
|
08cbe510dd | ||
|
|
af874cc63e | ||
|
|
b1aa377a3f | ||
|
|
2afdcc77cc | ||
|
|
c74f1d2cb4 | ||
|
|
62b7083c13 | ||
|
|
39bf15ba3e | ||
|
|
37277a23fe |
No files matched your search
@@ -1,6 +1,6 @@
|
||||
VERSION = 1
|
||||
PATCHLEVEL = 28
|
||||
SUBLEVEL = 1
|
||||
SUBLEVEL = 4
|
||||
EXTRAVERSION =
|
||||
NAME = Unnamed
|
||||
|
||||
|
||||
@@ -508,6 +508,8 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
create_symlinks_from_list(archive_handle->symlink_placeholders);
|
||||
|
||||
if (archive_handle->cpio__blocks != (off_t)-1
|
||||
&& !(opt & OPT_QUIET)
|
||||
) {
|
||||
|
||||
@@ -107,9 +107,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
}
|
||||
}
|
||||
else if (existing_sb.st_mtime >= file_header->mtime) {
|
||||
if (!(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
|
||||
&& !S_ISDIR(file_header->mode)
|
||||
) {
|
||||
if (!S_ISDIR(file_header->mode)) {
|
||||
bb_error_msg("%s not created: newer or "
|
||||
"same age file exists", dst_name);
|
||||
}
|
||||
@@ -125,7 +123,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
/* Handle hard links separately */
|
||||
if (hard_link) {
|
||||
res = link(hard_link, dst_name);
|
||||
if (res != 0 && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
if (res != 0) {
|
||||
/* shared message */
|
||||
bb_perror_msg("can't create %slink '%s' to '%s'",
|
||||
"hard", dst_name, hard_link
|
||||
@@ -165,10 +163,9 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
}
|
||||
case S_IFDIR:
|
||||
res = mkdir(dst_name, file_header->mode);
|
||||
if ((res == -1)
|
||||
if ((res != 0)
|
||||
&& (errno != EISDIR) /* btw, Linux doesn't return this */
|
||||
&& (errno != EEXIST)
|
||||
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
|
||||
) {
|
||||
bb_perror_msg("can't make dir %s", dst_name);
|
||||
}
|
||||
@@ -198,27 +195,16 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
*
|
||||
* Untarring bug.tar would otherwise place evil.py in '/tmp'.
|
||||
*/
|
||||
if (!unsafe_symlink_target(file_header->link_target)) {
|
||||
res = symlink(file_header->link_target, dst_name);
|
||||
if (res != 0
|
||||
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
|
||||
) {
|
||||
/* shared message */
|
||||
bb_perror_msg("can't create %slink '%s' to '%s'",
|
||||
"sym",
|
||||
dst_name, file_header->link_target
|
||||
);
|
||||
}
|
||||
}
|
||||
create_or_remember_symlink(&archive_handle->symlink_placeholders,
|
||||
file_header->link_target,
|
||||
dst_name);
|
||||
break;
|
||||
case S_IFSOCK:
|
||||
case S_IFBLK:
|
||||
case S_IFCHR:
|
||||
case S_IFIFO:
|
||||
res = mknod(dst_name, file_header->mode, file_header->device);
|
||||
if ((res == -1)
|
||||
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
|
||||
) {
|
||||
if (res != 0) {
|
||||
bb_perror_msg("can't create node %s", dst_name);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -127,8 +127,10 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
|
||||
archive_handle->action_header(typed);
|
||||
#if ENABLE_DPKG || ENABLE_DPKG_DEB
|
||||
if (archive_handle->dpkg__sub_archive) {
|
||||
while (archive_handle->dpkg__action_data_subarchive(archive_handle->dpkg__sub_archive) == EXIT_SUCCESS)
|
||||
struct archive_handle_t *sa = archive_handle->dpkg__sub_archive;
|
||||
while (archive_handle->dpkg__action_data_subarchive(sa) == EXIT_SUCCESS)
|
||||
continue;
|
||||
create_symlinks_from_list(sa->symlink_placeholders);
|
||||
} else
|
||||
#endif
|
||||
archive_handle->action_data(archive_handle);
|
||||
|
||||
@@ -5,44 +5,37 @@
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
int FAST_FUNC unsafe_symlink_target(const char *target)
|
||||
void FAST_FUNC create_or_remember_symlink(llist_t **symlink_placeholders,
|
||||
const char *target,
|
||||
const char *linkname)
|
||||
{
|
||||
const char *dot;
|
||||
|
||||
if (target[0] == '/') {
|
||||
const char *var;
|
||||
unsafe:
|
||||
var = getenv("EXTRACT_UNSAFE_SYMLINKS");
|
||||
if (var) {
|
||||
if (LONE_CHAR(var, '1'))
|
||||
return 0; /* pretend it's safe */
|
||||
return 1; /* "UNSAFE!" */
|
||||
}
|
||||
bb_error_msg("skipping unsafe symlink to '%s' in archive,"
|
||||
" set %s=1 to extract",
|
||||
target,
|
||||
"EXTRACT_UNSAFE_SYMLINKS"
|
||||
if (target[0] == '/' || strstr(target, "..")) {
|
||||
llist_add_to(symlink_placeholders,
|
||||
xasprintf("%s%c%s", linkname, '\0', target)
|
||||
);
|
||||
/* Prevent further messages */
|
||||
setenv("EXTRACT_UNSAFE_SYMLINKS", "0", 0);
|
||||
return 1; /* "UNSAFE!" */
|
||||
return;
|
||||
}
|
||||
if (symlink(target, linkname) != 0) {
|
||||
/* shared message */
|
||||
bb_perror_msg_and_die("can't create %slink '%s' to '%s'",
|
||||
"sym", linkname, target
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
dot = target;
|
||||
for (;;) {
|
||||
dot = strchr(dot, '.');
|
||||
if (!dot)
|
||||
return 0; /* safe target */
|
||||
void FAST_FUNC create_symlinks_from_list(llist_t *list)
|
||||
{
|
||||
while (list) {
|
||||
char *target;
|
||||
|
||||
/* Is it a path component starting with ".."? */
|
||||
if ((dot[1] == '.')
|
||||
&& (dot == target || dot[-1] == '/')
|
||||
/* Is it exactly ".."? */
|
||||
&& (dot[2] == '/' || dot[2] == '\0')
|
||||
) {
|
||||
goto unsafe;
|
||||
target = list->data + strlen(list->data) + 1;
|
||||
if (symlink(target, list->data)) {
|
||||
/* shared message */
|
||||
bb_error_msg_and_die("can't create %slink '%s' to '%s'",
|
||||
"sym",
|
||||
list->data, target
|
||||
);
|
||||
}
|
||||
/* NB: it can even be trailing ".", should only add 1 */
|
||||
dot += 1;
|
||||
list = list->link;
|
||||
}
|
||||
}
|
||||
@@ -1244,6 +1244,8 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
while (get_header_tar(tar_handle) == EXIT_SUCCESS)
|
||||
bb_got_signal = EXIT_SUCCESS; /* saw at least one header, good */
|
||||
|
||||
create_symlinks_from_list(tar_handle->symlink_placeholders);
|
||||
|
||||
/* Check that every file that should have been extracted was */
|
||||
while (tar_handle->accept) {
|
||||
if (!find_list_entry(tar_handle->reject, tar_handle->accept->data)
|
||||
|
||||
+14
-11
@@ -343,7 +343,9 @@ static void unzip_create_leading_dirs(const char *fn)
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_UNZIP_CDF
|
||||
static void unzip_extract_symlink(zip_header_t *zip, const char *dst_fn)
|
||||
static void unzip_extract_symlink(llist_t **symlink_placeholders,
|
||||
zip_header_t *zip,
|
||||
const char *dst_fn)
|
||||
{
|
||||
char *target;
|
||||
|
||||
@@ -368,15 +370,9 @@ static void unzip_extract_symlink(zip_header_t *zip, const char *dst_fn)
|
||||
target[xstate.mem_output_size] = '\0';
|
||||
#endif
|
||||
}
|
||||
if (!unsafe_symlink_target(target)) {
|
||||
//TODO: libbb candidate
|
||||
if (symlink(target, dst_fn)) {
|
||||
/* shared message */
|
||||
bb_perror_msg_and_die("can't create %slink '%s' to '%s'",
|
||||
"sym", dst_fn, target
|
||||
);
|
||||
}
|
||||
}
|
||||
create_or_remember_symlink(symlink_placeholders,
|
||||
target,
|
||||
dst_fn);
|
||||
free(target);
|
||||
}
|
||||
#endif
|
||||
@@ -488,6 +484,9 @@ int unzip_main(int argc, char **argv)
|
||||
llist_t *zaccept = NULL;
|
||||
llist_t *zreject = NULL;
|
||||
char *base_dir = NULL;
|
||||
#if ENABLE_FEATURE_UNZIP_CDF
|
||||
llist_t *symlink_placeholders = NULL;
|
||||
#endif
|
||||
int i;
|
||||
char key_buf[80]; /* must match size used by my_fgets80 */
|
||||
|
||||
@@ -952,7 +951,7 @@ int unzip_main(int argc, char **argv)
|
||||
#if ENABLE_FEATURE_UNZIP_CDF
|
||||
if (S_ISLNK(file_mode)) {
|
||||
if (dst_fd != STDOUT_FILENO) /* not -p? */
|
||||
unzip_extract_symlink(&zip, dst_fn);
|
||||
unzip_extract_symlink(&symlink_placeholders, &zip, dst_fn);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
@@ -988,6 +987,10 @@ int unzip_main(int argc, char **argv)
|
||||
total_entries++;
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_UNZIP_CDF
|
||||
create_symlinks_from_list(symlink_placeholders);
|
||||
#endif
|
||||
|
||||
if ((opts & OPT_l) && quiet <= 1) {
|
||||
if (!verbose) {
|
||||
// " Length Date Time Name\n"
|
||||
|
||||
@@ -11,13 +11,13 @@ echo "* Upping iface $if"
|
||||
ip link set dev $if up
|
||||
|
||||
>>udhcpd.leases
|
||||
sed 's/^interface.*$/interface '"$if/" -i udhcpc.conf
|
||||
sed 's/^interface.*$/interface '"$if/" -i udhcpd.conf
|
||||
|
||||
echo "* Starting udhcpd"
|
||||
exec \
|
||||
env - PATH="$PATH" \
|
||||
softlimit \
|
||||
setuidgid root \
|
||||
udhcpd -f -vv udhcpc.conf
|
||||
udhcpd -f -vv udhcpd.conf
|
||||
|
||||
exit $?
|
||||
File renamed without changes.
+1
-1
@@ -352,7 +352,7 @@ static int grep_file(FILE *file)
|
||||
goto opt_f_not_found;
|
||||
} else
|
||||
if (option_mask32 & OPT_w) {
|
||||
char c = (match != str) ? match[-1] : ' ';
|
||||
char c = (match != line) ? match[-1] : ' ';
|
||||
if (!isalnum(c) && c != '_') {
|
||||
c = match[strlen(gl->pattern)];
|
||||
if (!c || (!isalnum(c) && c != '_'))
|
||||
|
||||
+14
-9
@@ -64,6 +64,9 @@ typedef struct archive_handle_t {
|
||||
/* Currently processed file's header */
|
||||
file_header_t *file_header;
|
||||
|
||||
/* List of symlink placeholders */
|
||||
llist_t *symlink_placeholders;
|
||||
|
||||
/* Process the header component, e.g. tar -t */
|
||||
void FAST_FUNC (*action_header)(const file_header_t *);
|
||||
|
||||
@@ -119,15 +122,14 @@ typedef struct archive_handle_t {
|
||||
#define ARCHIVE_RESTORE_DATE (1 << 0)
|
||||
#define ARCHIVE_CREATE_LEADING_DIRS (1 << 1)
|
||||
#define ARCHIVE_UNLINK_OLD (1 << 2)
|
||||
#define ARCHIVE_EXTRACT_QUIET (1 << 3)
|
||||
#define ARCHIVE_EXTRACT_NEWER (1 << 4)
|
||||
#define ARCHIVE_DONT_RESTORE_OWNER (1 << 5)
|
||||
#define ARCHIVE_DONT_RESTORE_PERM (1 << 6)
|
||||
#define ARCHIVE_NUMERIC_OWNER (1 << 7)
|
||||
#define ARCHIVE_O_TRUNC (1 << 8)
|
||||
#define ARCHIVE_REMEMBER_NAMES (1 << 9)
|
||||
#define ARCHIVE_EXTRACT_NEWER (1 << 3)
|
||||
#define ARCHIVE_DONT_RESTORE_OWNER (1 << 4)
|
||||
#define ARCHIVE_DONT_RESTORE_PERM (1 << 5)
|
||||
#define ARCHIVE_NUMERIC_OWNER (1 << 6)
|
||||
#define ARCHIVE_O_TRUNC (1 << 7)
|
||||
#define ARCHIVE_REMEMBER_NAMES (1 << 8)
|
||||
#if ENABLE_RPM
|
||||
#define ARCHIVE_REPLACE_VIA_RENAME (1 << 10)
|
||||
#define ARCHIVE_REPLACE_VIA_RENAME (1 << 9)
|
||||
#endif
|
||||
|
||||
|
||||
@@ -197,7 +199,10 @@ void seek_by_jump(int fd, off_t amount) FAST_FUNC;
|
||||
void seek_by_read(int fd, off_t amount) FAST_FUNC;
|
||||
|
||||
const char *strip_unsafe_prefix(const char *str) FAST_FUNC;
|
||||
int unsafe_symlink_target(const char *target) FAST_FUNC;
|
||||
void create_or_remember_symlink(llist_t **symlink_placeholders,
|
||||
const char *target,
|
||||
const char *linkname) FAST_FUNC;
|
||||
void create_symlinks_from_list(llist_t *list) FAST_FUNC;
|
||||
|
||||
void data_align(archive_handle_t *archive_handle, unsigned boundary) FAST_FUNC;
|
||||
const llist_t *find_list_entry(const llist_t *list, const char *filename) FAST_FUNC;
|
||||
|
||||
@@ -30,7 +30,7 @@ int ssl_client_main(int argc UNUSED_PARAM, char **argv)
|
||||
// INIT_G();
|
||||
|
||||
tls = new_tls_state();
|
||||
opt = getopt32(argv, "s:#r:#n:", &tls->ofd, &tls->ifd, &sni);
|
||||
opt = getopt32(argv, "s:+r:+n:", &tls->ofd, &tls->ifd, &sni);
|
||||
if (!(opt & 2)) {
|
||||
/* -r N defaults to -s N */
|
||||
tls->ifd = tls->ofd;
|
||||
|
||||
+8
-3
@@ -269,17 +269,22 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
tcp = (applet_name[0] == 't');
|
||||
|
||||
/* "+": stop on first non-option */
|
||||
#ifdef SSLSVD
|
||||
opts = getopt32(argv, "^+"
|
||||
"c:+C:i:x:u:l:Eb:+hpt:vU:/:Z:K:" /* -c NUM, -b NUM */
|
||||
"\0"
|
||||
/* 3+ args, -i at most once, -p implies -h, -v is a counter */
|
||||
"\0" "-3:i--i:ph:vv",
|
||||
"-3:i--i:ph:vv",
|
||||
&cmax, &str_C, &instructs, &instructs, &user, &preset_local_hostname,
|
||||
&backlog, &str_t, &ssluser, &root, &cert, &key, &verbose
|
||||
);
|
||||
#else
|
||||
/* "+": stop on first non-option */
|
||||
opts = getopt32(argv, "+c:+C:i:x:u:l:Eb:hpt:v",
|
||||
opts = getopt32(argv, "^+"
|
||||
"c:+C:i:x:u:l:Eb:+hpt:v" /* -c NUM, -b NUM */
|
||||
"\0"
|
||||
/* 3+ args, -i at most once, -p implies -h, -v is a counter */
|
||||
"-3:i--i:ph:vv",
|
||||
&cmax, &str_C, &instructs, &instructs, &user, &preset_local_hostname,
|
||||
&backlog, &str_t, &verbose
|
||||
);
|
||||
|
||||
@@ -314,7 +314,7 @@ int udhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt,
|
||||
|
||||
void udhcp_sp_setup(void) FAST_FUNC;
|
||||
void udhcp_sp_fd_set(struct pollfd *pfds, int extra_fd) FAST_FUNC;
|
||||
int udhcp_sp_read(struct pollfd *pfds) FAST_FUNC;
|
||||
int udhcp_sp_read(void) FAST_FUNC;
|
||||
|
||||
int udhcp_read_interface(const char *interface, int *ifindex, uint32_t *nip, uint8_t *mac) FAST_FUNC;
|
||||
|
||||
|
||||
@@ -1378,13 +1378,12 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* yah, I know, *you* say it would never happen */
|
||||
timeout = INT_MAX;
|
||||
continue; /* back to main loop */
|
||||
} /* if select timed out */
|
||||
} /* if poll timed out */
|
||||
|
||||
/* select() didn't timeout, something happened */
|
||||
/* poll() didn't timeout, something happened */
|
||||
|
||||
/* Is it a signal? */
|
||||
/* note: udhcp_sp_read checks poll result before reading */
|
||||
switch (udhcp_sp_read(pfds)) {
|
||||
switch (udhcp_sp_read()) {
|
||||
case SIGUSR1:
|
||||
client_config.first_secs = 0; /* make secs field count from 0 */
|
||||
already_waited_sec = 0;
|
||||
@@ -1419,7 +1418,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
/* Is it a packet? */
|
||||
if (listen_mode == LISTEN_NONE || !pfds[1].revents)
|
||||
if (!pfds[1].revents)
|
||||
continue; /* no */
|
||||
|
||||
{
|
||||
|
||||
@@ -1576,13 +1576,12 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* yah, I know, *you* say it would never happen */
|
||||
timeout = INT_MAX;
|
||||
continue; /* back to main loop */
|
||||
} /* if select timed out */
|
||||
} /* if poll timed out */
|
||||
|
||||
/* select() didn't timeout, something happened */
|
||||
/* poll() didn't timeout, something happened */
|
||||
|
||||
/* Is it a signal? */
|
||||
/* note: udhcp_sp_read checks poll result before reading */
|
||||
switch (udhcp_sp_read(pfds)) {
|
||||
switch (udhcp_sp_read()) {
|
||||
case SIGUSR1:
|
||||
client_config.first_secs = 0; /* make secs field count from 0 */
|
||||
already_waited_sec = 0;
|
||||
@@ -1617,7 +1616,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
/* Is it a packet? */
|
||||
if (listen_mode == LISTEN_NONE || !pfds[1].revents)
|
||||
if (!pfds[1].revents)
|
||||
continue; /* no */
|
||||
|
||||
{
|
||||
|
||||
+34
-17
@@ -853,6 +853,9 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* Would rather not do read_config before daemonization -
|
||||
* otherwise NOMMU machines will parse config twice */
|
||||
read_config(argv[0] ? argv[0] : DHCPD_CONF_FILE);
|
||||
/* prevent poll timeout overflow */
|
||||
if (server_config.auto_time > INT_MAX / 1000)
|
||||
server_config.auto_time = INT_MAX / 1000;
|
||||
|
||||
/* Make sure fd 0,1,2 are open */
|
||||
bb_sanitize_stdio();
|
||||
@@ -914,21 +917,31 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
udhcp_sp_fd_set(pfds, server_socket);
|
||||
tv = timeout_end - monotonic_sec();
|
||||
retval = 0;
|
||||
if (!server_config.auto_time || tv > 0) {
|
||||
retval = poll(pfds, 2, server_config.auto_time ? tv * 1000 : -1);
|
||||
}
|
||||
if (retval == 0) {
|
||||
write_leases();
|
||||
goto continue_with_autotime;
|
||||
}
|
||||
if (retval < 0 && errno != EINTR) {
|
||||
log1("error on select");
|
||||
continue;
|
||||
|
||||
new_tv:
|
||||
tv = -1;
|
||||
if (server_config.auto_time) {
|
||||
tv = timeout_end - monotonic_sec();
|
||||
if (tv <= 0) {
|
||||
write_leases:
|
||||
write_leases();
|
||||
goto continue_with_autotime;
|
||||
}
|
||||
tv *= 1000;
|
||||
}
|
||||
|
||||
switch (udhcp_sp_read(pfds)) {
|
||||
/* Block here waiting for either signal or packet */
|
||||
retval = poll(pfds, 2, tv);
|
||||
if (retval <= 0) {
|
||||
if (retval == 0)
|
||||
goto write_leases;
|
||||
if (errno == EINTR)
|
||||
goto new_tv;
|
||||
/* < 0 and not EINTR: should not happen */
|
||||
bb_perror_msg_and_die("poll");
|
||||
}
|
||||
|
||||
if (pfds[0].revents) switch (udhcp_sp_read()) {
|
||||
case SIGUSR1:
|
||||
bb_error_msg("received %s", "SIGUSR1");
|
||||
write_leases();
|
||||
@@ -938,12 +951,16 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
|
||||
bb_error_msg("received %s", "SIGTERM");
|
||||
write_leases();
|
||||
goto ret0;
|
||||
case 0: /* no signal: read a packet */
|
||||
break;
|
||||
default: /* signal or error (probably EINTR): back to select */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Is it a packet? */
|
||||
if (!pfds[1].revents)
|
||||
continue; /* no */
|
||||
|
||||
/* Note: we do not block here, we block on poll() instead.
|
||||
* Blocking here would prevent SIGTERM from working:
|
||||
* socket read inside this call is restarted on caught signals.
|
||||
*/
|
||||
bytes = udhcp_recv_kernel_packet(&packet, server_socket);
|
||||
if (bytes < 0) {
|
||||
/* bytes can also be -2 ("bad packet data") */
|
||||
|
||||
@@ -40,6 +40,7 @@ void FAST_FUNC udhcp_sp_setup(void)
|
||||
xpiped_pair(signal_pipe);
|
||||
close_on_exec_on(signal_pipe.rd);
|
||||
close_on_exec_on(signal_pipe.wr);
|
||||
ndelay_on(signal_pipe.rd);
|
||||
ndelay_on(signal_pipe.wr);
|
||||
bb_signals(0
|
||||
+ (1 << SIGUSR1)
|
||||
@@ -61,20 +62,20 @@ void FAST_FUNC udhcp_sp_fd_set(struct pollfd pfds[2], int extra_fd)
|
||||
pfds[1].fd = extra_fd;
|
||||
pfds[1].events = POLLIN;
|
||||
}
|
||||
/* this simplifies "is extra_fd ready?" tests elsewhere: */
|
||||
pfds[1].revents = 0;
|
||||
}
|
||||
|
||||
/* Read a signal from the signal pipe. Returns 0 if there is
|
||||
* no signal, -1 on error (and sets errno appropriately), and
|
||||
* your signal on success */
|
||||
int FAST_FUNC udhcp_sp_read(struct pollfd pfds[2])
|
||||
int FAST_FUNC udhcp_sp_read(void)
|
||||
{
|
||||
unsigned char sig;
|
||||
|
||||
if (!pfds[0].revents)
|
||||
return 0;
|
||||
|
||||
/* Can't block here, fd is in nonblocking mode */
|
||||
if (safe_read(signal_pipe.rd, &sig, 1) != 1)
|
||||
return -1;
|
||||
return 0;
|
||||
|
||||
return sig;
|
||||
}
|
||||
+14
-8
@@ -239,6 +239,9 @@ typedef long arith_t;
|
||||
# define IF_NOT_FEATURE_SH_STANDALONE(...) __VA_ARGS__
|
||||
#endif
|
||||
|
||||
#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
|
||||
@@ -5392,12 +5395,15 @@ dup2_or_raise(int from, int to)
|
||||
return newfd;
|
||||
}
|
||||
static int
|
||||
fcntl_F_DUPFD(int fd, int avoid_fd)
|
||||
dup_CLOEXEC(int fd, int avoid_fd)
|
||||
{
|
||||
int newfd;
|
||||
repeat:
|
||||
newfd = fcntl(fd, F_DUPFD, avoid_fd + 1);
|
||||
if (newfd < 0) {
|
||||
newfd = fcntl(fd, F_DUPFD_CLOEXEC, avoid_fd + 1);
|
||||
if (newfd >= 0) {
|
||||
if (F_DUPFD_CLOEXEC == F_DUPFD) /* if old libc (w/o F_DUPFD_CLOEXEC) */
|
||||
fcntl(newfd, F_SETFD, FD_CLOEXEC);
|
||||
} else { /* newfd < 0 */
|
||||
if (errno == EBUSY)
|
||||
goto repeat;
|
||||
if (errno == EINTR)
|
||||
@@ -5513,7 +5519,7 @@ save_fd_on_redirect(int fd, int avoid_fd, struct redirtab *sq)
|
||||
for (i = 0; sq->two_fd[i].orig_fd != EMPTY; i++) {
|
||||
/* If we collide with an already moved fd... */
|
||||
if (fd == sq->two_fd[i].moved_to) {
|
||||
new_fd = fcntl_F_DUPFD(fd, avoid_fd);
|
||||
new_fd = dup_CLOEXEC(fd, avoid_fd);
|
||||
sq->two_fd[i].moved_to = new_fd;
|
||||
TRACE(("redirect_fd %d: already busy, moving to %d\n", fd, new_fd));
|
||||
if (new_fd < 0) /* what? */
|
||||
@@ -5528,7 +5534,7 @@ save_fd_on_redirect(int fd, int avoid_fd, struct redirtab *sq)
|
||||
}
|
||||
|
||||
/* If this fd is open, we move and remember it; if it's closed, new_fd = CLOSED (-1) */
|
||||
new_fd = fcntl_F_DUPFD(fd, avoid_fd);
|
||||
new_fd = dup_CLOEXEC(fd, avoid_fd);
|
||||
TRACE(("redirect_fd %d: previous fd is moved to %d (-1 if it was closed)\n", fd, new_fd));
|
||||
if (new_fd < 0) {
|
||||
if (errno != EBADF)
|
||||
@@ -7312,13 +7318,13 @@ hasmeta(const char *p)
|
||||
p = strpbrk(p, chars);
|
||||
if (!p)
|
||||
break;
|
||||
switch ((unsigned char) *p) {
|
||||
switch ((unsigned char)*p) {
|
||||
case CTLQUOTEMARK:
|
||||
for (;;) {
|
||||
p++;
|
||||
if (*p == CTLQUOTEMARK)
|
||||
if ((unsigned char)*p == CTLQUOTEMARK)
|
||||
break;
|
||||
if (*p == CTLESC)
|
||||
if ((unsigned char)*p == CTLESC)
|
||||
p++;
|
||||
if (*p == '\0') /* huh? */
|
||||
return 0;
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
/proc/self/fd
|
||||
/proc/self/fd/0
|
||||
/proc/self/fd/1
|
||||
/proc/self/fd/2
|
||||
/proc/self/fd/3
|
||||
@@ -0,0 +1,6 @@
|
||||
# The "find" should not see "saved" (duplicated) fd #1
|
||||
# Explicitly use bbox find, since other implementations of "find"
|
||||
# may open other descriptors as well.
|
||||
busybox find /proc/self/fd >tmp_$$.out
|
||||
cat tmp_$$.out
|
||||
rm -f tmp_$$.out
|
||||
@@ -0,0 +1,5 @@
|
||||
/proc/self/fd
|
||||
/proc/self/fd/0
|
||||
/proc/self/fd/1
|
||||
/proc/self/fd/2
|
||||
/proc/self/fd/3
|
||||
@@ -0,0 +1,6 @@
|
||||
# The "find" should not see "saved" (duplicated) fd #1
|
||||
# Explicitly use bbox find, since other implementations of "find"
|
||||
# may open other descriptors as well.
|
||||
{ busybox find /proc/self/fd; } >tmp_$$.out
|
||||
cat tmp_$$.out
|
||||
rm -f tmp_$$.out
|
||||
@@ -0,0 +1,5 @@
|
||||
/proc/self/fd
|
||||
/proc/self/fd/0
|
||||
/proc/self/fd/1
|
||||
/proc/self/fd/2
|
||||
/proc/self/fd/3
|
||||
@@ -0,0 +1,6 @@
|
||||
# The "find" should not see "saved" (duplicated) fd #1
|
||||
# Explicitly use bbox find, since other implementations of "find"
|
||||
# may open other descriptors as well.
|
||||
{ busybox find /proc/self/fd; true; } >tmp_$$.out
|
||||
cat tmp_$$.out
|
||||
rm -f tmp_$$.out
|
||||
+16
-9
@@ -1478,12 +1478,15 @@ static void free_strings(char **strings)
|
||||
free(strings);
|
||||
}
|
||||
|
||||
static int fcntl_F_DUPFD(int fd, int avoid_fd)
|
||||
static int dup_CLOEXEC(int fd, int avoid_fd)
|
||||
{
|
||||
int newfd;
|
||||
repeat:
|
||||
newfd = fcntl(fd, F_DUPFD, avoid_fd + 1);
|
||||
if (newfd < 0) {
|
||||
newfd = fcntl(fd, F_DUPFD_CLOEXEC, avoid_fd + 1);
|
||||
if (newfd >= 0) {
|
||||
if (F_DUPFD_CLOEXEC == F_DUPFD) /* if old libc (w/o F_DUPFD_CLOEXEC) */
|
||||
fcntl(newfd, F_SETFD, FD_CLOEXEC);
|
||||
} else { /* newfd < 0 */
|
||||
if (errno == EBUSY)
|
||||
goto repeat;
|
||||
if (errno == EINTR)
|
||||
@@ -6012,7 +6015,7 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg)
|
||||
} else
|
||||
/* If EXP_FLAG_SINGLEWORD, we handle assignment 'a=....$@.....'
|
||||
* and in this case should treat it like '$*' - see 'else...' below */
|
||||
if (first_ch == ('@'|0x80) /* quoted $@ */
|
||||
if (first_ch == (char)('@'|0x80) /* quoted $@ */
|
||||
&& !(output->o_expflags & EXP_FLAG_SINGLEWORD) /* not v="$@" case */
|
||||
) {
|
||||
while (1) {
|
||||
@@ -6766,7 +6769,7 @@ static struct squirrel *add_squirrel(struct squirrel *sq, int fd, int avoid_fd)
|
||||
if (sq) for (; sq[i].orig_fd >= 0; i++) {
|
||||
/* If we collide with an already moved fd... */
|
||||
if (fd == sq[i].moved_to) {
|
||||
sq[i].moved_to = fcntl_F_DUPFD(sq[i].moved_to, avoid_fd);
|
||||
sq[i].moved_to = dup_CLOEXEC(sq[i].moved_to, avoid_fd);
|
||||
debug_printf_redir("redirect_fd %d: already busy, moving to %d\n", fd, sq[i].moved_to);
|
||||
if (sq[i].moved_to < 0) /* what? */
|
||||
xfunc_die();
|
||||
@@ -6780,7 +6783,7 @@ static struct squirrel *add_squirrel(struct squirrel *sq, int fd, int avoid_fd)
|
||||
}
|
||||
|
||||
/* If this fd is open, we move and remember it; if it's closed, moved_to = -1 */
|
||||
moved_to = fcntl_F_DUPFD(fd, avoid_fd);
|
||||
moved_to = dup_CLOEXEC(fd, avoid_fd);
|
||||
debug_printf_redir("redirect_fd %d: previous fd is moved to %d (-1 if it was closed)\n", fd, moved_to);
|
||||
if (moved_to < 0 && errno != EBADF)
|
||||
xfunc_die();
|
||||
@@ -7429,6 +7432,10 @@ static NOINLINE void pseudo_exec_argv(nommu_save_t *nommu_save,
|
||||
*/
|
||||
close_saved_fds_and_FILE_fds();
|
||||
//FIXME: should also close saved redir fds
|
||||
//This casuses test failures in
|
||||
//redir_children_should_not_see_saved_fd_2.tests
|
||||
//redir_children_should_not_see_saved_fd_3.tests
|
||||
//if you replace "busybox find" with just "find" in them
|
||||
/* Without this, "rm -i FILE" can't be ^C'ed: */
|
||||
switch_off_special_sigs(G.special_sig_mask);
|
||||
debug_printf_exec("running applet '%s'\n", argv[0]);
|
||||
@@ -9133,7 +9140,7 @@ int hush_main(int argc, char **argv)
|
||||
G_saved_tty_pgrp = 0;
|
||||
|
||||
/* try to dup stdin to high fd#, >= 255 */
|
||||
G_interactive_fd = fcntl_F_DUPFD(STDIN_FILENO, 254);
|
||||
G_interactive_fd = dup_CLOEXEC(STDIN_FILENO, 254);
|
||||
if (G_interactive_fd < 0) {
|
||||
/* try to dup to any fd */
|
||||
G_interactive_fd = dup(STDIN_FILENO);
|
||||
@@ -9206,10 +9213,10 @@ int hush_main(int argc, char **argv)
|
||||
#elif ENABLE_HUSH_INTERACTIVE
|
||||
/* No job control compiled in, only prompt/line editing */
|
||||
if (isatty(STDIN_FILENO) && isatty(STDOUT_FILENO)) {
|
||||
G_interactive_fd = fcntl_F_DUPFD(STDIN_FILENO, 254);
|
||||
G_interactive_fd = dup_CLOEXEC(STDIN_FILENO, 254);
|
||||
if (G_interactive_fd < 0) {
|
||||
/* try to dup to any fd */
|
||||
G_interactive_fd = dup(STDIN_FILENO);
|
||||
G_interactive_fd = dup_CLOEXEC(STDIN_FILENO);
|
||||
if (G_interactive_fd < 0)
|
||||
/* give up */
|
||||
G_interactive_fd = 0;
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
/proc/self/fd
|
||||
/proc/self/fd/0
|
||||
/proc/self/fd/1
|
||||
/proc/self/fd/2
|
||||
/proc/self/fd/3
|
||||
@@ -0,0 +1,6 @@
|
||||
# The "find" should not see "saved" (duplicated) fd #1
|
||||
# Explicitly use bbox find, since other implementations of "find"
|
||||
# may open other descriptors as well.
|
||||
busybox find /proc/self/fd >tmp_$$.out
|
||||
cat tmp_$$.out
|
||||
rm -f tmp_$$.out
|
||||
@@ -0,0 +1,5 @@
|
||||
/proc/self/fd
|
||||
/proc/self/fd/0
|
||||
/proc/self/fd/1
|
||||
/proc/self/fd/2
|
||||
/proc/self/fd/3
|
||||
@@ -0,0 +1,6 @@
|
||||
# The "find" should not see "saved" (duplicated) fd #1
|
||||
# Explicitly use bbox find, since other implementations of "find"
|
||||
# may open other descriptors as well.
|
||||
{ busybox find /proc/self/fd; } >tmp_$$.out
|
||||
cat tmp_$$.out
|
||||
rm -f tmp_$$.out
|
||||
@@ -0,0 +1,5 @@
|
||||
/proc/self/fd
|
||||
/proc/self/fd/0
|
||||
/proc/self/fd/1
|
||||
/proc/self/fd/2
|
||||
/proc/self/fd/3
|
||||
@@ -0,0 +1,6 @@
|
||||
# The "find" should not see "saved" (duplicated) fd #1
|
||||
# Explicitly use bbox find, since other implementations of "find"
|
||||
# may open other descriptors as well.
|
||||
{ busybox find /proc/self/fd; true; } >tmp_$$.out
|
||||
cat tmp_$$.out
|
||||
rm -f tmp_$$.out
|
||||
@@ -165,6 +165,12 @@ testing "grep -w word doesn't match wordword" \
|
||||
"wordword\n" \
|
||||
""
|
||||
|
||||
testing "grep -F -w w doesn't match ww" \
|
||||
"grep -F -w w input" \
|
||||
"" \
|
||||
"ww\n" \
|
||||
""
|
||||
|
||||
testing "grep -w word match second word" \
|
||||
"grep -w word input" \
|
||||
"bword,word\n""wordb,word\n""bwordb,word\n" \
|
||||
|
||||
+5
-5
@@ -279,7 +279,7 @@ optional UUDECODE FEATURE_TAR_AUTODETECT FEATURE_SEAMLESS_BZ2
|
||||
testing "tar does not extract into symlinks" "\
|
||||
>>/tmp/passwd && uudecode -o input && tar xf input 2>&1 && rm passwd; cat /tmp/passwd; echo \$?
|
||||
" "\
|
||||
tar: skipping unsafe symlink to '/tmp/passwd' in archive, set EXTRACT_UNSAFE_SYMLINKS=1 to extract
|
||||
tar: can't create symlink 'passwd' to '/tmp/passwd'
|
||||
0
|
||||
" \
|
||||
"" "\
|
||||
@@ -299,7 +299,7 @@ optional UUDECODE FEATURE_TAR_AUTODETECT FEATURE_SEAMLESS_BZ2
|
||||
testing "tar -k does not extract into symlinks" "\
|
||||
>>/tmp/passwd && uudecode -o input && tar xf input -k 2>&1 && rm passwd; cat /tmp/passwd; echo \$?
|
||||
" "\
|
||||
tar: skipping unsafe symlink to '/tmp/passwd' in archive, set EXTRACT_UNSAFE_SYMLINKS=1 to extract
|
||||
tar: can't create symlink 'passwd' to '/tmp/passwd'
|
||||
0
|
||||
" \
|
||||
"" "\
|
||||
@@ -324,11 +324,11 @@ rm -rf etc usr
|
||||
' "\
|
||||
etc/ssl/certs/3b2716e5.0
|
||||
etc/ssl/certs/EBG_Elektronik_Sertifika_Hizmet_Sağlayıcısı.pem
|
||||
tar: skipping unsafe symlink to '/usr/share/ca-certificates/mozilla/EBG_Elektronik_Sertifika_Hizmet_Sağlayıcısı.crt' in archive, set EXTRACT_UNSAFE_SYMLINKS=1 to extract
|
||||
etc/ssl/certs/f80cc7f6.0
|
||||
usr/share/ca-certificates/mozilla/EBG_Elektronik_Sertifika_Hizmet_Sağlayıcısı.crt
|
||||
0
|
||||
etc/ssl/certs/3b2716e5.0 -> EBG_Elektronik_Sertifika_Hizmet_Sağlayıcısı.pem
|
||||
etc/ssl/certs/EBG_Elektronik_Sertifika_Hizmet_Sağlayıcısı.pem -> /usr/share/ca-certificates/mozilla/EBG_Elektronik_Sertifika_Hizmet_Sağlayıcısı.crt
|
||||
etc/ssl/certs/f80cc7f6.0 -> EBG_Elektronik_Sertifika_Hizmet_Sağlayıcısı.pem
|
||||
" \
|
||||
"" ""
|
||||
@@ -346,9 +346,9 @@ ls symlink/bb_test_evilfile
|
||||
' "\
|
||||
anything.txt
|
||||
symlink
|
||||
tar: skipping unsafe symlink to '/tmp' in archive, set EXTRACT_UNSAFE_SYMLINKS=1 to extract
|
||||
symlink/bb_test_evilfile
|
||||
0
|
||||
tar: can't create symlink 'symlink' to '/tmp'
|
||||
1
|
||||
ls: /tmp/bb_test_evilfile: No such file or directory
|
||||
ls: bb_test_evilfile: No such file or directory
|
||||
symlink/bb_test_evilfile
|
||||
|
||||
@@ -105,14 +105,14 @@ static const struct namespace_descr ns_list[] = {
|
||||
/*
|
||||
* Upstream nsenter doesn't support the short option for --preserve-credentials
|
||||
*/
|
||||
static const char opt_str[] ALIGN1 = "U::i::u::n::p::m::""t+S+G+r::w::F";
|
||||
static const char opt_str[] ALIGN1 = "U::i::u::n::p::m::""t:+S:+G:+r::w::F";
|
||||
|
||||
#if ENABLE_LONG_OPTS
|
||||
static const char nsenter_longopts[] ALIGN1 =
|
||||
"user\0" Optional_argument "U"
|
||||
"ipc\0" Optional_argument "i"
|
||||
"uts\0" Optional_argument "u"
|
||||
"network\0" Optional_argument "n"
|
||||
"net\0" Optional_argument "n"
|
||||
"pid\0" Optional_argument "p"
|
||||
"mount\0" Optional_argument "m"
|
||||
"target\0" Required_argument "t"
|
||||
|
||||
Reference in new issue
Block a user