diff options
Diffstat (limited to 'net/echoping/files')
-rw-r--r-- | net/echoping/files/extra-patch-idn2-acinclude.m4 | 16 | ||||
-rw-r--r-- | net/echoping/files/extra-patch-idn2-configure.ac | 22 | ||||
-rw-r--r-- | net/echoping/files/extra-patch-idn2-echoping.c | 219 | ||||
-rw-r--r-- | net/echoping/files/extra-patch-idn2-echoping.h | 12 |
4 files changed, 269 insertions, 0 deletions
diff --git a/net/echoping/files/extra-patch-idn2-acinclude.m4 b/net/echoping/files/extra-patch-idn2-acinclude.m4 new file mode 100644 index 000000000000..8390d699d09d --- /dev/null +++ b/net/echoping/files/extra-patch-idn2-acinclude.m4 @@ -0,0 +1,16 @@ +--- acinclude.m4.orig 2019-12-29 17:14:41.000000000 +0700 ++++ acinclude.m4 2025-05-05 00:12:04.181029000 +0700 +@@ -166,6 +166,13 @@ + [AC_ERROR([Get the GNU libidn library (http://www.josefsson.org/libidn/) in order to use Unicode - multi-script - domain names or use --without-libidn to disable it])], dnl + )]) + ++AC_DEFUN([CF_LIB_LIBIDN2], ++[ ++AC_CHECK_LIB(idn2,idn2_to_ascii_8z, ++[LIBS="${LIBS} -lidn2"], ++[AC_ERROR([Get the GNU libidn2 library (https://www.gnu.org/software/libidn/) in order to use Unicode - multi-script - domain names or use --without-libidn2 to disable it])], dnl ++)]) ++ + # Check OpenSSL + AC_DEFUN([CF_LIB_OPENSSL], + [ diff --git a/net/echoping/files/extra-patch-idn2-configure.ac b/net/echoping/files/extra-patch-idn2-configure.ac new file mode 100644 index 000000000000..24a45a894ced --- /dev/null +++ b/net/echoping/files/extra-patch-idn2-configure.ac @@ -0,0 +1,22 @@ +--- configure.ac.orig 2019-12-29 17:14:41.000000000 +0700 ++++ configure.ac 2025-05-04 23:33:58.901840000 +0700 +@@ -61,8 +68,8 @@ + dnl IDN + dnl Default: enable it + LIBIDN=1 +-AC_ARG_WITH(libidn, +- [ --with-libidn[=DIR] Internationalized Domain Names support (needs GNU libidn)],dnl ++AC_ARG_WITH(libidn2, ++ [ --with-libidn2[=DIR] Internationalized Domain Names support (needs GNU libidn2)],dnl + [if test "$withval" != "no"; then + if test "$withval" != "yes"; then + IDNROOT=$withval +@@ -186,7 +193,7 @@ + [AC_MSG_ERROR([echoping requires dlopen (dynamic loading of libraries) for plugins])])]) + + if test "$LIBIDN" = "1"; then +-CF_LIB_LIBIDN ++CF_LIB_LIBIDN2 + fi + if test "$OPENSSL" = "1" && test "$GNUTLS" = "1"; then + AC_MSG_ERROR([Choose OpenSSL or GNU TLS but not both]) diff --git a/net/echoping/files/extra-patch-idn2-echoping.c b/net/echoping/files/extra-patch-idn2-echoping.c new file mode 100644 index 000000000000..e5a3ed3e1ffa --- /dev/null +++ b/net/echoping/files/extra-patch-idn2-echoping.c @@ -0,0 +1,219 @@ +--- echoping.c.orig 2025-05-05 00:28:45.988741000 +0700 ++++ echoping.c 2025-05-05 01:44:14.970048000 +0700 +@@ -9,6 +9,12 @@ + * + * */ + ++#include <iconv.h> ++#include <langinfo.h> ++#include <limits.h> ++#include <stdint.h> ++#include <strings.h> ++ + char *progname; + + #include "echoping.h" +@@ -54,6 +60,188 @@ static terminate_f plugin_terminate; + struct timeval null_timeval; + static struct timeval max_timeval; + ++#ifdef LIBIDN ++/* Basically stolen from libidn with small modifications */ ++ ++static char * _str_cd_iconv (const char *src, iconv_t cd); ++static char * _str_iconv (const char *src, const char *from_codeset, const char *to_codeset); ++ ++static char * ++_str_cd_iconv (const char *src, iconv_t cd) ++{ ++ char *result; ++ size_t result_size; ++ size_t length; ++ const char *inptr = src; ++ size_t inbytes_remaining = strlen (src); ++ ++ /* Make a guess for the worst-case output size, in order to avoid a ++ realloc. It's OK if the guess is wrong as long as it is not zero and ++ doesn't lead to an integer overflow. */ ++ result_size = inbytes_remaining; ++ { ++ size_t approx_sqrt_SIZE_MAX = SIZE_MAX >> (sizeof (size_t) * CHAR_BIT / 2); ++ if (result_size <= approx_sqrt_SIZE_MAX / MB_LEN_MAX) ++ result_size *= MB_LEN_MAX; ++ } ++ result_size += 1; /* for the terminating NUL */ ++ ++ result = (char *) malloc (result_size); ++ if (result == NULL) ++ { ++ errno = ENOMEM; ++ return NULL; ++ } ++ ++ /* Set to the initial state. */ ++ iconv (cd, NULL, NULL, NULL, NULL); ++ ++ /* Do the conversion. */ ++ { ++ char *outptr = result; ++ size_t outbytes_remaining = result_size - 1; ++ ++ for (;;) ++ { ++ /* Here inptr + inbytes_remaining = src + strlen (src), ++ outptr + outbytes_remaining = result + result_size - 1. */ ++ size_t res = iconv (cd, ++ &inptr, &inbytes_remaining, ++ &outptr, &outbytes_remaining); ++ ++ if (res == (size_t)(-1)) ++ { ++ if (errno == EINVAL) ++ break; ++ else if (errno == E2BIG) ++ { ++ size_t used = outptr - result; ++ size_t newsize = result_size * 2; ++ char *newresult; ++ ++ if (!(newsize > result_size)) ++ { ++ errno = ENOMEM; ++ goto failed; ++ } ++ newresult = (char *) realloc (result, newsize); ++ if (newresult == NULL) ++ { ++ errno = ENOMEM; ++ goto failed; ++ } ++ result = newresult; ++ result_size = newsize; ++ outptr = result + used; ++ outbytes_remaining = result_size - 1 - used; ++ } ++ else ++ goto failed; ++ } ++ else ++ break; ++ } ++ for (;;) ++ { ++ /* Here outptr + outbytes_remaining = result + result_size - 1. */ ++ size_t res = iconv (cd, NULL, NULL, &outptr, &outbytes_remaining); ++ ++ if (res == (size_t)(-1)) ++ { ++ if (errno == E2BIG) ++ { ++ size_t used = outptr - result; ++ size_t newsize = result_size * 2; ++ char *newresult; ++ ++ if (!(newsize > result_size)) ++ { ++ errno = ENOMEM; ++ goto failed; ++ } ++ newresult = (char *) realloc (result, newsize); ++ if (newresult == NULL) ++ { ++ errno = ENOMEM; ++ goto failed; ++ } ++ result = newresult; ++ result_size = newsize; ++ outptr = result + used; ++ outbytes_remaining = result_size - 1 - used; ++ } ++ else ++ goto failed; ++ } ++ else ++ break; ++ } ++ ++ /* Add the terminating NUL byte. */ ++ *outptr++ = '\0'; ++ ++ length = outptr - result; ++ } ++ ++ /* Give away unused memory. */ ++ if (length < result_size) ++ { ++ char *smaller_result = (char *) realloc (result, length); ++ ++ if (smaller_result != NULL) ++ result = smaller_result; ++ } ++ ++ return result; ++ ++ failed: ++ free (result); ++ return NULL; ++} ++ ++static char * ++_str_iconv (const char *src, const char *from_codeset, const char *to_codeset) ++{ ++ if (*src == '\0' || strcasecmp (from_codeset, to_codeset) == 0) ++ { ++ char *result = strdup (src); ++ ++ if (result == NULL) ++ errno = ENOMEM; ++ return result; ++ } ++ else ++ { ++ iconv_t cd; ++ char *result; ++ ++ cd = iconv_open (to_codeset, from_codeset); ++ if (cd == (iconv_t) -1) ++ return NULL; ++ ++ result = _str_cd_iconv (src, cd); ++ ++ if (result == NULL) ++ { ++ /* Close cd, but preserve the errno from str_cd_iconv. */ ++ int saved_errno = errno; ++ iconv_close (cd); ++ errno = saved_errno; ++ } ++ else ++ { ++ if (iconv_close (cd) < 0) ++ { ++ free (result); ++ return NULL; ++ } ++ } ++ return result; ++ } ++} ++ ++#endif ++ + int + main(argc, argv) + int argc; +@@ -561,12 +749,12 @@ main(argc, argv) + server = leftover[0]; + #ifdef LIBIDN + locale_server = server; +- utf8_server = stringprep_locale_to_utf8(server); ++ utf8_server = _str_iconv(server, nl_langinfo(CODESET), "UTF-8"); + if (utf8_server) + server = utf8_server; + else + err_quit("Cannot convert %s to UTF-8 encoding: wrong locale (%s)?", +- server, stringprep_locale_charset()); ++ server, nl_langinfo(CODESET)); + #endif + if (!http && !icp) { + for (p = server; *p && (*p != ':'); p++) { diff --git a/net/echoping/files/extra-patch-idn2-echoping.h b/net/echoping/files/extra-patch-idn2-echoping.h new file mode 100644 index 000000000000..d278434dc817 --- /dev/null +++ b/net/echoping/files/extra-patch-idn2-echoping.h @@ -0,0 +1,12 @@ +--- echoping.h.orig 2025-05-05 00:28:45.991560000 +0700 ++++ echoping.h 2025-05-05 01:41:01.729365000 +0700 +@@ -52,8 +52,7 @@ + #endif + + #ifdef LIBIDN +-#include <stringprep.h> /* stringprep_locale_to_utf8() */ +-#include <idna.h> /* idna_to_ascii_from_utf8() */ ++#include <idn2.h> /* idna_to_ascii_from_utf8() */ + #endif + + #ifndef FALSE |