-
-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement is_ip4() and is_ip6() to avoid network dependencies #228
Conversation
@rockdaboot I tested it in the meson CI matrix:
There are some additional problems in these logs, which are unelated to your change (i.e. problems with stock 0.21.5). @neheb probably should look into that, having expressed interest before:
|
Why avoid network dependencies? |
Why having network dependencies? They may be annoying if not really needed by an application. |
Thanks for testing @eli-schwartz
That has been my fear. GetACP() requires Windows.h (see https://learn.microsoft.com/en-us/windows/win32/api/winnls/nf-winnls-getacp).
Maybe we can get rid of that. Not sure if GetACP() needs it.
I can fix this. |
Here's a patch that may help (I've only given it a limited build test): diff --git a/src/psl.c b/src/psl.c
index 0168a68..9fdef85 100644
--- a/src/psl.c
+++ b/src/psl.c
@@ -47,6 +47,13 @@
#include <sys/types.h>
#include <sys/stat.h>
+#if defined(_WIN32) && (defined(WITH_LIBIDN2) || defined(WITH_LIBIDN))
+# ifndef WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+# endif
+# include <windows.h> /* for GetACP() */
+#endif
+
#if defined(_MSC_VER) && ! defined(ssize_t)
# include <basetsd.h>
typedef SSIZE_T ssize_t;
diff --git a/tests/test-is-cookie-domain-acceptable.c b/tests/test-is-cookie-domain-acceptable.c
index d58bd47..17b46c6 100644
--- a/tests/test-is-cookie-domain-acceptable.c
+++ b/tests/test-is-cookie-domain-acceptable.c
@@ -32,10 +32,6 @@
# include <config.h>
#endif
-#ifdef _WIN32
-# include <winsock2.h> // WSAStartup, WSACleanup
-#endif
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -113,18 +109,6 @@ static void test_psl(void)
int main(int argc, const char * const *argv)
{
-#ifdef _WIN32
- WSADATA wsa_data;
- int err;
-
- if ((err = WSAStartup(MAKEWORD(2,2), &wsa_data))) {
- printf("WSAStartup failed with error: %d\n", err);
- return 1;
- }
-
- atexit((void (__cdecl*)(void)) WSACleanup);
-#endif
-
/* if VALGRIND testing is enabled, we have to call ourselves with valgrind checking */
if (argc == 1) {
const char *valgrind = getenv("TESTS_VALGRIND");
diff --git a/tools/psl.c b/tools/psl.c
index 527d780..05b2560 100644
--- a/tools/psl.c
+++ b/tools/psl.c
@@ -37,10 +37,9 @@
#endif
#ifdef _WIN32
-# include <winsock2.h> // WSAStartup, WSACleanup
-
// Windows does not have localtime_r but has localtime_s, which is more or less
// the same except that the arguments are reversed
+# include <time.h>
# define LOCALTIME_R_SUCCESSFUL(t_sec,t_now) \
(localtime_s(t_now, t_sec) == 0)
#else
@@ -78,20 +77,6 @@ static void usage(int err, FILE* f)
exit(err);
}
-static void init_windows(void) {
-#ifdef _WIN32
- WSADATA wsa_data;
- int err;
-
- if ((err = WSAStartup(MAKEWORD(2,2), &wsa_data))) {
- printf("WSAStartup failed with error: %d\n", err);
- exit(EXIT_FAILURE);
- }
-
- atexit((void (__cdecl*)(void)) WSACleanup);
-#endif
-}
-
/* RFC 2822-compliant date format */
static const char *time2str(time_t t)
{
@@ -238,8 +223,6 @@ int main(int argc, const char *const *argv)
else if (mode == 4) {
char *cookie_domain_lower;
- init_windows();
-
if ((rc = psl_str_to_utf8lower(domain, NULL, NULL, &cookie_domain_lower)) == PSL_SUCCESS) {
if (!batch_mode)
printf("%s: ", domain);
@@ -284,8 +267,6 @@ int main(int argc, const char *const *argv)
}
}
else if (mode == 4) {
- init_windows();
-
for (; arg < argv + argc; arg++) {
if (!batch_mode)
printf("%s: ", *arg); |
Thank you @vszakats ! @eli-schwartz Pushed the removal of WSA code. When #231 is merged, I'll rebase this PR and ping you for another round of tests. |
a95821d
to
7d77063
Compare
@vszakats or someone else, could you test again building libpsl on Windows / Msys2 and running the tests? If tests fail, it would be interesting to see the log output from the failing tests. |
It works with msys2 and GCC, but fails with msys2 and clang:
|
@eli-schwartz Just to make sure, without the new Because if the first parameter to |
It's being run against the 0.21.5 release with:
|
I don't have an MSYS2 environment. Tried cross-building with autotools + llvm-mingw (v20231128) for x64 instead, which is close enough. Source was fe13dad + https://github.com/mesonbuild/wrapdb/blob/libpsl/subprojects/packagefiles/libpsl-winipv4.patch. The build first failed with:
Fixed it with this patch: --- a/src/psl.c
+++ b/src/psl.c
@@ -320,22 +334,13 @@ static int suffix_init(psl_entry_t *suffix, const char *rule, size_t length)
return 0;
}
-#ifndef HAVE_STRDUP
-static char *strdup(const char *s)
+static char *my_strdup(const char *s)
{
char *p = malloc(strlen(s) + 1);
if (!p)
return NULL;
return strcpy(p, s);
}
-#elif !HAVE_DECL_STRDUP
-/*
- * On Linux with
- * CC=gcc CFLAGS="-Wall -Wextra -Wpedantic -std=c89" ./configure
- * strdup isn't declared (warning: implicit declaration of function 'strdup').
- */
-char *strdup(const char *);
-#endif
#if !defined(WITH_LIBIDN) && !defined(WITH_LIBIDN2) && !defined(WITH_LIBICU)
/*
@@ -733,7 +738,7 @@ static int psl_idna_toASCII(psl_idna_t *idna, const char *utf8, char **ascii)
lookupname[bytes_written] = 0; /* u_strToUTF8() doesn't 0-terminate if dest is filled up */
} else {
- if (!(lookupname = strdup(lookupname)))
+ if (!(lookupname = my_strdup(lookupname)))
goto cleanup;
}
@@ -808,7 +813,7 @@ cleanup:
if (domain_to_punycode(utf8, lookupname, sizeof(lookupname)) == 0) {
if (ascii)
- if ((*ascii = strdup(lookupname)))
+ if ((*ascii = my_strdup(lookupname)))
ret = 0;
}
#endif
@@ -1758,7 +1763,7 @@ psl_error_t psl_str_to_utf8lower(const char *str, const char *encoding, const ch
if (lower) {
char *p, *tmp;
- if (!(tmp = strdup(str)))
+ if (!(tmp = my_strdup(str)))
return PSL_ERR_NO_MEM;
*lower = tmp;
@@ -1816,7 +1821,7 @@ psl_error_t psl_str_to_utf8lower(const char *str, const char *encoding, const ch
if (U_SUCCESS(status)) {
ret = PSL_SUCCESS;
if (lower) {
- char *tmp = strdup(utf8_lower);
+ char *tmp = my_strdup(utf8_lower);
if (tmp)
*lower = tmp; Then it failed to build tests when running Patched to skip fuzz tests: --- a/Makefile.am
+++ b/Makefile.am
@@ -8,7 +8,7 @@ if ENABLE_MAN
SUBDIRS += docs/libpsl
endif
endif
-SUBDIRS += fuzz tests msvc
+SUBDIRS += tests msvc
ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS} With this, tests built correctly, but they failed to execute due to the cross-build scenario.
Rest of tests run OK too, except I repeated the cross-build with stock llvm/clang (17.0.6) + mingw-w64 (11.0.1) both via Homebrew and the tests passed too:
The MSYS2 tests passing with UCRT64 but failing with CLANG64 seems unrelated to the winsock2 removal. (Sadly I have no idea what else may be the problem there.) |
7d77063
to
ecdeb35
Compare
The reason for the fuzz tests not building is likely a missing DLL (need to be added to LDADD in fuzz/Makefile.am), but can't test that anyway. With MinGW on Linux, it's not a problem (fuzz tests are SKIPped). Added |
Can someone please review, especially try compiling on Windows?
Fixes #226