From 844f76dbedc693388ee52cdd5cf9c09f809f84a0 Mon Sep 17 00:00:00 2001 From: wangkerong Date: Thu, 16 Dec 2021 15:11:02 +0800 Subject: [PATCH] fix testcase failure --- ...ix-expectations-when-running-as-root.patch | 154 ++++++++++++++++++ glib2.spec | 6 +- 2 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 backport-fix-expectations-when-running-as-root.patch diff --git a/backport-fix-expectations-when-running-as-root.patch b/backport-fix-expectations-when-running-as-root.patch new file mode 100644 index 0000000..131b7db --- /dev/null +++ b/backport-fix-expectations-when-running-as-root.patch @@ -0,0 +1,154 @@ +From 087fdf86a6041709ae37b43cde4ddc4a8c925b8d Mon Sep 17 00:00:00 2001 +From: Simon McVittie +Date: Wed, 28 Oct 2020 09:49:32 +0000 +Subject: [PATCH] glib/tests/fileutils: Fix expectations when running as root + +This test asserts that g_file_set_contents_full() will fail when used +on a read-only file, but processes with CAP_DAC_OVERRIDE on Linux or +uid 0 on traditional Unix can and do ignore DAC permissions. +See also #2027, #2028. + +Bug-Debian: https://bugs.debian.org/973271 +Signed-off-by: Simon McVittie + +Reference:https://gitlab.gnome.org/GNOME/glib/-/commit/087fdf86a6041709ae37b43cde4ddc4a8c925b8d +--- + glib/tests/fileutils.c | 64 ++++++++++++++++++++++++++++++++++++------ + 1 file changed, 56 insertions(+), 8 deletions(-) + +diff --git a/glib/tests/fileutils.c b/glib/tests/fileutils.c +index 4baedf6..f4b30a1 100644 +--- a/glib/tests/fileutils.c ++++ b/glib/tests/fileutils.c +@@ -524,10 +524,10 @@ test_mkdir_with_parents (void) + g_assert_cmpint (errno, ==, EINVAL); + } + +-#ifdef G_OS_UNIX + /* + * check_cap_dac_override: +- * @tmpdir: A temporary directory in which we can create and delete files ++ * @tmpdir: (nullable): A temporary directory in which we can create ++ * and delete files. If %NULL, use the g_get_tmp_dir(), safely. + * + * Check whether the current process can bypass DAC permissions. + * +@@ -550,10 +550,29 @@ test_mkdir_with_parents (void) + static gboolean + check_cap_dac_override (const char *tmpdir) + { ++#ifdef G_OS_UNIX ++ gchar *safe_tmpdir = NULL; + gchar *dac_denies_write; + gchar *inside; + gboolean have_cap; + ++ if (tmpdir == NULL) ++ { ++ /* It's unsafe to write predictable filenames into g_get_tmp_dir(), ++ * because it's usually a shared directory that can be subject to ++ * symlink attacks, so use a subdirectory for this check. */ ++ GError *error = NULL; ++ ++ safe_tmpdir = g_dir_make_tmp (NULL, &error); ++ g_assert_no_error (error); ++ g_clear_error (&error); ++ ++ if (safe_tmpdir == NULL) ++ return FALSE; ++ ++ tmpdir = safe_tmpdir; ++ } ++ + dac_denies_write = g_build_filename (tmpdir, "dac-denies-write", NULL); + inside = g_build_filename (dac_denies_write, "inside", NULL); + +@@ -577,11 +596,18 @@ check_cap_dac_override (const char *tmpdir) + + g_assert_cmpint (chmod (dac_denies_write, S_IRWXU) == 0 ? 0 : errno, ==, 0); + g_assert_cmpint (rmdir (dac_denies_write) == 0 ? 0 : errno, ==, 0); ++ ++ if (safe_tmpdir != NULL) ++ g_assert_no_errno (rmdir (safe_tmpdir)); ++ + g_free (dac_denies_write); + g_free (inside); ++ g_free (safe_tmpdir); + return have_cap; +-} ++#else ++ return FALSE; + #endif ++} + + /* Reproducer for https://gitlab.gnome.org/GNOME/glib/issues/1852 */ + static void +@@ -1132,6 +1158,7 @@ test_set_contents_full_read_only_file (void) + GError *error = NULL; + gchar *file_name = NULL; + gboolean ret; ++ gboolean can_override_dac = check_cap_dac_override (NULL); + + g_test_summary ("Test g_file_set_contents_full() on a read-only file"); + +@@ -1147,8 +1174,18 @@ test_set_contents_full_read_only_file (void) + + /* Set the file contents */ + ret = g_file_set_contents_full (file_name, "b", 1, G_FILE_SET_CONTENTS_NONE, 0644, &error); +- g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_ACCES); +- g_assert_false (ret); ++ ++ if (can_override_dac) ++ { ++ g_assert_no_error (error); ++ g_assert_true (ret); ++ } ++ else ++ { ++ g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_ACCES); ++ g_assert_false (ret); ++ } ++ + g_clear_error (&error); + + g_remove (file_name); +@@ -1174,11 +1211,13 @@ test_set_contents_full_read_only_directory (void) + gchar *dir_name = NULL; + gchar *file_name = NULL; + gboolean ret; ++ gboolean can_override_dac; + + g_test_message ("Flags %d", flags); + + dir_name = g_dir_make_tmp ("glib-file-set-contents-full-rodir-XXXXXX", &error); + g_assert_no_error (error); ++ can_override_dac = check_cap_dac_override (dir_name); + + file_name = g_build_filename (dir_name, "file", NULL); + fd = g_open (file_name, O_CREAT | O_RDWR, 0644); +@@ -1191,10 +1230,19 @@ test_set_contents_full_read_only_directory (void) + + /* Set the file contents */ + ret = g_file_set_contents_full (file_name, "b", 1, flags, 0644, &error); +- g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_ACCES); +- g_assert_false (ret); +- g_clear_error (&error); + ++ if (can_override_dac) ++ { ++ g_assert_no_error (error); ++ g_assert_true (ret); ++ } ++ else ++ { ++ g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_ACCES); ++ g_assert_false (ret); ++ } ++ ++ g_clear_error (&error); + g_remove (file_name); + g_unlink (dir_name); + +-- +2.27.0 + diff --git a/glib2.spec b/glib2.spec index 82d0a13..2ea257d 100644 --- a/glib2.spec +++ b/glib2.spec @@ -1,6 +1,6 @@ Name: glib2 Version: 2.66.8 -Release: 4 +Release: 5 Summary: The core library that forms the basis for projects such as GTK+ and GNOME License: LGPLv2+ URL: http://www.gtk.org @@ -20,6 +20,7 @@ Patch6009: backport-gdbusobjectmanagerservice-fix-leak-in-error-path.patch Patch6010: backport-gfileenumerator-fix-leak-in-error-path.patch Patch6011: backport-gsettings-Fix-a-minor-memory-leak-when-getting-GSettingsAction-state.patch Patch6012: backport-fix-a-memory-leak.patch +Patch6013: backport-fix-expectations-when-running-as-root.patch BuildRequires: chrpath gcc gcc-c++ gettext perl-interpreter %ifnarch i686 @@ -192,6 +193,9 @@ glib-compile-schemas %{_datadir}/glib-2.0/schemas &> /dev/null || : %endif %changelog +* Thu Dec 16 2021 wangkerong - 2.66.8-5 +- fixed the fileutils testcase failure when the rpmbuild -ba command is used to building + * Tue Sep 7 2021 fengtao - 2.66.8-4 - Type:bugfix - ID:NA -- Gitee