ASR_BASE
Change-Id: Icf3719cc0afe3eeb3edc7fa80a2eb5199ca9dda1
diff --git a/package/utils/busybox/patches/120-lto-jobserver.patch b/package/utils/busybox/patches/120-lto-jobserver.patch
new file mode 100644
index 0000000..d4f997e
--- /dev/null
+++ b/package/utils/busybox/patches/120-lto-jobserver.patch
@@ -0,0 +1,27 @@
+--- a/scripts/Kbuild.include
++++ b/scripts/Kbuild.include
+@@ -131,7 +131,7 @@ make-cmd = $(subst \#,\\\#,$(subst $$,$$
+ #
+ if_changed = $(if $(strip $(filter-out $(PHONY),$?) \
+ $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \
+- @set -e; \
++ +@set -e; \
+ $(echo-cmd) $(cmd_$(1)); \
+ echo 'cmd_$@ := $(make-cmd)' > $(@D)/.$(@F).cmd)
+
+@@ -140,7 +140,7 @@ if_changed = $(if $(strip $(filter-out $
+ if_changed_dep = $(if $(strip $(filter-out $(PHONY),$?) \
+ $(filter-out FORCE $(wildcard $^),$^) \
+ $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \
+- @set -e; \
++ +@set -e; \
+ $(echo-cmd) $(cmd_$(1)); \
+ scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(@D)/.$(@F).tmp; \
+ rm -f $(depfile); \
+@@ -151,5 +151,5 @@ if_changed_dep = $(if $(strip $(filter-o
+ # and if so will execute $(rule_foo)
+ if_changed_rule = $(if $(strip $(filter-out $(PHONY),$?) \
+ $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ),\
+- @set -e; \
++ +@set -e; \
+ $(rule_$(1)))
diff --git a/package/utils/busybox/patches/200-udhcpc_reduce_msgs.patch b/package/utils/busybox/patches/200-udhcpc_reduce_msgs.patch
new file mode 100644
index 0000000..c0f234e
--- /dev/null
+++ b/package/utils/busybox/patches/200-udhcpc_reduce_msgs.patch
@@ -0,0 +1,18 @@
+--- a/networking/udhcp/dhcpc.c
++++ b/networking/udhcp/dhcpc.c
+@@ -722,6 +722,7 @@ static int bcast_or_ucast(struct dhcp_pa
+ static NOINLINE int send_discover(uint32_t requested)
+ {
+ struct dhcp_packet packet;
++ static int msgs = 0;
+
+ /* Fill in: op, htype, hlen, cookie, chaddr fields,
+ * xid field, message type option:
+@@ -736,6 +737,7 @@ static NOINLINE int send_discover(uint32
+ */
+ add_client_options(&packet);
+
++ if (msgs++ < 3)
+ bb_simple_info_msg("broadcasting discover");
+ return raw_bcast_from_client_data_ifindex(&packet, INADDR_ANY);
+ }
diff --git a/package/utils/busybox/patches/201-udhcpc_changed_ifindex.patch b/package/utils/busybox/patches/201-udhcpc_changed_ifindex.patch
new file mode 100644
index 0000000..a4bda99
--- /dev/null
+++ b/package/utils/busybox/patches/201-udhcpc_changed_ifindex.patch
@@ -0,0 +1,15 @@
+--- a/networking/udhcp/dhcpc.c
++++ b/networking/udhcp/dhcpc.c
+@@ -1384,6 +1384,12 @@ int udhcpc_main(int argc UNUSED_PARAM, c
+ struct pollfd pfds[2];
+ struct dhcp_packet packet;
+
++ /* When running on a bridge, the ifindex may have changed (e.g. if
++ * member interfaces were added/removed or if the status of the
++ * bridge changed).
++ * Workaround: refresh it here before processing the next packet */
++ udhcp_read_interface(client_data.interface, &client_data.ifindex, NULL, client_data.client_mac);
++
+ //bb_error_msg("sockfd:%d, listen_mode:%d", client_data.sockfd, client_data.listen_mode);
+
+ /* Was opening raw or udp socket here
diff --git a/package/utils/busybox/patches/210-add_netmsg_util.patch b/package/utils/busybox/patches/210-add_netmsg_util.patch
new file mode 100644
index 0000000..d7b2ae7
--- /dev/null
+++ b/package/utils/busybox/patches/210-add_netmsg_util.patch
@@ -0,0 +1,79 @@
+--- /dev/null
++++ b/networking/netmsg.c
+@@ -0,0 +1,76 @@
++/*
++ * Copyright (C) 2006 Felix Fietkau <nbd@nbd.name>
++ *
++ * This is free software, licensed under the GNU General Public License v2.
++ */
++
++//config:config NETMSG
++//config: bool "netmsg"
++//config: default n
++//config: help
++//config: simple program for sending udp broadcast messages
++
++//applet:IF_NETMSG(APPLET(netmsg, BB_DIR_BIN, BB_SUID_REQUIRE))
++
++//kbuild:lib-$(CONFIG_NETMSG) += netmsg.o
++
++//usage:#define netmsg_trivial_usage NOUSAGE_STR
++//usage:#define netmsg_full_usage ""
++
++#include <sys/types.h>
++#include <sys/socket.h>
++#include <netinet/in.h>
++#include <netdb.h>
++#include <stdio.h>
++#include <stdlib.h>
++#include <string.h>
++#include "busybox.h"
++
++#ifndef CONFIG_NETMSG
++int main(int argc, char **argv)
++#else
++int netmsg_main(int argc, char **argv)
++#endif
++{
++ int s;
++ struct sockaddr_in addr;
++ int optval = 1;
++ unsigned char buf[1001];
++
++ if (argc != 3) {
++ fprintf(stderr, "usage: %s <ip> \"<message>\"\n", argv[0]);
++ exit(1);
++ }
++
++ if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
++ perror("Opening socket");
++ exit(1);
++ }
++
++ memset(&addr, 0, sizeof(addr));
++ addr.sin_family = AF_INET;
++ addr.sin_addr.s_addr = inet_addr(argv[1]);
++ addr.sin_port = htons(0x1337);
++
++ memset(buf, 0, 1001);
++ buf[0] = 0xde;
++ buf[1] = 0xad;
++
++ strncpy(buf + 2, argv[2], 998);
++
++ if (setsockopt (s, SOL_SOCKET, SO_BROADCAST, (caddr_t) &optval, sizeof (optval)) < 0) {
++ perror("setsockopt()");
++ goto fail;
++ }
++
++ if (sendto(s, buf, 1001, 0, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
++ perror("sendto()");
++ goto fail;
++ }
++
++ return 0;
++
++fail:
++ close(s);
++ exit(1);
++}
diff --git a/package/utils/busybox/patches/220-add_lock_util.patch b/package/utils/busybox/patches/220-add_lock_util.patch
new file mode 100644
index 0000000..579b705
--- /dev/null
+++ b/package/utils/busybox/patches/220-add_lock_util.patch
@@ -0,0 +1,158 @@
+--- /dev/null
++++ b/miscutils/lock.c
+@@ -0,0 +1,155 @@
++/*
++ * Copyright (C) 2006 Felix Fietkau <nbd@nbd.name>
++ *
++ * This is free software, licensed under the GNU General Public License v2.
++ */
++
++//config:config LOCK
++//config: bool "lock"
++//config: default n
++//config: help
++//config: Small utility for using locks in scripts
++
++//applet:IF_LOCK(APPLET(lock, BB_DIR_BIN, BB_SUID_DROP))
++
++//kbuild:lib-$(CONFIG_LOCK) += lock.o
++
++//usage:#define lock_trivial_usage NOUSAGE_STR
++//usage:#define lock_full_usage ""
++
++#include <sys/types.h>
++#include <sys/file.h>
++#include <sys/stat.h>
++#include <signal.h>
++#include <fcntl.h>
++#include <unistd.h>
++#include <stdio.h>
++#include "busybox.h"
++
++static int unlock = 0;
++static int shared = 0;
++static int waitonly = 0;
++static int try_lock = 0;
++static int fd;
++static char *file;
++
++static void usage(char *name)
++{
++ fprintf(stderr, "Usage: %s [-suw] <filename>\n"
++ " -s Use shared locking\n"
++ " -u Unlock\n"
++ " -w Wait for the lock to become free, don't acquire lock\n"
++ " -n Don't wait for the lock to become free. Fail with exit code\n"
++ "\n", name);
++ exit(1);
++}
++
++static void exit_unlock(int sig)
++{
++ flock(fd, LOCK_UN);
++ exit(0);
++}
++
++static int do_unlock(void)
++{
++ FILE *f;
++ int i;
++
++ if ((f = fopen(file, "r")) == NULL)
++ return 0;
++
++ fscanf(f, "%d", &i);
++ if (i > 0)
++ kill(i, SIGTERM);
++
++ fclose(f);
++
++ return 0;
++}
++
++static int do_lock(void)
++{
++ pid_t pid;
++ int flags;
++ char pidstr[12];
++
++ if ((fd = open(file, O_RDWR | O_CREAT | O_EXCL, 0700)) < 0) {
++ if ((fd = open(file, O_RDWR)) < 0) {
++ fprintf(stderr, "Can't open %s\n", file);
++ return 1;
++ }
++ }
++
++ flags = shared ? LOCK_SH : LOCK_EX;
++ flags |= try_lock ? LOCK_NB : 0;
++
++ if (flock(fd, flags) < 0) {
++ fprintf(stderr, "Can't lock %s\n", file);
++ return 1;
++ }
++
++ pid = fork();
++
++ if (pid < 0)
++ return -1;
++
++ if (pid == 0) {
++ signal(SIGKILL, exit_unlock);
++ signal(SIGTERM, exit_unlock);
++ signal(SIGINT, exit_unlock);
++ if (waitonly)
++ exit_unlock(0);
++ else
++ while (1)
++ sleep(1);
++ } else {
++ if (!waitonly) {
++ lseek(fd, 0, SEEK_SET);
++ ftruncate(fd, 0);
++ snprintf(pidstr, sizeof(pidstr), "%d\n", pid);
++ write(fd, pidstr, strlen(pidstr));
++ close(fd);
++ }
++
++ return 0;
++ }
++ return 0;
++}
++
++int lock_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
++int lock_main(int argc, char **argv)
++{
++ char **args = &argv[1];
++ int c = argc - 1;
++
++ while ((*args != NULL) && (*args)[0] == '-') {
++ char *ch = *args;
++ while (*(++ch) > 0) {
++ switch(*ch) {
++ case 'w':
++ waitonly = 1;
++ break;
++ case 's':
++ shared = 1;
++ break;
++ case 'u':
++ unlock = 1;
++ break;
++ case 'n':
++ try_lock = 1;
++ break;
++ }
++ }
++ c--;
++ args++;
++ }
++
++ if (c != 1)
++ usage(argv[0]);
++
++ file = *args;
++ if (unlock)
++ return do_unlock();
++ else
++ return do_lock();
++}
diff --git a/package/utils/busybox/patches/270-libbb_make_unicode_printable.patch b/package/utils/busybox/patches/270-libbb_make_unicode_printable.patch
new file mode 100644
index 0000000..0b682dc
--- /dev/null
+++ b/package/utils/busybox/patches/270-libbb_make_unicode_printable.patch
@@ -0,0 +1,20 @@
+--- a/libbb/printable_string.c
++++ b/libbb/printable_string.c
+@@ -28,8 +28,6 @@ const char* FAST_FUNC printable_string2(
+ }
+ if (c < ' ')
+ break;
+- if (c >= 0x7f)
+- break;
+ s++;
+ }
+
+@@ -42,7 +40,7 @@ const char* FAST_FUNC printable_string2(
+ unsigned char c = *d;
+ if (c == '\0')
+ break;
+- if (c < ' ' || c >= 0x7f)
++ if (c < ' ')
+ *d = '?';
+ d++;
+ }
diff --git a/package/utils/busybox/patches/301-ip-link-fix-netlink-msg-size.patch b/package/utils/busybox/patches/301-ip-link-fix-netlink-msg-size.patch
new file mode 100644
index 0000000..f4c0a80
--- /dev/null
+++ b/package/utils/busybox/patches/301-ip-link-fix-netlink-msg-size.patch
@@ -0,0 +1,11 @@
+--- a/networking/libiproute/iplink.c
++++ b/networking/libiproute/iplink.c
+@@ -683,7 +683,7 @@ static int do_add_or_delete(char **argv,
+ }
+ xrtnl_open(&rth);
+ ll_init_map(&rth);
+- if (type_str) {
++ if (type_str && rtm == RTM_NEWLINK) {
+ struct rtattr *linkinfo = NLMSG_TAIL(&req.n);
+
+ addattr_l(&req.n, sizeof(req), IFLA_LINKINFO, NULL, 0);
diff --git a/package/utils/busybox/patches/500-move-traceroute-applets-to-bin.patch b/package/utils/busybox/patches/500-move-traceroute-applets-to-bin.patch
new file mode 100644
index 0000000..0389eed
--- /dev/null
+++ b/package/utils/busybox/patches/500-move-traceroute-applets-to-bin.patch
@@ -0,0 +1,13 @@
+--- a/networking/traceroute.c
++++ b/networking/traceroute.c
+@@ -236,8 +236,8 @@
+ //config: depends on TRACEROUTE || TRACEROUTE6
+
+ /* Needs socket(AF_INET, SOCK_RAW, IPPROTO_ICMP), therefore BB_SUID_MAYBE: */
+-//applet:IF_TRACEROUTE(APPLET(traceroute, BB_DIR_USR_BIN, BB_SUID_MAYBE))
+-//applet:IF_TRACEROUTE6(APPLET(traceroute6, BB_DIR_USR_BIN, BB_SUID_MAYBE))
++//applet:IF_TRACEROUTE(APPLET(traceroute, BB_DIR_BIN, BB_SUID_MAYBE))
++//applet:IF_TRACEROUTE6(APPLET(traceroute6, BB_DIR_BIN, BB_SUID_MAYBE))
+
+ //kbuild:lib-$(CONFIG_TRACEROUTE) += traceroute.o
+ //kbuild:lib-$(CONFIG_TRACEROUTE6) += traceroute.o
diff --git a/package/utils/busybox/patches/510-move-passwd-applet-to-bin.patch b/package/utils/busybox/patches/510-move-passwd-applet-to-bin.patch
new file mode 100644
index 0000000..7dc2cd3
--- /dev/null
+++ b/package/utils/busybox/patches/510-move-passwd-applet-to-bin.patch
@@ -0,0 +1,11 @@
+--- a/loginutils/passwd.c
++++ b/loginutils/passwd.c
+@@ -23,7 +23,7 @@
+ //config: With this option passwd will refuse new passwords which are "weak".
+
+ //applet:/* Needs to be run by root or be suid root - needs to change /etc/{passwd,shadow}: */
+-//applet:IF_PASSWD(APPLET(passwd, BB_DIR_USR_BIN, BB_SUID_REQUIRE))
++//applet:IF_PASSWD(APPLET(passwd, BB_DIR_BIN, BB_SUID_REQUIRE))
+
+ //kbuild:lib-$(CONFIG_PASSWD) += passwd.o
+
diff --git a/package/utils/busybox/patches/520-loginutils-handle-crypt-failures.patch b/package/utils/busybox/patches/520-loginutils-handle-crypt-failures.patch
new file mode 100644
index 0000000..91340d4
--- /dev/null
+++ b/package/utils/busybox/patches/520-loginutils-handle-crypt-failures.patch
@@ -0,0 +1,53 @@
+--- a/loginutils/chpasswd.c
++++ b/loginutils/chpasswd.c
+@@ -89,6 +89,11 @@ int chpasswd_main(int argc UNUSED_PARAM,
+
+ crypt_make_pw_salt(salt, algo);
+ free_me = pass = pw_encrypt(pass, salt, 0);
++
++ if (pass[0] == 0) {
++ free(free_me);
++ bb_perror_msg_and_die("password encryption failed");
++ }
+ }
+
+ /* This is rather complex: if user is not found in /etc/shadow,
+--- a/loginutils/cryptpw.c
++++ b/loginutils/cryptpw.c
+@@ -87,7 +87,7 @@ int cryptpw_main(int argc UNUSED_PARAM,
+ /* Supports: cryptpw -m sha256 PASS 'rounds=999999999$SALT' */
+ char salt[MAX_PW_SALT_LEN + sizeof("rounds=999999999$")];
+ char *salt_ptr;
+- char *password;
++ char *password, *hash;
+ const char *opt_m, *opt_S;
+ int fd;
+
+@@ -132,8 +132,12 @@ int cryptpw_main(int argc UNUSED_PARAM,
+ /* may still be NULL on EOF/error */
+ }
+
+- if (password)
+- puts(pw_encrypt(password, salt, 1));
++ if (password) {
++ hash = pw_encrypt(password, salt, 1);
++ if (hash[0] == 0)
++ bb_perror_msg_and_die("password encryption failed");
++ puts(hash);
++ }
+
+ return EXIT_SUCCESS;
+ }
+--- a/loginutils/passwd.c
++++ b/loginutils/passwd.c
+@@ -187,6 +187,10 @@ int passwd_main(int argc UNUSED_PARAM, c
+ if (!newp) {
+ logmode = LOGMODE_STDIO;
+ bb_error_msg_and_die("password for %s is unchanged", name);
++ } else if (newp[0] == 0) {
++ logmode = LOGMODE_STDIO;
++ free(newp);
++ bb_perror_msg_and_die("password encryption failed");
+ }
+ } else if (opt & OPT_lock) {
+ if (!c)
diff --git a/package/utils/busybox/patches/530-nslookup-ensure-unique-transaction-IDs-for-the-DNS-queries.patch b/package/utils/busybox/patches/530-nslookup-ensure-unique-transaction-IDs-for-the-DNS-queries.patch
new file mode 100644
index 0000000..caa5ee7
--- /dev/null
+++ b/package/utils/busybox/patches/530-nslookup-ensure-unique-transaction-IDs-for-the-DNS-queries.patch
@@ -0,0 +1,42 @@
+From: Uwe Kleine-König <uwe@kleine-koenig.org>
+Date: Sat, 8 Oct 2022 19:22:52 +0200
+Subject: [PATCH] nslookup: ensure unique transaction IDs for the DNS queries
+
+The transaction IDs generated by res_mkquery() for both glibc and musl only
+depends on the state of the monotonic clock.
+For some machines (here: a TP-Link RE200 powered by a MediaTek MT7620A)
+the monotonic clock has a coarse resolution (here: 20 µs) and it can happen
+that the requests for A and AAAA share the same transaction ID.
+
+In that case the mapping from received responses to the sent queries
+doesn't work and name resolution fails as follows:
+
+ # /bin/busybox nslookup heise.de
+ Server: 127.0.0.1
+ Address: 127.0.0.1:53
+
+ Non-authoritative answer:
+ Name: heise.de
+ Address: 193.99.144.80
+
+ *** Can't find heise.de: No answer
+
+because the AAAA reply is dropped as a duplicate reply to the A query.
+
+To prevent this make sure the transaction IDs are unique.
+
+Forwarded: http://lists.busybox.net/pipermail/busybox/2022-October/089911.html
+---
+--- a/networking/nslookup.c
++++ b/networking/nslookup.c
+@@ -978,6 +978,10 @@ int nslookup_main(int argc UNUSED_PARAM,
+ }
+ }
+
++ /* Ensure the Transaction IDs are unique */
++ for (rc = 1; rc < G.query_count; rc++)
++ G.query[rc].query[1] = G.query[rc - 1].query[1] + 1;
++
+ for (rc = 0; rc < G.serv_count;) {
+ int c;
+
diff --git a/package/utils/busybox/patches/540-ignore-SIGQUIT-to-avoid-coredump.patch b/package/utils/busybox/patches/540-ignore-SIGQUIT-to-avoid-coredump.patch
new file mode 100644
index 0000000..31618bf
--- /dev/null
+++ b/package/utils/busybox/patches/540-ignore-SIGQUIT-to-avoid-coredump.patch
@@ -0,0 +1,11 @@
+--- a/shell/ash.c
++++ b/shell/ash.c
+@@ -10079,7 +10079,7 @@ execcmd(int argc UNUSED_PARAM, char **ar
+ * SIGQUIT is still set to IGN. Fix it:
+ */
+ shlvl++;
+- setsignal(SIGQUIT);
++ /*setsignal(SIGQUIT); - avoid coredump after "ctrl+\" or executing "kill -3" in shell */
+ /*setsignal(SIGTERM); - unnecessary because of iflag=0 */
+ /*setsignal(SIGTSTP); - unnecessary because of mflag=0 */
+ /*setsignal(SIGTTOU); - unnecessary because of mflag=0 */
diff --git a/package/utils/busybox/patches/600-get-seuser-from-username.patch b/package/utils/busybox/patches/600-get-seuser-from-username.patch
new file mode 100644
index 0000000..7744f1c
--- /dev/null
+++ b/package/utils/busybox/patches/600-get-seuser-from-username.patch
@@ -0,0 +1,34 @@
+--- a/loginutils/login.c
++++ b/loginutils/login.c
+@@ -183,13 +183,17 @@ static void die_if_nologin(void)
+ static void initselinux(char *username, char *full_tty,
+ security_context_t *user_sid)
+ {
++ char *seuser = NULL, *level = NULL;
+ security_context_t old_tty_sid, new_tty_sid;
+
+ if (!is_selinux_enabled())
+ return;
+
+- if (get_default_context(username, NULL, user_sid)) {
+- bb_error_msg_and_die("can't get SID for %s", username);
++ if (getseuserbyname(username, &seuser, &level)) {
++ bb_error_msg_and_die("can't get seuser for %s", username);
++ }
++ if (get_default_context(seuser, NULL, user_sid)) {
++ bb_error_msg_and_die("can't get SID for %s", seuser);
+ }
+ if (getfilecon(full_tty, &old_tty_sid) < 0) {
+ bb_perror_msg_and_die("getfilecon(%s) failed", full_tty);
+@@ -201,6 +205,11 @@ static void initselinux(char *username,
+ if (setfilecon(full_tty, new_tty_sid) != 0) {
+ bb_perror_msg_and_die("chsid(%s, %s) failed", full_tty, new_tty_sid);
+ }
++
++ if (ENABLE_FEATURE_CLEAN_UP) {
++ free(seuser);
++ free(level);
++ }
+ }
+ #endif
+
diff --git a/package/utils/busybox/patches/601-fix_termios_configuration_missing.patch b/package/utils/busybox/patches/601-fix_termios_configuration_missing.patch
new file mode 100644
index 0000000..9f2d9b6
--- /dev/null
+++ b/package/utils/busybox/patches/601-fix_termios_configuration_missing.patch
@@ -0,0 +1,27 @@
+--- a/libbb/lineedit.c
++++ b/libbb/lineedit.c
+@@ -2467,6 +2467,7 @@ int FAST_FUNC read_line_input(line_input
+ #endif
+ struct termios initial_settings;
+ struct termios new_settings;
++ struct termios tmp_settings;
+ char read_key_buffer[KEYCODE_BUFFER_SIZE];
+
+ INIT_S();
+@@ -3006,7 +3007,15 @@ int FAST_FUNC read_line_input(line_input
+ #endif
+
+ /* restore initial_settings */
+- tcsetattr_stdin_TCSANOW(&initial_settings);
++ if (tcgetattr(STDIN_FILENO, &tmp_settings) < 0){
++ tcsetattr_stdin_TCSANOW(&initial_settings);
++ }else{
++ tmp_settings.c_lflag |= (ICANON | ECHO | ECHONL | ISIG);
++ tmp_settings.c_cc[VMIN] = initial_settings.c_cc[VMIN];
++ tmp_settings.c_cc[VTIME] = initial_settings.c_cc[VTIME];
++ tcsetattr_stdin_TCSANOW(&tmp_settings);
++ }
++
+ #if ENABLE_FEATURE_EDITING_WINCH
+ /* restore SIGWINCH handler */
+ sigaction_set(SIGWINCH, &S.SIGWINCH_handler);