From 6e6d8000a4694c3cea5b20404eadf4b7c137fd1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Fri, 21 Jan 2022 20:32:16 +0400 Subject: [PATCH 1/6] tests: remove old libtool workarounds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc-André Lureau --- glib/tests/option-argv0.c | 1 - glib/tests/spawn-multithreaded.c | 5 ----- glib/tests/spawn-singlethread.c | 5 ----- 3 files changed, 11 deletions(-) diff --git a/glib/tests/option-argv0.c b/glib/tests/option-argv0.c index 37ac44a9f..a18e68676 100644 --- a/glib/tests/option-argv0.c +++ b/glib/tests/option-argv0.c @@ -39,7 +39,6 @@ test_platform_argv0 (void) const gchar * const expected_prgnames[] = { "option-argv0", - "lt-option-argv0", #ifdef G_OS_WIN32 "option-argv0.exe", #endif diff --git a/glib/tests/spawn-multithreaded.c b/glib/tests/spawn-multithreaded.c index 614e503ca..69fffec11 100644 --- a/glib/tests/spawn-multithreaded.c +++ b/glib/tests/spawn-multithreaded.c @@ -384,11 +384,6 @@ main (int argc, dirname = g_path_get_dirname (argv[0]); echo_prog_path = g_build_filename (dirname, "test-spawn-echo" EXEEXT, NULL); - if (!g_file_test (echo_prog_path, G_FILE_TEST_EXISTS)) - { - g_free (echo_prog_path); - echo_prog_path = g_build_filename (dirname, "lt-test-spawn-echo" EXEEXT, NULL); - } g_free (dirname); g_assert (g_file_test (echo_prog_path, G_FILE_TEST_EXISTS)); diff --git a/glib/tests/spawn-singlethread.c b/glib/tests/spawn-singlethread.c index 7711ba8fe..b17b47237 100644 --- a/glib/tests/spawn-singlethread.c +++ b/glib/tests/spawn-singlethread.c @@ -505,11 +505,6 @@ main (int argc, dirname = g_path_get_dirname (argv[0]); echo_prog_path = g_build_filename (dirname, "test-spawn-echo" EXEEXT, NULL); - if (!g_file_test (echo_prog_path, G_FILE_TEST_EXISTS)) - { - g_free (echo_prog_path); - echo_prog_path = g_build_filename (dirname, "lt-test-spawn-echo" EXEEXT, NULL); - } echo_script_path = g_build_filename (dirname, "echo-script" SCRIPT_EXT, NULL); if (!g_file_test (echo_script_path, G_FILE_TEST_EXISTS)) { From 8bb73c2a743aed0eaff22b35c4979ce2ea687be0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Fri, 21 Jan 2022 20:41:18 +0400 Subject: [PATCH 2/6] tests: replace ipconfig call in spawn-multithread on win32 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use a silent command instead (tbh, I don't understand the need for this) Signed-off-by: Marc-André Lureau --- glib/tests/spawn-multithreaded.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/glib/tests/spawn-multithreaded.c b/glib/tests/spawn-multithreaded.c index 69fffec11..fc0bf9c6e 100644 --- a/glib/tests/spawn-multithreaded.c +++ b/glib/tests/spawn-multithreaded.c @@ -145,7 +145,7 @@ test_spawn_childs (void) global_main_loop = g_main_loop_new (NULL, FALSE); #ifdef G_OS_WIN32 - system ("ipconfig /all"); + system ("cd ."); #else system ("true"); #endif @@ -172,7 +172,7 @@ test_spawn_childs_threads (void) global_main_loop = g_main_loop_new (NULL, FALSE); #ifdef G_OS_WIN32 - system ("ipconfig /all"); + system ("cd ."); #else system ("true"); #endif From 2ebe30e170f612faf9c4a83371033b9b8111b271 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Fri, 21 Jan 2022 21:08:12 +0400 Subject: [PATCH 3/6] tests: fix spawn-multithreaded on win32 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add test-spawn-sleep helper program to sleep on Windows (child-test removed in commit 241b9f41b, probably breaking the test) (fwiw, Windows has a timeout command nowadays, but it conflicts with msys2 timeout which has different usage) Signed-off-by: Marc-André Lureau --- glib/tests/meson.build | 10 ++++++++++ glib/tests/spawn-multithreaded.c | 14 ++++++++------ glib/tests/test-spawn-sleep.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 glib/tests/test-spawn-sleep.c diff --git a/glib/tests/meson.build b/glib/tests/meson.build index 9150f3f44..dc6b095d8 100644 --- a/glib/tests/meson.build +++ b/glib/tests/meson.build @@ -267,6 +267,16 @@ executable('test-spawn-echo', 'test-spawn-echo.c', install: installed_tests_enabled, ) +if host_machine.system() == 'windows' + # test-spawn-sleep helper binary required by the spawn tests above + executable('test-spawn-sleep', 'test-spawn-sleep.c', + c_args : test_cargs, + dependencies : test_deps, + install_dir: installed_tests_execdir, + install: installed_tests_enabled, + ) +endif + executable('testing-helper', 'testing-helper.c', c_args : test_cargs, dependencies : test_deps, diff --git a/glib/tests/spawn-multithreaded.c b/glib/tests/spawn-multithreaded.c index fc0bf9c6e..c73a23433 100644 --- a/glib/tests/spawn-multithreaded.c +++ b/glib/tests/spawn-multithreaded.c @@ -31,6 +31,7 @@ #include static char *echo_prog_path; +static char *sleep_prog_path; #ifdef G_OS_UNIX #include @@ -43,10 +44,6 @@ static char *echo_prog_path; static GMainLoop *global_main_loop; static guint alive; -#ifdef G_OS_WIN32 -static char *argv0; -#endif - static GPid get_a_child (gint ttl) { @@ -61,9 +58,9 @@ get_a_child (gint ttl) si.cb = sizeof (&si); memset (&pi, 0, sizeof (pi)); - cmdline = g_strdup_printf ("child-test -c%d", ttl); + cmdline = g_strdup_printf ("%s %d", sleep_prog_path, ttl); - if (!CreateProcess (argv0, cmdline, NULL, NULL, + if (!CreateProcess (NULL, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) g_error ("CreateProcess failed: %s", g_win32_error_message (GetLastError ())); @@ -384,9 +381,13 @@ main (int argc, dirname = g_path_get_dirname (argv[0]); echo_prog_path = g_build_filename (dirname, "test-spawn-echo" EXEEXT, NULL); + sleep_prog_path = g_build_filename (dirname, "test-spawn-sleep" EXEEXT, NULL); g_free (dirname); g_assert (g_file_test (echo_prog_path, G_FILE_TEST_EXISTS)); +#ifdef G_OS_WIN32 + g_assert (g_file_test (sleep_prog_path, G_FILE_TEST_EXISTS)); +#endif g_test_add_func ("/gthread/spawn-childs", test_spawn_childs); g_test_add_func ("/gthread/spawn-childs-threads", test_spawn_childs_threads); @@ -396,6 +397,7 @@ main (int argc, ret = g_test_run(); g_free (echo_prog_path); + g_free (sleep_prog_path); return ret; } diff --git a/glib/tests/test-spawn-sleep.c b/glib/tests/test-spawn-sleep.c new file mode 100644 index 000000000..34dfd5bd9 --- /dev/null +++ b/glib/tests/test-spawn-sleep.c @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2022 Red Hat, Inc. + * + * This work is provided "as is"; redistribution and modification + * in whole or in part, in any medium, physical or electronic is + * permitted without restriction. + * + * This work is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * In no event shall the authors or contributors be liable for any + * direct, indirect, incidental, special, exemplary, or consequential + * damages (including, but not limited to, procurement of substitute + * goods or services; loss of use, data, or profits; or business + * interruption) however caused and on any theory of liability, whether + * in contract, strict liability, or tort (including negligence or + * otherwise) arising in any way out of the use of this software, even + * if advised of the possibility of such damage. + */ +#include "config.h" + +#include +#include "glib.h" + +int +main (int argc, + char *argv[]) +{ + g_usleep (atoi (argv[1]) * G_USEC_PER_SEC); + return 0; +} From 68aff6dd0713b2663293bce975f0291e2830ed30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 3 Feb 2022 19:55:34 +0400 Subject: [PATCH 4/6] glib/spawn-win32: workaround SEGV on spawnvpe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I haven't been able to write a reproducer yet and report the bug to Microsoft, but this is 100% crashing when running "meson test gsubprocess" Signed-off-by: Marc-André Lureau --- glib/gspawn-win32.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/glib/gspawn-win32.c b/glib/gspawn-win32.c index 30812dba6..fc2a96c94 100644 --- a/glib/gspawn-win32.c +++ b/glib/gspawn-win32.c @@ -637,6 +637,13 @@ fork_exec (gint *exit_status, argc = protect_argv (argv, &protected_argv); + /* + * FIXME: Workaround broken spawnvpe functions that SEGV when "=X:=" + * environment variables are missing. Calling chdir() will set the magic + * environment variable again. + */ + _chdir ("."); + if (stdin_fd == -1 && stdout_fd == -1 && stderr_fd == -1 && (flags & G_SPAWN_CHILD_INHERITS_STDIN) && !(flags & G_SPAWN_STDOUT_TO_DEV_NULL) && From 2583a66ee7a6104b774444c9d6264c9b7cd77950 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Wed, 16 Feb 2022 02:56:00 +0400 Subject: [PATCH 5/6] tests: skip spawn-path-search tests on win32 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Manipulating PATH the way the test does, it breaks DLL lookups and fails to run helper programs. Signed-off-by: Marc-André Lureau --- glib/tests/spawn-path-search.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/glib/tests/spawn-path-search.c b/glib/tests/spawn-path-search.c index 2a8911139..5008fc960 100644 --- a/glib/tests/spawn-path-search.c +++ b/glib/tests/spawn-path-search.c @@ -23,6 +23,17 @@ #include #endif +static gboolean +skip_win32 (void) +{ +#ifdef G_OS_WIN32 + g_test_skip ("The test manipulate PATH, and breaks DLL lookups."); + return TRUE; +#else + return FALSE; +#endif +} + static void test_do_not_search (void) { @@ -38,6 +49,9 @@ test_do_not_search (void) g_test_summary ("Without G_SPAWN_SEARCH_PATH, spawn-test-helper " "means ./spawn-test-helper."); + if (skip_win32 ()) + return; + envp = g_environ_setenv (envp, "PATH", subdir, TRUE); g_ptr_array_add (argv, @@ -90,6 +104,9 @@ test_search_path (void) g_test_summary ("With G_SPAWN_SEARCH_PATH, spawn-test-helper " "means $PATH/spawn-test-helper."); + if (skip_win32 ()) + return; + envp = g_environ_setenv (envp, "PATH", subdir, TRUE); g_ptr_array_add (argv, @@ -143,6 +160,9 @@ test_search_path_from_envp (void) g_test_summary ("With G_SPAWN_SEARCH_PATH_FROM_ENVP, spawn-test-helper " "means $PATH/spawn-test-helper with $PATH from envp."); + if (skip_win32 ()) + return; + envp = g_environ_setenv (envp, "PATH", here, TRUE); g_ptr_array_add (argv, @@ -198,6 +218,9 @@ test_search_path_ambiguous (void) g_test_summary ("With G_SPAWN_SEARCH_PATH and G_SPAWN_SEARCH_PATH_FROM_ENVP, " "the latter wins."); + if (skip_win32 ()) + return; + envp = g_environ_setenv (envp, "PATH", here, TRUE); g_ptr_array_add (argv, @@ -252,6 +275,10 @@ test_search_path_fallback_in_environ (void) int wait_status = -1; g_test_summary ("With G_SPAWN_SEARCH_PATH but no PATH, a fallback is used."); + + if (skip_win32 ()) + return; + /* We can't make a meaningful assertion about what the fallback *is*, * but we can assert that it *includes* the current working directory. */ @@ -319,6 +346,9 @@ test_search_path_fallback_in_envp (void) /* We can't make a meaningful assertion about what the fallback *is*, * but we can assert that it *includes* the current working directory. */ + if (skip_win32 ()) + return; + if (g_file_test ("/usr/bin/spawn-test-helper", G_FILE_TEST_IS_EXECUTABLE) || g_file_test ("/bin/spawn-test-helper", G_FILE_TEST_IS_EXECUTABLE)) { @@ -384,6 +414,9 @@ test_search_path_heap_allocation (void) int wait_status = -1; gsize i; + if (skip_win32 ()) + return; + memset (placeholder, '_', sizeof (placeholder)); /* Force search_path_buffer to be heap-allocated */ long_dir = g_test_build_filename (G_TEST_BUILT, "path-test-subdir", placeholder, NULL); From 0f85eefb8b3601d2b5d23b36c09a0184f6b18d94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Wed, 16 Feb 2022 18:50:17 +0400 Subject: [PATCH 6/6] gio: fix OOB string access if filename is empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc-André Lureau --- gio/gcontenttype.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gio/gcontenttype.c b/gio/gcontenttype.c index 3e5b841ab..3c9522bc6 100644 --- a/gio/gcontenttype.c +++ b/gio/gcontenttype.c @@ -780,7 +780,7 @@ g_content_type_guess (const gchar *filename, if (filename) { i = strlen (filename); - if (filename[i - 1] == '/') + if (i > 0 && filename[i - 1] == '/') { name_mimetypes[0] = "inode/directory"; name_mimetypes[1] = NULL;