summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2024-02-26 09:59:08 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2024-02-26 09:59:08 +0100
commit2acbac8ef9d314b73fbbd68c2e70580988c063a9 (patch)
tree9d134169add19bb6fd752f460c6afaf16ac1310b /src
parenteece9692d707ccb20356ec06955f8308c4e59ca7 (diff)
New upstream version 4.23upstream/4.23upstream
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am3
-rw-r--r--src/Makefile.in16
-rw-r--r--src/io.c43
-rw-r--r--src/rand.c4
-rw-r--r--src/socket.c6
-rw-r--r--src/string.c2
-rw-r--r--src/tc-socket.c4
7 files changed, 62 insertions, 16 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 676cd73..11a240e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -13,6 +13,9 @@ libHX_la_LDFLAGS = -no-undefined -version-info 39:0:7
if WITH_GNU_LD
libHX_la_LDFLAGS += -Wl,--version-script=${srcdir}/libHX.map
endif
+if WITH_SUN_LD
+libHX_la_LDFLAGS += -Wl,-M,${srcdir}/libHX.map
+endif
EXTRA_libHX_la_DEPENDENCIES = libHX.map
if MINGW32
diff --git a/src/Makefile.in b/src/Makefile.in
index 7e1bd81..22766b5 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -91,8 +91,9 @@ POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
@WITH_GNU_LD_TRUE@am__append_1 = -Wl,--version-script=${srcdir}/libHX.map
-@MINGW32_TRUE@am__append_2 = ux-file.c ux-mmap.c
-@MINGW32_TRUE@am__append_3 = -lws2_32
+@WITH_SUN_LD_TRUE@am__append_2 = -Wl,-M,${srcdir}/libHX.map
+@MINGW32_TRUE@am__append_3 = ux-file.c ux-mmap.c
+@MINGW32_TRUE@am__append_4 = -lws2_32
check_PROGRAMS = tc-compile$(EXEEXT) tc-cast$(EXEEXT) \
tc-deque$(EXEEXT) tc-dir$(EXEEXT) tc-format$(EXEEXT) \
tc-io$(EXEEXT) tc-list$(EXEEXT) tc-list2$(EXEEXT) \
@@ -104,13 +105,13 @@ check_PROGRAMS = tc-compile$(EXEEXT) tc-cast$(EXEEXT) \
$(am__EXEEXT_1)
TESTS = tc-format$(EXEEXT) tc-option$(EXEEXT) tc-strchr2$(EXEEXT) \
tc-string$(EXEEXT) tc-strquote$(EXEEXT) $(am__EXEEXT_2)
-@HAVE_CXX_TRUE@am__append_4 = tx-compile tx-cast tx-deque tx-dir \
+@HAVE_CXX_TRUE@am__append_5 = tx-compile tx-cast tx-deque tx-dir \
@HAVE_CXX_TRUE@ tx-intdiff tx-list tx-list2 \
@HAVE_CXX_TRUE@ tx-misc tx-netio \
@HAVE_CXX_TRUE@ tx-option tx-proc tx-rand tx-strchr2 tx-string \
@HAVE_CXX_TRUE@ tx-strquote tx-time
-@HAVE_CXX_TRUE@am__append_5 = tx-strchr2 tx-strquote
+@HAVE_CXX_TRUE@am__append_6 = tx-strchr2 tx-strquote
subdir = src
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/gcc4_visibility.m4 \
@@ -767,10 +768,11 @@ AM_CFLAGS = ${regular_CFLAGS}
AM_CXXFLAGS = ${regular_CXXFLAGS}
lib_LTLIBRARIES = libHX.la
libHX_la_SOURCES = deque.c dl.c format.c io.c map.c mc.c misc.c opt.c \
- proc.c rand.c socket.c string.c time.c $(am__append_2)
+ proc.c rand.c socket.c string.c time.c $(am__append_3)
libHX_la_LIBADD = ${libdl_LIBS} -lm ${libpthread_LIBS} ${librt_LIBS} \
- ${libsocket_LIBS} $(am__append_3)
-libHX_la_LDFLAGS = -no-undefined -version-info 39:0:7 $(am__append_1)
+ ${libsocket_LIBS} $(am__append_4)
+libHX_la_LDFLAGS = -no-undefined -version-info 39:0:7 $(am__append_1) \
+ $(am__append_2)
EXTRA_libHX_la_DEPENDENCIES = libHX.map
EXTRA_DIST = internal.h map_int.h libHX.map uxcompat.h analyze.sh
tc_cast_CFLAGS = ${AM_CFLAGS} -std=gnu99
diff --git a/src/io.c b/src/io.c
index ee48dee..9199d03 100644
--- a/src/io.c
+++ b/src/io.c
@@ -7,6 +7,7 @@
* General Public License as published by the Free Software Foundation;
* either version 2.1 or (at your option) any later version.
*/
+#define _GNU_SOURCE 1
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
@@ -630,15 +631,37 @@ EXPORT_SYMBOL ssize_t HXio_fullwrite(int fd, const void *vbuf, size_t size)
}
#if __linux__
-static ssize_t HX_sendfile_linux(int dst, int src, size_t count)
+#ifdef HAVE_COPY_FILE_RANGE
+static ssize_t HX_cfr_linux(int dst, int src, size_t count)
{
- long pagesize = sysconf(_SC_PAGE_SIZE);
- size_t xfersize;
ssize_t ret, xferd = 0;
+ /*
+ * Use INT(32)_MAX rather than SSIZE_MAX, as there is an issue with
+ * overflow detection pending.
+ * https://lore.kernel.org/linux-man/38nr2286-1o9q-0004-2323-799587773o15@vanv.qr/
+ */
+ size_t xfersize = INT_MAX;
+ if (count > xfersize)
+ count = xfersize;
+ while ((ret = copy_file_range(src, nullptr, dst, nullptr, count, 0)) > 0)
+ xferd += ret;
+ if (xferd > 0)
+ return xferd;
+ if (ret < 0)
+ return -errno;
+ return 0;
+}
+#endif
- if (pagesize < 0)
- pagesize = 4096;
- xfersize = SSIZE_MAX - pagesize;
+static ssize_t HX_sendfile_linux(int dst, int src, size_t count)
+{
+ ssize_t ret, xferd = 0;
+ /*
+ * Use INT(32)_MAX rather than SSIZE_MAX, as there is an issue with
+ * overflow detection pending.
+ * https://lore.kernel.org/linux-man/38nr2286-1o9q-0004-2323-799587773o15@vanv.qr/
+ */
+ size_t xfersize = INT_MAX;
if (count > xfersize)
count = xfersize;
while ((ret = sendfile(dst, src, nullptr, count)) > 0)
@@ -686,7 +709,13 @@ static ssize_t HX_sendfile_rw(int dst, int src, size_t count)
EXPORT_SYMBOL ssize_t HX_sendfile(int dst, int src, size_t count)
{
#if __linux__
- ssize_t ret = HX_sendfile_linux(dst, src, count);
+ ssize_t ret;
+#ifdef HAVE_COPY_FILE_RANGE
+ ret = HX_cfr_linux(dst, src, count);
+ if (ret != -ENOSYS && ret != -EXDEV)
+ return ret;
+#endif
+ ret = HX_sendfile_linux(dst, src, count);
if (ret != -ENOSYS)
return ret;
#endif
diff --git a/src/rand.c b/src/rand.c
index 498d4a5..3247b69 100644
--- a/src/rand.c
+++ b/src/rand.c
@@ -18,6 +18,10 @@
#ifdef __unix__
# include <unistd.h>
#endif
+#ifdef __APPLE__
+# include <sys/types.h>
+# include <unistd.h>
+#endif
#ifdef _WIN32
# include <process.h>
#endif
diff --git a/src/socket.c b/src/socket.c
index 9fdd903..fe813f5 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -41,7 +41,7 @@
#else
# define STUPIDWIN(x) (x)
#endif
-#if defined(__sun) && !defined(SO_PROTOCOL)
+#if defined(__sun) && !defined(SO_PROTOCOL) && defined(SO_PROTOTYPE)
# define SO_PROTOCOL SO_PROTOTYPE
#endif
#ifndef AI_V4MAPPED
@@ -333,18 +333,22 @@ static int try_sk_from_env(int fd, const struct addrinfo *ai, const char *intf)
return -1;
#else
optlen = sizeof(value);
+#ifdef SO_DOMAIN
ret = getsockopt(fd, SOL_SOCKET, SO_DOMAIN, &value, &optlen);
if (ret < 0 || value != ai->ai_family)
return -1;
+#endif
optlen = sizeof(value);
ret = getsockopt(fd, SOL_SOCKET, SO_TYPE, &value, &optlen);
if (ret < 0 || value != ai->ai_socktype)
return -1;
optlen = sizeof(value);
+#ifdef SO_PROTOCOL
ret = getsockopt(fd, SOL_SOCKET, SO_PROTOCOL, &value, &optlen);
if (ret < 0 || value != ai->ai_protocol)
return -1;
#endif
+#endif
struct sockaddr_storage addr;
memset(&addr, 0, sizeof(addr));
optlen = sizeof(addr);
diff --git a/src/string.c b/src/string.c
index 06066ce..e468063 100644
--- a/src/string.c
+++ b/src/string.c
@@ -1036,7 +1036,7 @@ EXPORT_SYMBOL unsigned long long HX_strtoull_unit(const char *s,
* UB. Thus check for range and apply the negation after the
* conversion to ULL.
*/
- if (q > ULLONG_MAX) {
+ if (q >= static_cast(double, ULLONG_MAX)) {
errno = ERANGE;
return ULLONG_MAX;
}
diff --git a/src/tc-socket.c b/src/tc-socket.c
index 3cdeb90..2c140a1 100644
--- a/src/tc-socket.c
+++ b/src/tc-socket.c
@@ -17,6 +17,7 @@
static int t_parse(void)
{
char host[32] = "bogus";
+ uint16_t port = 4321;
if (HX_addrport_split("[::1]", host, sizeof(host), nullptr) != 1 ||
strcmp(host, "::1") != 0)
return 1;
@@ -26,6 +27,9 @@ static int t_parse(void)
if (HX_addrport_split("", host, sizeof(host), nullptr) != 1 ||
strcmp(host, "") != 0)
return 1;
+ if (HX_addrport_split("[]:", host, sizeof(host), &port) != 1 ||
+ strcmp(host, "") != 0 || port != 0)
+ return 1;
return 0;
}