Compare commits

...
10 Commits
Author SHA1 Message Date
Denys Vlasenko e3821088af Bump version to 1.28.1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-14 17:43:09 +01:00
Denys Vlasenko 4a80eb142a cp: fix option handling in non-longopt config
the patch getopt32: remove opt_complementary 22542eca18

introduced a regressed in the cp command since it removed all aliases of arguments
if long_opts is not configured.

Patch by Sebastian Gottschall <s.gottschall@dd-wrt.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-14 17:38:40 +01:00
Denys Vlasenko 1574aff942 svlogd: improve --help text
function                                             old     new   delta
packed_usage                                       32278   32367     +89

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-14 17:38:40 +01:00
Denys Vlasenko f5b9a22678 ip: fix crash in "ip neigh show"
parse_rtattr() was using tb[] array without initializing it.

Based on patch by Balaji Punnuru <balaji_punnuru@cable.comcast.com>

function                                             old     new   delta
parse_rtattr                                          85     107     +22
print_route                                         1630    1617     -13
print_linkinfo                                       807     794     -13
iproute_get                                          835     822     -13
print_rule                                           680     665     -15
ll_remember_index                                    263     248     -15
print_addrinfo                                      1223    1197     -26
ipaddr_list_or_flush                                1253    1223     -30
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/7 up/down: 22/-125)          Total: -103 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-14 17:38:40 +01:00
Denys Vlasenko 1123922320 tls: fix hash calculations if client cert is requested and sent
Symptoms: connecting to
    openssl s_server -cert vsftpd.pem -port 990 -debug -cipher AES128-SHA
works, but with "-verify 1" option added it does not.

function                                             old     new   delta
tls_xread_record                                     474     499     +25
tls_handshake                                       1582    1607     +25
bad_record_die                                        98     110     +12
tls_run_copy_loop                                    282     293     +11
tls_xread_handshake_block                             58      51      -7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/1 up/down: 73/-7)              Total: 66 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-14 17:38:40 +01:00
Aaro Koskinen ce5ba9277b cp: implement -T
Implement "cp -T". Some Linux kernel Makefiles started using this recently,
so allow also building on systems using busybox cp.

function                                             old     new   delta
cp_main                                              360     428     +68
copy_file                                           1678    1676      -2
packed_usage                                       32290   32259     -31
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 76/-39)             Total: 35 bytes

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-14 17:38:29 +01:00
Denys Vlasenko 20f02c3c87 tar: accomodate non-terminated tar.chksum fields as seen from github.com
function                                             old     new   delta
get_header_tar                                      1783    1696     -87

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-14 17:38:29 +01:00
Denys Vlasenko 277636670c udhcpc6: fix ipv6prefix[_lease] envvar value in script invocation
Based on a patch by DannyAAM <danny@saru.moe>.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-14 17:38:29 +01:00
Shawn Landden 4e71661e3a umount: ignore -c
"-c, --no-canonicalize: Do not canonicalize paths."

As busybox doesn't canonicalize paths in the first place it is safe to ignore
this option.

See https://github.com/systemd/systemd/issues/7786

Signed-off-by: Shawn Landden <slandden@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-14 17:38:29 +01:00
Ingo van Lil 59675c625d ash: fail if 'shift' operand is out of range
If the numeric argument passed to ash's 'shift' built-in is greater than
'$#' the command performs no operation and exits successfully. It should
return a non-zero exit code instead:

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#shift

This is consistent with bash and hush.

function                                             old     new   delta
shiftcmd                                             122     120      -2

Signed-off-by: Ingo van Lil <inguin@gmx.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-14 17:38:29 +01:00
16 changed files with 150 additions and 104 deletions

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
VERSION = 1
PATCHLEVEL = 28
SUBLEVEL = 0
SUBLEVEL = 1
EXTRAVERSION =
NAME = Unnamed
+26 -25
View File
@@ -152,6 +152,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
file_header_t *file_header = archive_handle->file_header;
struct tar_header_t tar;
char *cp;
int tar_typeflag; /* can be "char", "int" seems give smaller code */
int i, sum_u, sum;
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
int sum_s;
@@ -253,10 +254,10 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
* POSIX says that checksum is done on unsigned bytes, but
* Sun and HP-UX gets it wrong... more details in
* GNU tar source. */
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
sum_s = ' ' * sizeof(tar.chksum);
#endif
sum_u = ' ' * sizeof(tar.chksum);
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
sum_s = sum_u;
#endif
for (i = 0; i < 148; i++) {
sum_u += ((unsigned char*)&tar)[i];
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
@@ -269,27 +270,22 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
sum_s += ((signed char*)&tar)[i];
#endif
}
/* This field does not need special treatment (getOctal) */
{
char *endp; /* gcc likes temp var for &endp */
sum = strtoul(tar.chksum, &endp, 8);
if ((*endp != '\0' && *endp != ' ')
|| (sum_u != sum IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum))
) {
bb_error_msg_and_die("invalid tar header checksum");
}
}
/* don't use xstrtoul, tar.chksum may have leading spaces */
sum = strtoul(tar.chksum, NULL, 8);
if (sum_u != sum IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum)) {
/* Most tarfiles have tar.chksum NUL or space terminated, but
* github.com decided to be "special" and have unterminated field:
* 0090: 30343300 30303031 33323731 30000000 |043.000132710...|
* ^^^^^^^^|
* Need to use GET_OCTAL. This overwrites tar.typeflag ---+
* (the '0' char immediately after chksum in example above) with NUL.
*/
tar_typeflag = (uint8_t)tar.typeflag; /* save it */
sum = GET_OCTAL(tar.chksum);
if (sum_u != sum
IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum)
) {
bb_error_msg_and_die("invalid tar header checksum");
}
/* 0 is reserved for high perf file, treat as normal file */
if (!tar.typeflag) tar.typeflag = '0';
parse_names = (tar.typeflag >= '0' && tar.typeflag <= '7');
/* getOctal trashes subsequent field, therefore we call it
/* GET_OCTAL trashes subsequent field, therefore we call it
* on fields in reverse order */
if (tar.devmajor[0]) {
char t = tar.prefix[0];
@@ -299,6 +295,11 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
file_header->device = makedev(major, minor);
tar.prefix[0] = t;
}
/* 0 is reserved for high perf file, treat as normal file */
if (tar_typeflag == '\0') tar_typeflag = '0';
parse_names = (tar_typeflag >= '0' && tar_typeflag <= '7');
file_header->link_target = NULL;
if (!p_linkname && parse_names && tar.linkname[0]) {
file_header->link_target = xstrndup(tar.linkname, sizeof(tar.linkname));
@@ -332,7 +333,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
/* Set bits 12-15 of the files mode */
/* (typeflag was not trashed because chksum does not use getOctal) */
switch (tar.typeflag) {
switch (tar_typeflag) {
case '1': /* hardlink */
/* we mark hardlinks as regular files with zero size and a link name */
file_header->mode |= S_IFREG;
@@ -381,7 +382,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
case 'x': { /* pax extended header */
if ((uoff_t)file_header->size > 0xfffff) /* paranoia */
goto skip_ext_hdr;
process_pax_hdr(archive_handle, file_header->size, (tar.typeflag == 'g'));
process_pax_hdr(archive_handle, file_header->size, (tar_typeflag == 'g'));
goto again_after_align;
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
/* See http://www.gnu.org/software/tar/manual/html_node/Extensions.html */
@@ -419,7 +420,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
skip_ext_hdr:
{
off_t sz;
bb_error_msg("warning: skipping header '%c'", tar.typeflag);
bb_error_msg("warning: skipping header '%c'", tar_typeflag);
sz = (file_header->size + 511) & ~(off_t)511;
archive_handle->offset += sz;
sz >>= 9; /* sz /= 512 but w/o contortions for signed div */
@@ -429,7 +430,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
goto again_after_align;
}
default:
bb_error_msg_and_die("unknown typeflag: 0x%x", tar.typeflag);
bb_error_msg_and_die("unknown typeflag: 0x%x", tar_typeflag);
}
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
+18 -3
View File
@@ -47,6 +47,7 @@
//usage: "\n -f Overwrite"
//usage: "\n -i Prompt before overwrite"
//usage: "\n -l,-s Create (sym)links"
//usage: "\n -T Treat DEST as a normal file"
//usage: "\n -u Copy only newer files"
#include "libbb.h"
@@ -92,13 +93,18 @@ int cp_main(int argc, char **argv)
"no-dereference\0" No_argument "P"
"recursive\0" No_argument "R"
"symbolic-link\0" No_argument "s"
"no-target-directory\0" No_argument "T"
"verbose\0" No_argument "v"
"update\0" No_argument "u"
"remove-destination\0" No_argument "\xff"
"parents\0" No_argument "\xfe"
);
#else
flags = getopt32(argv, FILEUTILS_CP_OPTSTR);
flags = getopt32(argv, "^"
FILEUTILS_CP_OPTSTR
"\0"
"-2:l--s:s--l:Pd:rRd:Rd:apdR"
);
#endif
/* Options of cp from GNU coreutils 6.10:
* -a, --archive
@@ -121,6 +127,8 @@ int cp_main(int argc, char **argv)
* remove each existing destination file before attempting to open
* --parents
* use full source file name under DIRECTORY
* -T, --no-target-directory
* treat DEST as a normal file
* NOT SUPPORTED IN BBOX:
* --backup[=CONTROL]
* make a backup of each existing destination file
@@ -139,8 +147,6 @@ int cp_main(int argc, char **argv)
* override the usual backup suffix
* -t, --target-directory=DIRECTORY
* copy all SOURCE arguments into DIRECTORY
* -T, --no-target-directory
* treat DEST as a normal file
* -x, --one-file-system
* stay on this file system
* -Z, --context=CONTEXT
@@ -175,6 +181,12 @@ int cp_main(int argc, char **argv)
if (d_flags < 0)
return EXIT_FAILURE;
if (flags & FILEUTILS_NO_TARGET_DIR) { /* -T */
if (!(s_flags & 2) && (d_flags & 2))
/* cp -T NOTDIR DIR */
bb_error_msg_and_die("'%s' is a directory", last);
}
#if ENABLE_FEATURE_CP_LONG_OPTIONS
//bb_error_msg("flags:%x FILEUTILS_RMDEST:%x OPT_parents:%x",
// flags, FILEUTILS_RMDEST, OPT_parents);
@@ -192,11 +204,14 @@ int cp_main(int argc, char **argv)
if (!((s_flags | d_flags) & 2)
/* ...or: recursing, the 1st is a directory, and the 2nd doesn't exist... */
|| ((flags & FILEUTILS_RECUR) && (s_flags & 2) && !d_flags)
|| (flags & FILEUTILS_NO_TARGET_DIR)
) {
/* Do a simple copy */
dest = last;
goto DO_COPY; /* NB: argc==2 -> *++argv==last */
}
} else if (flags & FILEUTILS_NO_TARGET_DIR) {
bb_error_msg_and_die("too many arguments");
}
while (1) {
+4 -3
View File
@@ -404,10 +404,11 @@ enum { /* cp.c, mv.c, install.c depend on these values. CAREFUL when changing th
/* -P = -d (mapped in cp.c) */
FILEUTILS_VERBOSE = (1 << 12) * ENABLE_FEATURE_VERBOSE, /* -v */
FILEUTILS_UPDATE = 1 << 13, /* -u */
FILEUTILS_NO_TARGET_DIR = 1 << 14, /* -T */
#if ENABLE_SELINUX
FILEUTILS_PRESERVE_SECURITY_CONTEXT = 1 << 14, /* -c */
FILEUTILS_PRESERVE_SECURITY_CONTEXT = 1 << 15, /* -c */
#endif
FILEUTILS_RMDEST = 1 << (15 - !ENABLE_SELINUX), /* --remove-destination */
FILEUTILS_RMDEST = 1 << (16 - !ENABLE_SELINUX), /* --remove-destination */
/*
* Hole. cp may have some bits set here,
* they should not affect remove_file()/copy_file()
@@ -417,7 +418,7 @@ enum { /* cp.c, mv.c, install.c depend on these values. CAREFUL when changing th
#endif
FILEUTILS_IGNORE_CHMOD_ERR = 1 << 31,
};
#define FILEUTILS_CP_OPTSTR "pdRfilsLHarPvu" IF_SELINUX("c")
#define FILEUTILS_CP_OPTSTR "pdRfilsLHarPvuT" IF_SELINUX("c")
extern int remove_file(const char *path, int flags) FAST_FUNC;
/* NB: without FILEUTILS_RECUR in flags, it will basically "cat"
* the source, not copy (unless "source" is a directory).
+3 -3
View File
@@ -113,7 +113,7 @@ static NOINLINE int print_linkinfo(const struct nlmsghdr *n)
if (G_filter.up && !(ifi->ifi_flags & IFF_UP))
return 0;
memset(tb, 0, sizeof(tb));
//memset(tb, 0, sizeof(tb)); - parse_rtattr does this
parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
if (tb[IFLA_IFNAME] == NULL) {
bb_error_msg("nil ifname");
@@ -227,7 +227,7 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM,
if (G_filter.flushb && n->nlmsg_type != RTM_NEWADDR)
return 0;
memset(rta_tb, 0, sizeof(rta_tb));
//memset(rta_tb, 0, sizeof(rta_tb)); - parse_rtattr does this
parse_rtattr(rta_tb, IFA_MAX, IFA_RTA(ifa), n->nlmsg_len - NLMSG_LENGTH(sizeof(*ifa)));
if (!rta_tb[IFA_LOCAL])
@@ -535,7 +535,7 @@ int FAST_FUNC ipaddr_list_or_flush(char **argv, int flush)
continue;
if (G_filter.pfx.family || G_filter.label) {
struct rtattr *tb[IFA_MAX+1];
memset(tb, 0, sizeof(tb));
//memset(tb, 0, sizeof(tb)); - parse_rtattr does this
parse_rtattr(tb, IFA_MAX, IFA_RTA(ifa), IFA_PAYLOAD(n));
if (!tb[IFA_LOCAL])
tb[IFA_LOCAL] = tb[IFA_ADDRESS];
+6 -4
View File
@@ -110,11 +110,13 @@ static int FAST_FUNC print_neigh(const struct sockaddr_nl *who UNUSED_PARAM,
return 0;
if (G_filter.index && G_filter.index != r->ndm_ifindex)
return 0;
if (!(G_filter.state&r->ndm_state) &&
!(r->ndm_flags & NTF_PROXY) &&
(r->ndm_state || !(G_filter.state & 0x100)) &&
(r->ndm_family != AF_DECnet))
if (!(G_filter.state&r->ndm_state)
&& !(r->ndm_flags & NTF_PROXY)
&& (r->ndm_state || !(G_filter.state & 0x100))
&& (r->ndm_family != AF_DECnet)
) {
return 0;
}
parse_rtattr(tb, NDA_MAX, NDA_RTA(r), n->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
+2 -2
View File
@@ -83,7 +83,7 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
if (len < 0)
bb_error_msg_and_die("wrong nlmsg len %d", len);
memset(tb, 0, sizeof(tb));
//memset(tb, 0, sizeof(tb)); - parse_rtattr does this
parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
#if HAVE_RTA_TABLE
@@ -1081,7 +1081,7 @@ static int iproute_get(char **argv)
bb_error_msg_and_die("wrong len %d", len);
}
memset(tb, 0, sizeof(tb));
//memset(tb, 0, sizeof(tb)); - parse_rtattr does this
parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
if (tb[RTA_PREFSRC]) {
+1 -1
View File
@@ -63,7 +63,7 @@ static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM,
if (len < 0)
return -1;
memset(tb, 0, sizeof(tb));
//memset(tb, 0, sizeof(tb)); - parse_rtattr does this
parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
if (r->rtm_family == AF_INET)
+2
View File
@@ -401,6 +401,8 @@ int FAST_FUNC rta_addattr_l(struct rtattr *rta, int maxlen, int type, void *data
void FAST_FUNC parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len)
{
memset(tb, 0, (max + 1) * sizeof(tb[0]));
while (RTA_OK(rta, len)) {
if (rta->rta_type <= max) {
tb[rta->rta_type] = rta;
+1 -1
View File
@@ -51,7 +51,7 @@ int FAST_FUNC ll_remember_index(const struct sockaddr_nl *who UNUSED_PARAM,
if (n->nlmsg_len < NLMSG_LENGTH(sizeof(ifi)))
return -1;
memset(tb, 0, sizeof(tb));
//memset(tb, 0, sizeof(tb)); - parse_rtattr does this
parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), IFLA_PAYLOAD(n));
if (tb[IFLA_IFNAME] == NULL)
return 0;
+13 -9
View File
@@ -57,17 +57,21 @@
/* nullifies tb on error */
#define __parse_rtattr_nested_compat(tb, max, rta, len) \
({if ((RTA_PAYLOAD(rta) >= len) && \
(RTA_PAYLOAD(rta) >= RTA_ALIGN(len) + sizeof(struct rtattr))) { \
rta = RTA_DATA(rta) + RTA_ALIGN(len); \
parse_rtattr_nested(tb, max, rta); \
} else \
memset(tb, 0, sizeof(struct rtattr *) * (max + 1)); \
})
({ \
if ((RTA_PAYLOAD(rta) >= len) \
&& (RTA_PAYLOAD(rta) >= RTA_ALIGN(len) + sizeof(struct rtattr)) \
) { \
rta = RTA_DATA(rta) + RTA_ALIGN(len); \
parse_rtattr_nested(tb, max, rta); \
} else \
memset(tb, 0, sizeof(struct rtattr *) * (max + 1)); \
})
#define parse_rtattr_nested_compat(tb, max, rta, data, len) \
({data = RTA_PAYLOAD(rta) >= len ? RTA_DATA(rta) : NULL; \
__parse_rtattr_nested_compat(tb, max, rta, len); })
({ \
data = RTA_PAYLOAD(rta) >= len ? RTA_DATA(rta) : NULL; \
__parse_rtattr_nested_compat(tb, max, rta, len); \
})
#define show_details (0) /* not implemented. Does anyone need it? */
#define use_iec (0) /* not currently documented in the upstream manpage */
+53 -39
View File
@@ -84,23 +84,23 @@
# define dbg_der(...) ((void)0)
#endif
#define RECORD_TYPE_CHANGE_CIPHER_SPEC 20
#define RECORD_TYPE_ALERT 21
#define RECORD_TYPE_HANDSHAKE 22
#define RECORD_TYPE_APPLICATION_DATA 23
#define RECORD_TYPE_CHANGE_CIPHER_SPEC 20 /* 0x14 */
#define RECORD_TYPE_ALERT 21 /* 0x15 */
#define RECORD_TYPE_HANDSHAKE 22 /* 0x16 */
#define RECORD_TYPE_APPLICATION_DATA 23 /* 0x17 */
#define HANDSHAKE_HELLO_REQUEST 0
#define HANDSHAKE_CLIENT_HELLO 1
#define HANDSHAKE_SERVER_HELLO 2
#define HANDSHAKE_HELLO_VERIFY_REQUEST 3
#define HANDSHAKE_NEW_SESSION_TICKET 4
#define HANDSHAKE_CERTIFICATE 11
#define HANDSHAKE_SERVER_KEY_EXCHANGE 12
#define HANDSHAKE_CERTIFICATE_REQUEST 13
#define HANDSHAKE_SERVER_HELLO_DONE 14
#define HANDSHAKE_CERTIFICATE_VERIFY 15
#define HANDSHAKE_CLIENT_KEY_EXCHANGE 16
#define HANDSHAKE_FINISHED 20
#define HANDSHAKE_HELLO_REQUEST 0 /* 0x00 */
#define HANDSHAKE_CLIENT_HELLO 1 /* 0x01 */
#define HANDSHAKE_SERVER_HELLO 2 /* 0x02 */
#define HANDSHAKE_HELLO_VERIFY_REQUEST 3 /* 0x03 */
#define HANDSHAKE_NEW_SESSION_TICKET 4 /* 0x04 */
#define HANDSHAKE_CERTIFICATE 11 /* 0x0b */
#define HANDSHAKE_SERVER_KEY_EXCHANGE 12 /* 0x0c */
#define HANDSHAKE_CERTIFICATE_REQUEST 13 /* 0x0d */
#define HANDSHAKE_SERVER_HELLO_DONE 14 /* 0x0e */
#define HANDSHAKE_CERTIFICATE_VERIFY 15 /* 0x0f */
#define HANDSHAKE_CLIENT_KEY_EXCHANGE 16 /* 0x10 */
#define HANDSHAKE_FINISHED 20 /* 0x14 */
#define SSL_NULL_WITH_NULL_NULL 0x0000
#define SSL_RSA_WITH_NULL_MD5 0x0001
@@ -512,10 +512,12 @@ static void bad_record_die(tls_state_t *tls, const char *expected, int len)
bb_error_msg("got bad TLS record (len:%d) while expecting %s", len, expected);
if (len > 0) {
uint8_t *p = tls->inbuf;
while (len > 0) {
if (len > 99)
len = 99; /* don't flood, a few lines should be enough */
do {
fprintf(stderr, " %02x", *p++);
len--;
}
} while (len != 0);
fputc('\n', stderr);
}
xfunc_die();
@@ -671,9 +673,11 @@ static void xwrite_encrypted(tls_state_t *tls, unsigned size, unsigned type)
// AES_128_CBC Block 16 16 16
// AES_256_CBC Block 32 16 16
/* Fill IV and padding in outbuf */
tls_get_random(buf - AES_BLOCKSIZE, AES_BLOCKSIZE); /* IV */
dbg("before crypt: 5 hdr + %u data + %u hash bytes\n", size, tls->MAC_size);
dbg("before crypt: 5 hdr + %u data + %u hash bytes\n",
size - tls->MAC_size, tls->MAC_size);
/* Fill IV and padding in outbuf */
// RFC is talking nonsense:
// "Padding that is added to force the length of the plaintext to be
// an integral multiple of the block cipher's block length."
@@ -773,7 +777,7 @@ static const char *alert_text(int code)
return itoa(code);
}
static int tls_xread_record(tls_state_t *tls)
static int tls_xread_record(tls_state_t *tls, const char *expected)
{
struct record_hdr *xhdr;
int sz;
@@ -796,13 +800,16 @@ static int tls_xread_record(tls_state_t *tls)
if (total >= RECHDR_LEN && target == MAX_INBUF) {
xhdr = (void*)tls->inbuf;
target = RECHDR_LEN + (0x100 * xhdr->len16_hi + xhdr->len16_lo);
if (target > MAX_INBUF) {
/* malformed input (too long): yell and die */
tls->buffered_size = 0;
tls->ofs_to_buffered = total;
tls_error_die(tls);
if (target > MAX_INBUF /* malformed input (too long) */
|| xhdr->proto_maj != TLS_MAJ
|| xhdr->proto_min != TLS_MIN
) {
sz = total < target ? total : target;
if (sz > 24)
sz = 24; /* don't flood */
bad_record_die(tls, expected, sz);
}
/* can also check type/proto_maj/proto_min here */
dbg("xhdr type:%d ver:%d.%d len:%d\n",
xhdr->type, xhdr->proto_maj, xhdr->proto_min,
0x100 * xhdr->len16_hi + xhdr->len16_lo
@@ -1137,13 +1144,11 @@ static void find_key_in_der_cert(tls_state_t *tls, uint8_t *der, int len)
static int tls_xread_handshake_block(tls_state_t *tls, int min_len)
{
struct record_hdr *xhdr;
int len = tls_xread_record(tls);
int len = tls_xread_record(tls, "handshake record");
xhdr = (void*)tls->inbuf;
if (len < min_len
|| xhdr->type != RECORD_TYPE_HANDSHAKE
|| xhdr->proto_maj != TLS_MAJ
|| xhdr->proto_min != TLS_MIN
) {
bad_record_die(tls, "handshake record", len);
}
@@ -1195,7 +1200,9 @@ static void send_client_hello_and_alloc_hsd(tls_state_t *tls, const char *sni)
// 0023 0000 - session_ticket
// 000a 0008 0006001700180019 - supported_groups
// 000b 0002 0100 - ec_point_formats
// 000d 0016 00140401040305010503060106030301030302010203 - signature_algorithms
// 000d 0016 0014 0401 0403 0501 0503 0601 0603 0301 0303 0201 0203 - signature_algorithms
// wolfssl library sends this option, RFC 7627 (closes a security weakness, some servers may require it. TODO?):
// 0017 0000 - extended master secret
};
struct client_hello *record;
int len;
@@ -1354,7 +1361,7 @@ static void get_server_cert(tls_state_t *tls)
xhdr = (void*)tls->inbuf;
certbuf = (void*)(xhdr + 1);
if (certbuf[0] != HANDSHAKE_CERTIFICATE)
tls_error_die(tls);
bad_record_die(tls, "certificate", len);
dbg("<< CERTIFICATE\n");
// 4392 bytes:
// 0b 00|11|24 00|11|21 00|05|b0 30|82|05|ac|30|82|04|94|a0|03|02|01|02|02|11|00|9f|85|bf|66|4b|0c|dd|af|ca|50|86|79|50|1b|2b|e4|30|0d...
@@ -1611,6 +1618,7 @@ void FAST_FUNC tls_handshake(tls_state_t *tls, const char *sni)
// <------- Finished
// Application Data <------> Application Data
int len;
int got_cert_req;
send_client_hello_and_alloc_hsd(tls, sni);
get_server_hello(tls);
@@ -1638,7 +1646,8 @@ void FAST_FUNC tls_handshake(tls_state_t *tls, const char *sni)
len = tls_xread_handshake_block(tls, 4);
}
if (tls->inbuf[RECHDR_LEN] == HANDSHAKE_CERTIFICATE_REQUEST) {
got_cert_req = (tls->inbuf[RECHDR_LEN] == HANDSHAKE_CERTIFICATE_REQUEST);
if (got_cert_req) {
dbg("<< CERTIFICATE_REQUEST\n");
// RFC 5246: "If no suitable certificate is available,
// the client MUST send a certificate message containing no
@@ -1647,7 +1656,9 @@ void FAST_FUNC tls_handshake(tls_state_t *tls, const char *sni)
// Client certificates are sent using the Certificate structure
// defined in Section 7.4.2."
// (i.e. the same format as server certs)
send_empty_client_cert(tls);
/*send_empty_client_cert(tls); - WRONG (breaks handshake hash calc) */
/* need to hash _all_ server replies first, up to ServerHelloDone */
len = tls_xread_handshake_block(tls, 4);
}
@@ -1657,6 +1668,9 @@ void FAST_FUNC tls_handshake(tls_state_t *tls, const char *sni)
// 0e 000000 (len:0)
dbg("<< SERVER_HELLO_DONE\n");
if (got_cert_req)
send_empty_client_cert(tls);
send_client_key_exchange(tls);
send_change_cipher_spec(tls);
@@ -1667,7 +1681,7 @@ void FAST_FUNC tls_handshake(tls_state_t *tls, const char *sni)
send_client_finished(tls);
/* Get CHANGE_CIPHER_SPEC */
len = tls_xread_record(tls);
len = tls_xread_record(tls, "switch to encrypted traffic");
if (len != 1 || memcmp(tls->inbuf, rec_CHANGE_CIPHER_SPEC, 6) != 0)
bad_record_die(tls, "switch to encrypted traffic", len);
dbg("<< CHANGE_CIPHER_SPEC\n");
@@ -1685,9 +1699,9 @@ void FAST_FUNC tls_handshake(tls_state_t *tls, const char *sni)
}
/* Get (encrypted) FINISHED from the server */
len = tls_xread_record(tls);
len = tls_xread_record(tls, "'server finished'");
if (len < 4 || tls->inbuf[RECHDR_LEN] != HANDSHAKE_FINISHED)
tls_error_die(tls);
bad_record_die(tls, "'server finished'", len);
dbg("<< FINISHED\n");
/* application data can be sent/received */
@@ -1763,7 +1777,7 @@ void FAST_FUNC tls_run_copy_loop(tls_state_t *tls)
if (pfds[1].revents) {
dbg("NETWORK HAS DATA\n");
read_record:
nread = tls_xread_record(tls);
nread = tls_xread_record(tls, "encrypted data");
if (nread < 1) {
/* TLS protocol has no real concept of one-sided shutdowns:
* if we get "TLS EOF" from the peer, writes will fail too
@@ -1775,7 +1789,7 @@ void FAST_FUNC tls_run_copy_loop(tls_state_t *tls)
break;
}
if (tls->inbuf[0] != RECORD_TYPE_APPLICATION_DATA)
bb_error_msg_and_die("unexpected record type %d", tls->inbuf[0]);
bad_record_die(tls, "encrypted data", nread);
xwrite(STDOUT_FILENO, tls->inbuf + RECHDR_LEN, nread);
/* We may already have a complete next record buffered,
* can process it without network reads (and possible blocking)
+4 -4
View File
@@ -277,11 +277,11 @@ static void option_to_env(uint8_t *option, uint8_t *option_end)
* | |
* +-+-+-+-+-+-+-+-+
*/
//move_from_unaligned32(v32, option + 4 + 4);
//*new_env() = xasprintf("lease=%u", (unsigned)v32);
move_from_unaligned32(v32, option + 4 + 4);
*new_env() = xasprintf("ipv6prefix_lease=%u", (unsigned)v32);
sprint_nip6(ipv6str, option + 4 + 4 + 1);
*new_env() = xasprintf("ipv6prefix=%s/%u", ipv6str, (unsigned)(option[4 + 4]));
sprint_nip6(ipv6str, option + 4 + 4 + 4 + 1);
*new_env() = xasprintf("ipv6prefix=%s/%u", ipv6str, (unsigned)(option[4 + 4 + 4]));
break;
#if ENABLE_FEATURE_UDHCPC6_RFC3646
case D6_OPT_DNS_SERVERS: {
+13 -6
View File
@@ -140,15 +140,22 @@ log message, you can use a pattern like this instead
//usage:#define svlogd_full_usage "\n\n"
//usage: "Read log data from stdin and write to rotated log files in DIRs"
//usage: "\n"
//usage: "\n""-r C Replace non-printable characters with C"
//usage: "\n""-R CHARS Also replace CHARS with C (default _)"
//usage: "\n""-t Timestamp with @tai64n"
//usage: "\n""-tt Timestamp with yyyy-mm-dd_hh:mm:ss.sssss"
//usage: "\n""-ttt Timestamp with yyyy-mm-ddThh:mm:ss.sssss"
//usage: "\n""-v Verbose"
//usage: "\n"
//usage: "\n""DIR/config file modifies behavior:"
//usage: "\n""sSIZE - when to rotate logs"
//usage: "\n""sSIZE - when to rotate logs (default 1000000, 0 disables)"
//usage: "\n""nNUM - number of files to retain"
/*usage: "\n""NNUM - min number files to retain" - confusing */
/*usage: "\n""tSEC - rotate file if it get SEC seconds old" - confusing */
///////: "\n""NNUM - min number files to retain" - confusing
///////: "\n""tSEC - rotate file if it get SEC seconds old" - confusing
//usage: "\n""!PROG - process rotated log with PROG"
/*usage: "\n""uIPADDR - send log over UDP" - unsupported */
/*usage: "\n""UIPADDR - send log over UDP and DONT log" - unsupported */
/*usage: "\n""pPFX - prefix each line with PFX" - unsupported */
///////: "\n""uIPADDR - send log over UDP" - unsupported
///////: "\n""UIPADDR - send log over UDP and DONT log" - unsupported
///////: "\n""pPFX - prefix each line with PFX" - unsupported
//usage: "\n""+,-PATTERN - (de)select line for logging"
//usage: "\n""E,ePATTERN - (de)select line for stderr"
+1 -1
View File
@@ -10858,7 +10858,7 @@ shiftcmd(int argc UNUSED_PARAM, char **argv)
if (argv[1])
n = number(argv[1]);
if (n > shellparam.nparam)
n = 0; /* bash compat, was = shellparam.nparam; */
return 1;
INT_OFF;
shellparam.nparam -= n;
for (ap1 = shellparam.p; --n >= 0; ap1++) {
+2 -2
View File
@@ -81,8 +81,8 @@ static struct mntent *getmntent_r(FILE* stream, struct mntent* result,
}
#endif
/* ignored: -v -t -i */
#define OPTION_STRING "fldnra" "vt:i"
/* ignored: -c -v -t -i */
#define OPTION_STRING "fldnra" "cvt:i"
#define OPT_FORCE (1 << 0) // Same as MNT_FORCE
#define OPT_LAZY (1 << 1) // Same as MNT_DETACH
#define OPT_FREELOOP (1 << 2)