[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#1034149: unblock: (pre-approval): glib2.0/2.74.6-2



Package: release.debian.org
Severity: normal
User: release.debian.org@packages.debian.org
Usertags: unblock
X-Debbugs-Cc: glib2.0@packages.debian.org
Control: affects -1 + src:glib2.0

I've been using this proposed glib2.0 update for a few days and I'd like
to upload it to unstable. There's nothing RC here, but it seems safer and
easier to do several small bugfix updates rather than one large one.

[ Reason ]
Pick up stable-branch changes from upstream, which are expected to be
released in 2.74.7 at some point.

[ Impact ]
If not accepted:
- Peer-to-peer D-Bus servers implemented with GLib, such as the ones in
  gvfs and ibus, won't interoperate properly with sd-bus clients
  (GNOME/glib#2916)
- Some multi-threaded uses of GDBus will have a use-after-free
  (GNOME/glib#2924)
- glib2.0 will FTBFS in non-minimal Docker containers (GNOME/glib#3307)

[ Tests ]
Automated tests continue to pass, and I've been using this version on my
laptop for several days. There is no specific test coverage for the changes.

[ Risks ]
High-visibility key package, but the changes are narrowly targeted.

[ Checklist ]
  [x] all changes are documented in the d/changelog
  [x] I reviewed all changes and I approve them
  [x] attach debdiff against the package in testing

unblock glib2.0/2.74.6-2
diffstat for glib2.0-2.74.6 glib2.0-2.74.6

 debian/changelog                                                               |   13 
 debian/patches/gdbus-Fix-an-accidental-string-freeze-break.patch               |   31 ++
 debian/patches/gdbus-Never-buffer-reads-during-server-authentication.patch     |  141 ++++++++++
 debian/patches/gdbusconnection-Make-GDBusMethodInvocation-transfer-a-bit.patch |   28 +
 debian/patches/gdbusinterfaceskeleton-Fix-a-use-after-free-of-a-GDBusMet.patch |   58 ++++
 debian/patches/gdbusinterfaceskeleton-Remove-an-unnecessary-helper-struc.patch |   83 +++++
 debian/patches/series                                                          |    6 
 debian/patches/tests-Skip-assert-msg-test.py-if-gdb-fails.patch                |   34 ++
 gio/gdbusauth.c                                                                |   50 ++-
 gio/gdbusconnection.c                                                          |    2 
 gio/gdbusinterfaceskeleton.c                                                   |   24 -
 glib/tests/assert-msg-test.py                                                  |    6 
 12 files changed, 442 insertions(+), 34 deletions(-)

diff -Nru glib2.0-2.74.6/debian/changelog glib2.0-2.74.6/debian/changelog
--- glib2.0-2.74.6/debian/changelog	2023-03-02 20:53:53.000000000 +0000
+++ glib2.0-2.74.6/debian/changelog	2023-04-04 09:55:32.000000000 +0100
@@ -1,3 +1,16 @@
+glib2.0 (2.74.6-2) unstable; urgency=medium
+
+  * d/patches: Update to upstream 2.74.x branch commit
+    2.74.6-12-ga1e169129, omitting Windows-specific changes
+    - Fix GDBus server interop with sd-bus clients (GNOME/glib#2916)
+    - Fix use-after-free of a GDBusMethodInvocation in some threaded
+      use patterns (GNOME/glib#2924)
+    - Fix a test failure resulting in FTBFS in some container environments
+      if gdb happens to be installed, but access to ptrace and
+      /proc/PID/mem is disallowed (GNOME/glib#3307)
+
+ -- Simon McVittie <smcv@debian.org>  Tue, 04 Apr 2023 09:55:32 +0100
+
 glib2.0 (2.74.6-1) unstable; urgency=medium
 
   * New upstream stable release
diff -Nru glib2.0-2.74.6/debian/patches/gdbusconnection-Make-GDBusMethodInvocation-transfer-a-bit.patch glib2.0-2.74.6/debian/patches/gdbusconnection-Make-GDBusMethodInvocation-transfer-a-bit.patch
--- glib2.0-2.74.6/debian/patches/gdbusconnection-Make-GDBusMethodInvocation-transfer-a-bit.patch	1970-01-01 01:00:00.000000000 +0100
+++ glib2.0-2.74.6/debian/patches/gdbusconnection-Make-GDBusMethodInvocation-transfer-a-bit.patch	2023-04-04 09:55:32.000000000 +0100
@@ -0,0 +1,28 @@
+From: Philip Withnall <pwithnall@endlessos.org>
+Date: Wed, 22 Feb 2023 12:50:10 +0000
+Subject: gdbusconnection: Make GDBusMethodInvocation transfer a bit clearer
+
+Add a missing steal call in `schedule_method_call()`. This introduces no
+functional changes, but documents the ownership transfer more clearly.
+
+Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
+Bug: https://gitlab.gnome.org/GNOME/glib/-/issues/2924
+Origin: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3298
+Applied-upstream: 2.74.7, commit:2da9ca2727a559a5e6b517582d14ba05d963f603
+---
+ gio/gdbusconnection.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/gio/gdbusconnection.c b/gio/gdbusconnection.c
+index 663cd95..368898d 100644
+--- a/gio/gdbusconnection.c
++++ b/gio/gdbusconnection.c
+@@ -5048,7 +5048,7 @@ schedule_method_call (GDBusConnection            *connection,
+   g_source_set_priority (idle_source, G_PRIORITY_DEFAULT);
+   g_source_set_callback (idle_source,
+                          call_in_idle_cb,
+-                         invocation,
++                         g_steal_pointer (&invocation),
+                          g_object_unref);
+   g_source_set_static_name (idle_source, "[gio, " __FILE__ "] call_in_idle_cb");
+   g_source_attach (idle_source, main_context);
diff -Nru glib2.0-2.74.6/debian/patches/gdbus-Fix-an-accidental-string-freeze-break.patch glib2.0-2.74.6/debian/patches/gdbus-Fix-an-accidental-string-freeze-break.patch
--- glib2.0-2.74.6/debian/patches/gdbus-Fix-an-accidental-string-freeze-break.patch	1970-01-01 01:00:00.000000000 +0100
+++ glib2.0-2.74.6/debian/patches/gdbus-Fix-an-accidental-string-freeze-break.patch	2023-04-04 09:55:32.000000000 +0100
@@ -0,0 +1,31 @@
+From: Philip Withnall <pwithnall@endlessos.org>
+Date: Thu, 2 Mar 2023 12:37:48 +0000
+Subject: gdbus: Fix an accidental string freeze break
+
+Commit d982c8607 accidentally broke the string freeze on `glib-2-74` by
+adding a new translatable string.
+
+We can avoid that by reusing an existing string which has a similar
+meaning.
+
+Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
+Bug: https://gitlab.gnome.org/Teams/Translation/Coordination/-/issues/47
+Origin: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3303
+Applied-upstream: 2.74.7, commit:be83335ecae64b0cd7a133966eba42e803cf8695
+---
+ gio/gdbusauth.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/gio/gdbusauth.c b/gio/gdbusauth.c
+index b52a06e..455484d 100644
+--- a/gio/gdbusauth.c
++++ b/gio/gdbusauth.c
+@@ -1042,7 +1042,7 @@ _g_dbus_auth_run_server (GDBusAuth              *auth,
+             g_set_error_literal (error,
+                                  G_IO_ERROR,
+                                  G_IO_ERROR_FAILED,
+-                                 _ ("Unexpected lack of content trying to read a byte"));
++                                 _ ("Unexpected lack of content trying to read a line"));
+           else
+             g_propagate_error (error, local_error);
+           goto out;
diff -Nru glib2.0-2.74.6/debian/patches/gdbusinterfaceskeleton-Fix-a-use-after-free-of-a-GDBusMet.patch glib2.0-2.74.6/debian/patches/gdbusinterfaceskeleton-Fix-a-use-after-free-of-a-GDBusMet.patch
--- glib2.0-2.74.6/debian/patches/gdbusinterfaceskeleton-Fix-a-use-after-free-of-a-GDBusMet.patch	1970-01-01 01:00:00.000000000 +0100
+++ glib2.0-2.74.6/debian/patches/gdbusinterfaceskeleton-Fix-a-use-after-free-of-a-GDBusMet.patch	2023-04-04 09:55:32.000000000 +0100
@@ -0,0 +1,58 @@
+From: Philip Withnall <pwithnall@endlessos.org>
+Date: Wed, 22 Feb 2023 12:47:36 +0000
+Subject: gdbusinterfaceskeleton: Fix a use-after-free of a
+ GDBusMethodInvocation
+MIME-Version: 1.0
+Content-Type: text/plain; charset="utf-8"
+Content-Transfer-Encoding: 8bit
+
+This `GDBusMethodInvocation` may be shared across threads, with no
+guarantee on the strong ref in one thread outlasting any refs in other
+threads — so it needs a ref in this helper struct.
+
+This should fix a use-after-free where the `GDBusMethodInvocation` is
+freed from `g_value_unset()` after `g_signal_emit()` returns in
+`dispatch_in_thread_func()` in one thread; but then dereferenced again
+in `g_source_destroy_internal()` from another thread.
+
+Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
+Bug: https://gitlab.gnome.org/GNOME/glib/-/issues/2924
+Origin: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3298
+Applied-upstream: 2.74.7, commit:b29892237d3d0fa9b4615c9428d438aec60f1d82
+---
+ gio/gdbusinterfaceskeleton.c | 9 ++++++---
+ 1 file changed, 6 insertions(+), 3 deletions(-)
+
+diff --git a/gio/gdbusinterfaceskeleton.c b/gio/gdbusinterfaceskeleton.c
+index d28282f..a2a79fe 100644
+--- a/gio/gdbusinterfaceskeleton.c
++++ b/gio/gdbusinterfaceskeleton.c
+@@ -462,14 +462,17 @@ typedef struct
+ {
+   gint ref_count;  /* (atomic) */
+   GDBusInterfaceMethodCallFunc  method_call_func;
+-  GDBusMethodInvocation        *invocation;
++  GDBusMethodInvocation        *invocation;  /* (owned) */
+ } DispatchData;
+ 
+ static void
+ dispatch_data_unref (DispatchData *data)
+ {
+   if (g_atomic_int_dec_and_test (&data->ref_count))
+-    g_slice_free (DispatchData, data);
++    {
++      g_clear_object (&data->invocation);
++      g_slice_free (DispatchData, data);
++    }
+ }
+ 
+ static DispatchData *
+@@ -628,7 +631,7 @@ g_dbus_interface_method_dispatch_helper (GDBusInterfaceSkeleton       *interface
+ 
+       data = g_slice_new0 (DispatchData);
+       data->method_call_func = method_call_func;
+-      data->invocation = invocation;
++      data->invocation = g_object_ref (invocation);
+       data->ref_count = 1;
+ 
+       task = g_task_new (interface, NULL, NULL, NULL);
diff -Nru glib2.0-2.74.6/debian/patches/gdbusinterfaceskeleton-Remove-an-unnecessary-helper-struc.patch glib2.0-2.74.6/debian/patches/gdbusinterfaceskeleton-Remove-an-unnecessary-helper-struc.patch
--- glib2.0-2.74.6/debian/patches/gdbusinterfaceskeleton-Remove-an-unnecessary-helper-struc.patch	1970-01-01 01:00:00.000000000 +0100
+++ glib2.0-2.74.6/debian/patches/gdbusinterfaceskeleton-Remove-an-unnecessary-helper-struc.patch	2023-04-04 09:55:32.000000000 +0100
@@ -0,0 +1,83 @@
+From: Philip Withnall <pwithnall@endlessos.org>
+Date: Wed, 22 Feb 2023 12:40:49 +0000
+Subject: gdbusinterfaceskeleton: Remove an unnecessary helper struct member
+MIME-Version: 1.0
+Content-Type: text/plain; charset="utf-8"
+Content-Transfer-Encoding: 8bit
+
+The `GDBusInterfaceSkeleton` is already stored as the source object of
+the `GTask` here, with a strong reference.
+
+Storing it again in the task’s data struct is redundant, and makes it
+look like the `GDBusInterfaceSkeleton` is being used without holding a
+strong reference. (There’s not actually a bug there though: the strong
+reference from the `GTask` outlives the data struct, so is sufficient.)
+
+Remove the unnecessary helper struct member to clarify the code a bit.
+
+Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
+Bug: https://gitlab.gnome.org/GNOME/glib/-/issues/2924
+Origin: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3298
+Applied-upstream: 2.74.7, commit:d90fbc36367534f941941abb7e76e4c7cd8ed6b8
+---
+ gio/gdbusinterfaceskeleton.c | 15 +++++++--------
+ 1 file changed, 7 insertions(+), 8 deletions(-)
+
+diff --git a/gio/gdbusinterfaceskeleton.c b/gio/gdbusinterfaceskeleton.c
+index 3f07d4d..d28282f 100644
+--- a/gio/gdbusinterfaceskeleton.c
++++ b/gio/gdbusinterfaceskeleton.c
+@@ -461,7 +461,6 @@ dbus_interface_interface_init (GDBusInterfaceIface *iface)
+ typedef struct
+ {
+   gint ref_count;  /* (atomic) */
+-  GDBusInterfaceSkeleton       *interface;
+   GDBusInterfaceMethodCallFunc  method_call_func;
+   GDBusMethodInvocation        *invocation;
+ } DispatchData;
+@@ -502,16 +501,17 @@ dispatch_in_thread_func (GTask        *task,
+                          GCancellable *cancellable)
+ {
+   DispatchData *data = task_data;
++  GDBusInterfaceSkeleton *interface = g_task_get_source_object (task);
+   GDBusInterfaceSkeletonFlags flags;
+   GDBusObject *object;
+   gboolean authorized;
+ 
+-  g_mutex_lock (&data->interface->priv->lock);
+-  flags = data->interface->priv->flags;
+-  object = data->interface->priv->object;
++  g_mutex_lock (&interface->priv->lock);
++  flags = interface->priv->flags;
++  object = interface->priv->object;
+   if (object != NULL)
+     g_object_ref (object);
+-  g_mutex_unlock (&data->interface->priv->lock);
++  g_mutex_unlock (&interface->priv->lock);
+ 
+   /* first check on the enclosing object (if any), then the interface */
+   authorized = TRUE;
+@@ -519,13 +519,13 @@ dispatch_in_thread_func (GTask        *task,
+     {
+       g_signal_emit_by_name (object,
+                              "authorize-method",
+-                             data->interface,
++                             interface,
+                              data->invocation,
+                              &authorized);
+     }
+   if (authorized)
+     {
+-      g_signal_emit (data->interface,
++      g_signal_emit (interface,
+                      signals[G_AUTHORIZE_METHOD_SIGNAL],
+                      0,
+                      data->invocation,
+@@ -627,7 +627,6 @@ g_dbus_interface_method_dispatch_helper (GDBusInterfaceSkeleton       *interface
+       DispatchData *data;
+ 
+       data = g_slice_new0 (DispatchData);
+-      data->interface = interface;
+       data->method_call_func = method_call_func;
+       data->invocation = invocation;
+       data->ref_count = 1;
diff -Nru glib2.0-2.74.6/debian/patches/gdbus-Never-buffer-reads-during-server-authentication.patch glib2.0-2.74.6/debian/patches/gdbus-Never-buffer-reads-during-server-authentication.patch
--- glib2.0-2.74.6/debian/patches/gdbus-Never-buffer-reads-during-server-authentication.patch	1970-01-01 01:00:00.000000000 +0100
+++ glib2.0-2.74.6/debian/patches/gdbus-Never-buffer-reads-during-server-authentication.patch	2023-04-04 09:55:32.000000000 +0100
@@ -0,0 +1,141 @@
+From: Marius Vollmer <mvollmer@redhat.com>
+Date: Mon, 13 Feb 2023 14:12:52 +0200
+Subject: gdbus: Never buffer reads during server authentication
+
+Otherwise, the content of the buffer is thrown away when switching
+from reading via a GDataInputStream to unbuffered reads when waiting
+for the "BEGIN" line.
+
+(The code already tried to protect against over-reading like this by
+using unbuffered reads for the last few lines of the auth protocol,
+but it might already be too late at that point.  The buffer of the
+GDataInputStream might already contain the "BEGIN" line for example.)
+
+This matters when connecting a sd-bus client directly to a GDBus
+client.  A sd-bus client optimistically sends the whole auth
+conversation in one go without waiting for intermediate replies.  This
+is done to improve performance for the many short-lived connections
+that are typically made.
+
+Bug: https://gitlab.gnome.org/GNOME/glib/-/issues/2916
+Origin: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3300
+Applied-upstream: 2.74.7, commit:d982c86078741671949a6800f60d450901497e4e
+---
+ gio/gdbusauth.c | 50 +++++++++++++++++++++++++++++++-------------------
+ 1 file changed, 31 insertions(+), 19 deletions(-)
+
+diff --git a/gio/gdbusauth.c b/gio/gdbusauth.c
+index 6710368..b52a06e 100644
+--- a/gio/gdbusauth.c
++++ b/gio/gdbusauth.c
+@@ -949,7 +949,6 @@ _g_dbus_auth_run_server (GDBusAuth              *auth,
+ {
+   gboolean ret;
+   ServerState state;
+-  GDataInputStream *dis;
+   GDataOutputStream *dos;
+   GError *local_error;
+   gchar *line;
+@@ -965,7 +964,6 @@ _g_dbus_auth_run_server (GDBusAuth              *auth,
+   _g_dbus_auth_add_mechs (auth, observer);
+ 
+   ret = FALSE;
+-  dis = NULL;
+   dos = NULL;
+   mech = NULL;
+   negotiated_capabilities = 0;
+@@ -981,13 +979,18 @@ _g_dbus_auth_run_server (GDBusAuth              *auth,
+       goto out;
+     }
+ 
+-  dis = G_DATA_INPUT_STREAM (g_data_input_stream_new (g_io_stream_get_input_stream (auth->priv->stream)));
++  /* We use an extremely slow (but reliable) line reader for input
++   * instead of something buffered - this basically does a recvfrom()
++   * system call per character
++   *
++   * (the problem with using GDataInputStream's read_line is that
++   * because of buffering it might start reading into the first D-Bus
++   * message that appears after "BEGIN\r\n"....)
++   */
++
+   dos = G_DATA_OUTPUT_STREAM (g_data_output_stream_new (g_io_stream_get_output_stream (auth->priv->stream)));
+-  g_filter_input_stream_set_close_base_stream (G_FILTER_INPUT_STREAM (dis), FALSE);
+   g_filter_output_stream_set_close_base_stream (G_FILTER_OUTPUT_STREAM (dos), FALSE);
+ 
+-  g_data_input_stream_set_newline_type (dis, G_DATA_STREAM_NEWLINE_TYPE_CR_LF);
+-
+   /* read the NUL-byte, possibly with credentials attached */
+ #ifndef G_CREDENTIALS_PREFER_MESSAGE_PASSING
+   if (G_IS_SOCKET_CONNECTION (auth->priv->stream))
+@@ -1026,11 +1029,22 @@ _g_dbus_auth_run_server (GDBusAuth              *auth,
+     }
+   else
+     {
++      gchar c;
++      gssize num_read;
++
+       local_error = NULL;
+-      (void)g_data_input_stream_read_byte (dis, cancellable, &local_error);
+-      if (local_error != NULL)
++      num_read = g_input_stream_read (g_io_stream_get_input_stream (auth->priv->stream),
++                                      &c, 1,
++                                      cancellable, &local_error);
++      if (num_read != 1 || local_error != NULL)
+         {
+-          g_propagate_error (error, local_error);
++          if (local_error == NULL)
++            g_set_error_literal (error,
++                                 G_IO_ERROR,
++                                 G_IO_ERROR_FAILED,
++                                 _ ("Unexpected lack of content trying to read a byte"));
++          else
++            g_propagate_error (error, local_error);
+           goto out;
+         }
+     }
+@@ -1058,7 +1072,10 @@ _g_dbus_auth_run_server (GDBusAuth              *auth,
+         {
+         case SERVER_STATE_WAITING_FOR_AUTH:
+           debug_print ("SERVER: WaitingForAuth");
+-          line = _my_g_data_input_stream_read_line (dis, &line_length, cancellable, error);
++          line = _my_g_input_stream_read_line_safe (g_io_stream_get_input_stream (auth->priv->stream),
++                                                    &line_length,
++                                                    cancellable,
++                                                    error);
+           debug_print ("SERVER: WaitingForAuth, read '%s'", line);
+           if (line == NULL)
+             goto out;
+@@ -1276,7 +1293,10 @@ _g_dbus_auth_run_server (GDBusAuth              *auth,
+ 
+         case SERVER_STATE_WAITING_FOR_DATA:
+           debug_print ("SERVER: WaitingForData");
+-          line = _my_g_data_input_stream_read_line (dis, &line_length, cancellable, error);
++          line = _my_g_input_stream_read_line_safe (g_io_stream_get_input_stream (auth->priv->stream),
++                                                    &line_length,
++                                                    cancellable,
++                                                    error);
+           debug_print ("SERVER: WaitingForData, read '%s'", line);
+           if (line == NULL)
+             goto out;
+@@ -1315,13 +1335,6 @@ _g_dbus_auth_run_server (GDBusAuth              *auth,
+ 
+         case SERVER_STATE_WAITING_FOR_BEGIN:
+           debug_print ("SERVER: WaitingForBegin");
+-          /* Use extremely slow (but reliable) line reader - this basically
+-           * does a recvfrom() system call per character
+-           *
+-           * (the problem with using GDataInputStream's read_line is that because of
+-           * buffering it might start reading into the first D-Bus message that
+-           * appears after "BEGIN\r\n"....)
+-           */
+           line = _my_g_input_stream_read_line_safe (g_io_stream_get_input_stream (auth->priv->stream),
+                                                     &line_length,
+                                                     cancellable,
+@@ -1380,7 +1393,6 @@ _g_dbus_auth_run_server (GDBusAuth              *auth,
+ 
+  out:
+   g_clear_object (&mech);
+-  g_clear_object (&dis);
+   g_clear_object (&dos);
+   g_clear_object (&own_credentials);
+ 
diff -Nru glib2.0-2.74.6/debian/patches/series glib2.0-2.74.6/debian/patches/series
--- glib2.0-2.74.6/debian/patches/series	2023-03-02 20:53:53.000000000 +0000
+++ glib2.0-2.74.6/debian/patches/series	2023-04-04 09:55:32.000000000 +0100
@@ -1,3 +1,9 @@
+gdbus-Never-buffer-reads-during-server-authentication.patch
+gdbusinterfaceskeleton-Remove-an-unnecessary-helper-struc.patch
+gdbusinterfaceskeleton-Fix-a-use-after-free-of-a-GDBusMet.patch
+gdbusconnection-Make-GDBusMethodInvocation-transfer-a-bit.patch
+gdbus-Fix-an-accidental-string-freeze-break.patch
+tests-Skip-assert-msg-test.py-if-gdb-fails.patch
 tests-Don-t-rely-on-output-locale-of-sort-in-spawn-test.patch
 01_gettext-desktopfiles.patch
 0001-timer-test-use-volatile-for-locals.patch
diff -Nru glib2.0-2.74.6/debian/patches/tests-Skip-assert-msg-test.py-if-gdb-fails.patch glib2.0-2.74.6/debian/patches/tests-Skip-assert-msg-test.py-if-gdb-fails.patch
--- glib2.0-2.74.6/debian/patches/tests-Skip-assert-msg-test.py-if-gdb-fails.patch	1970-01-01 01:00:00.000000000 +0100
+++ glib2.0-2.74.6/debian/patches/tests-Skip-assert-msg-test.py-if-gdb-fails.patch	2023-04-04 09:55:32.000000000 +0100
@@ -0,0 +1,34 @@
+From: Matt Turner <mattst88@gmail.com>
+Date: Thu, 2 Mar 2023 00:13:22 -0500
+Subject: tests: Skip assert-msg-test.py if gdb fails
+
+Similar to commit 6e44151bf74d, skip the test if gdb is unable to read
+/proc/PID/mem, which gdb does as a fallback if ptrace is unavailable.
+
+This allows the test to skip when run under Gentoo's sandbox.
+
+(cherry picked from commit 19a8df9d8bff279a55b0fa3bb7ba4fbf7fcbefa8)
+
+Origin: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3307
+Applied-upstream: 2.74.7, commit:f36c8876e796f20b6bddcfaf7dad7301c1049c04
+---
+ glib/tests/assert-msg-test.py | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/glib/tests/assert-msg-test.py b/glib/tests/assert-msg-test.py
+index 5e5f3fb..edc506f 100755
+--- a/glib/tests/assert-msg-test.py
++++ b/glib/tests/assert-msg-test.py
+@@ -157,9 +157,9 @@ class TestAssertMessage(unittest.TestCase):
+ 
+             # Some CI environments disable ptrace (as they’re running in a
+             # container). If so, skip the test as there’s nothing we can do.
+-            if (
+-                result.info.returncode != 0
+-                and "ptrace: Operation not permitted" in result.err
++            if result.info.returncode != 0 and (
++                "ptrace: Operation not permitted" in result.err
++                or "warning: opening /proc/PID/mem file for lwp" in result.err
+             ):
+                 self.skipTest("GDB is not functional due to ptrace being disabled")
+ 
diff -Nru glib2.0-2.74.6/gio/gdbusauth.c glib2.0-2.74.6/gio/gdbusauth.c
--- glib2.0-2.74.6/gio/gdbusauth.c	2023-02-23 13:54:27.000000000 +0000
+++ glib2.0-2.74.6/gio/gdbusauth.c	2023-04-10 13:09:07.000000000 +0100
@@ -949,7 +949,6 @@
 {
   gboolean ret;
   ServerState state;
-  GDataInputStream *dis;
   GDataOutputStream *dos;
   GError *local_error;
   gchar *line;
@@ -965,7 +964,6 @@
   _g_dbus_auth_add_mechs (auth, observer);
 
   ret = FALSE;
-  dis = NULL;
   dos = NULL;
   mech = NULL;
   negotiated_capabilities = 0;
@@ -981,13 +979,18 @@
       goto out;
     }
 
-  dis = G_DATA_INPUT_STREAM (g_data_input_stream_new (g_io_stream_get_input_stream (auth->priv->stream)));
+  /* We use an extremely slow (but reliable) line reader for input
+   * instead of something buffered - this basically does a recvfrom()
+   * system call per character
+   *
+   * (the problem with using GDataInputStream's read_line is that
+   * because of buffering it might start reading into the first D-Bus
+   * message that appears after "BEGIN\r\n"....)
+   */
+
   dos = G_DATA_OUTPUT_STREAM (g_data_output_stream_new (g_io_stream_get_output_stream (auth->priv->stream)));
-  g_filter_input_stream_set_close_base_stream (G_FILTER_INPUT_STREAM (dis), FALSE);
   g_filter_output_stream_set_close_base_stream (G_FILTER_OUTPUT_STREAM (dos), FALSE);
 
-  g_data_input_stream_set_newline_type (dis, G_DATA_STREAM_NEWLINE_TYPE_CR_LF);
-
   /* read the NUL-byte, possibly with credentials attached */
 #ifndef G_CREDENTIALS_PREFER_MESSAGE_PASSING
   if (G_IS_SOCKET_CONNECTION (auth->priv->stream))
@@ -1026,11 +1029,22 @@
     }
   else
     {
+      gchar c;
+      gssize num_read;
+
       local_error = NULL;
-      (void)g_data_input_stream_read_byte (dis, cancellable, &local_error);
-      if (local_error != NULL)
+      num_read = g_input_stream_read (g_io_stream_get_input_stream (auth->priv->stream),
+                                      &c, 1,
+                                      cancellable, &local_error);
+      if (num_read != 1 || local_error != NULL)
         {
-          g_propagate_error (error, local_error);
+          if (local_error == NULL)
+            g_set_error_literal (error,
+                                 G_IO_ERROR,
+                                 G_IO_ERROR_FAILED,
+                                 _ ("Unexpected lack of content trying to read a line"));
+          else
+            g_propagate_error (error, local_error);
           goto out;
         }
     }
@@ -1058,7 +1072,10 @@
         {
         case SERVER_STATE_WAITING_FOR_AUTH:
           debug_print ("SERVER: WaitingForAuth");
-          line = _my_g_data_input_stream_read_line (dis, &line_length, cancellable, error);
+          line = _my_g_input_stream_read_line_safe (g_io_stream_get_input_stream (auth->priv->stream),
+                                                    &line_length,
+                                                    cancellable,
+                                                    error);
           debug_print ("SERVER: WaitingForAuth, read '%s'", line);
           if (line == NULL)
             goto out;
@@ -1276,7 +1293,10 @@
 
         case SERVER_STATE_WAITING_FOR_DATA:
           debug_print ("SERVER: WaitingForData");
-          line = _my_g_data_input_stream_read_line (dis, &line_length, cancellable, error);
+          line = _my_g_input_stream_read_line_safe (g_io_stream_get_input_stream (auth->priv->stream),
+                                                    &line_length,
+                                                    cancellable,
+                                                    error);
           debug_print ("SERVER: WaitingForData, read '%s'", line);
           if (line == NULL)
             goto out;
@@ -1315,13 +1335,6 @@
 
         case SERVER_STATE_WAITING_FOR_BEGIN:
           debug_print ("SERVER: WaitingForBegin");
-          /* Use extremely slow (but reliable) line reader - this basically
-           * does a recvfrom() system call per character
-           *
-           * (the problem with using GDataInputStream's read_line is that because of
-           * buffering it might start reading into the first D-Bus message that
-           * appears after "BEGIN\r\n"....)
-           */
           line = _my_g_input_stream_read_line_safe (g_io_stream_get_input_stream (auth->priv->stream),
                                                     &line_length,
                                                     cancellable,
@@ -1380,7 +1393,6 @@
 
  out:
   g_clear_object (&mech);
-  g_clear_object (&dis);
   g_clear_object (&dos);
   g_clear_object (&own_credentials);
 
diff -Nru glib2.0-2.74.6/gio/gdbusconnection.c glib2.0-2.74.6/gio/gdbusconnection.c
--- glib2.0-2.74.6/gio/gdbusconnection.c	2023-02-23 13:54:27.000000000 +0000
+++ glib2.0-2.74.6/gio/gdbusconnection.c	2023-04-10 13:09:07.000000000 +0100
@@ -5048,7 +5048,7 @@
   g_source_set_priority (idle_source, G_PRIORITY_DEFAULT);
   g_source_set_callback (idle_source,
                          call_in_idle_cb,
-                         invocation,
+                         g_steal_pointer (&invocation),
                          g_object_unref);
   g_source_set_static_name (idle_source, "[gio, " __FILE__ "] call_in_idle_cb");
   g_source_attach (idle_source, main_context);
diff -Nru glib2.0-2.74.6/gio/gdbusinterfaceskeleton.c glib2.0-2.74.6/gio/gdbusinterfaceskeleton.c
--- glib2.0-2.74.6/gio/gdbusinterfaceskeleton.c	2023-02-23 13:54:27.000000000 +0000
+++ glib2.0-2.74.6/gio/gdbusinterfaceskeleton.c	2023-04-10 13:09:07.000000000 +0100
@@ -461,16 +461,18 @@
 typedef struct
 {
   gint ref_count;  /* (atomic) */
-  GDBusInterfaceSkeleton       *interface;
   GDBusInterfaceMethodCallFunc  method_call_func;
-  GDBusMethodInvocation        *invocation;
+  GDBusMethodInvocation        *invocation;  /* (owned) */
 } DispatchData;
 
 static void
 dispatch_data_unref (DispatchData *data)
 {
   if (g_atomic_int_dec_and_test (&data->ref_count))
-    g_slice_free (DispatchData, data);
+    {
+      g_clear_object (&data->invocation);
+      g_slice_free (DispatchData, data);
+    }
 }
 
 static DispatchData *
@@ -502,16 +504,17 @@
                          GCancellable *cancellable)
 {
   DispatchData *data = task_data;
+  GDBusInterfaceSkeleton *interface = g_task_get_source_object (task);
   GDBusInterfaceSkeletonFlags flags;
   GDBusObject *object;
   gboolean authorized;
 
-  g_mutex_lock (&data->interface->priv->lock);
-  flags = data->interface->priv->flags;
-  object = data->interface->priv->object;
+  g_mutex_lock (&interface->priv->lock);
+  flags = interface->priv->flags;
+  object = interface->priv->object;
   if (object != NULL)
     g_object_ref (object);
-  g_mutex_unlock (&data->interface->priv->lock);
+  g_mutex_unlock (&interface->priv->lock);
 
   /* first check on the enclosing object (if any), then the interface */
   authorized = TRUE;
@@ -519,13 +522,13 @@
     {
       g_signal_emit_by_name (object,
                              "authorize-method",
-                             data->interface,
+                             interface,
                              data->invocation,
                              &authorized);
     }
   if (authorized)
     {
-      g_signal_emit (data->interface,
+      g_signal_emit (interface,
                      signals[G_AUTHORIZE_METHOD_SIGNAL],
                      0,
                      data->invocation,
@@ -627,9 +630,8 @@
       DispatchData *data;
 
       data = g_slice_new0 (DispatchData);
-      data->interface = interface;
       data->method_call_func = method_call_func;
-      data->invocation = invocation;
+      data->invocation = g_object_ref (invocation);
       data->ref_count = 1;
 
       task = g_task_new (interface, NULL, NULL, NULL);
diff -Nru glib2.0-2.74.6/glib/tests/assert-msg-test.py glib2.0-2.74.6/glib/tests/assert-msg-test.py
--- glib2.0-2.74.6/glib/tests/assert-msg-test.py	2023-02-23 13:54:27.000000000 +0000
+++ glib2.0-2.74.6/glib/tests/assert-msg-test.py	2023-04-10 13:09:07.000000000 +0100
@@ -157,9 +157,9 @@
 
             # Some CI environments disable ptrace (as they’re running in a
             # container). If so, skip the test as there’s nothing we can do.
-            if (
-                result.info.returncode != 0
-                and "ptrace: Operation not permitted" in result.err
+            if result.info.returncode != 0 and (
+                "ptrace: Operation not permitted" in result.err
+                or "warning: opening /proc/PID/mem file for lwp" in result.err
             ):
                 self.skipTest("GDB is not functional due to ptrace being disabled")
 

Reply to: