6fcf6b
From 7b46597384de916b4027ebaff662d06ff3ea2bc8 Mon Sep 17 00:00:00 2001
6fcf6b
From: Philip Withnall <pwithnall@endlessos.org>
6fcf6b
Date: Thu, 4 Feb 2021 13:30:52 +0000
6fcf6b
Subject: [PATCH 1/6] gstrfuncs: Add internal g_memdup2() function
6fcf6b
MIME-Version: 1.0
6fcf6b
Content-Type: text/plain; charset=UTF-8
6fcf6b
Content-Transfer-Encoding: 8bit
6fcf6b
6fcf6b
This will replace the existing `g_memdup()` function for use within
6fcf6b
GLib. It has an unavoidable security flaw of taking its `byte_size`
6fcf6b
argument as a `guint` rather than as a `gsize`. Most callers will
6fcf6b
expect it to be a `gsize`, and may pass in large values which could
6fcf6b
silently be truncated, resulting in an undersize allocation compared
6fcf6b
to what the caller expects.
6fcf6b
6fcf6b
This could lead to a classic buffer overflow vulnerability for many
6fcf6b
callers of `g_memdup()`.
6fcf6b
6fcf6b
`g_memdup2()`, in comparison, takes its `byte_size` as a `gsize`.
6fcf6b
6fcf6b
Spotted by Kevin Backhouse of GHSL.
6fcf6b
6fcf6b
In GLib 2.68, `g_memdup2()` will be a new public API. In this version
6fcf6b
for backport to older stable releases, it’s a new `static inline` API
6fcf6b
in a private header, so that use of `g_memdup()` within GLib can be
6fcf6b
fixed without adding a new API in a stable release series.
6fcf6b
6fcf6b
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
6fcf6b
Helps: CVE-2021-27219
6fcf6b
Helps: GHSL-2021-045
6fcf6b
Helps: #2319
6fcf6b
(cherry picked from commit 5e5f75a77e399c638be66d74e5daa8caeb433e00)
6fcf6b
---
6fcf6b
 docs/reference/glib/meson.build |  1 +
6fcf6b
 glib/gstrfuncsprivate.h         | 55 +++++++++++++++++++++++++++++++++
6fcf6b
 glib/meson.build                |  1 +
6fcf6b
 glib/tests/strfuncs.c           | 23 ++++++++++++++
6fcf6b
 4 files changed, 80 insertions(+)
6fcf6b
 create mode 100644 glib/gstrfuncsprivate.h
6fcf6b
6fcf6b
diff --git a/docs/reference/glib/meson.build b/docs/reference/glib/meson.build
6fcf6b
index f0f915e96..1a3680941 100644
6fcf6b
--- a/docs/reference/glib/meson.build
6fcf6b
+++ b/docs/reference/glib/meson.build
6fcf6b
@@ -20,6 +20,7 @@ if get_option('gtk_doc')
6fcf6b
     'gprintfint.h',
6fcf6b
     'gmirroringtable.h',
6fcf6b
     'gscripttable.h',
6fcf6b
+    'gstrfuncsprivate.h',
6fcf6b
     'glib-mirroring-tab',
6fcf6b
     'gnulib',
6fcf6b
     'pcre',
6fcf6b
diff --git a/glib/gstrfuncsprivate.h b/glib/gstrfuncsprivate.h
6fcf6b
new file mode 100644
6fcf6b
index 000000000..85c88328a
6fcf6b
--- /dev/null
6fcf6b
+++ b/glib/gstrfuncsprivate.h
6fcf6b
@@ -0,0 +1,55 @@
6fcf6b
+/* GLIB - Library of useful routines for C programming
6fcf6b
+ * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
6fcf6b
+ *
6fcf6b
+ * This library is free software; you can redistribute it and/or
6fcf6b
+ * modify it under the terms of the GNU Lesser General Public
6fcf6b
+ * License as published by the Free Software Foundation; either
6fcf6b
+ * version 2.1 of the License, or (at your option) any later version.
6fcf6b
+ *
6fcf6b
+ * This library is distributed in the hope that it will be useful,
6fcf6b
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
6fcf6b
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
6fcf6b
+ * Lesser General Public License for more details.
6fcf6b
+ *
6fcf6b
+ * You should have received a copy of the GNU Lesser General Public
6fcf6b
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
6fcf6b
+ */
6fcf6b
+
6fcf6b
+#include <glib.h>
6fcf6b
+#include <string.h>
6fcf6b
+
6fcf6b
+/*
6fcf6b
+ * g_memdup2:
6fcf6b
+ * @mem: (nullable): the memory to copy.
6fcf6b
+ * @byte_size: the number of bytes to copy.
6fcf6b
+ *
6fcf6b
+ * Allocates @byte_size bytes of memory, and copies @byte_size bytes into it
6fcf6b
+ * from @mem. If @mem is %NULL it returns %NULL.
6fcf6b
+ *
6fcf6b
+ * This replaces g_memdup(), which was prone to integer overflows when
6fcf6b
+ * converting the argument from a #gsize to a #guint.
6fcf6b
+ *
6fcf6b
+ * This static inline version is a backport of the new public API from
6fcf6b
+ * GLib 2.68, kept internal to GLib for backport to older stable releases.
6fcf6b
+ * See https://gitlab.gnome.org/GNOME/glib/-/issues/2319.
6fcf6b
+ *
6fcf6b
+ * Returns: (nullable): a pointer to the newly-allocated copy of the memory,
6fcf6b
+ *    or %NULL if @mem is %NULL.
6fcf6b
+ * Since: 2.68
6fcf6b
+ */
6fcf6b
+static inline gpointer
6fcf6b
+g_memdup2 (gconstpointer mem,
6fcf6b
+           gsize         byte_size)
6fcf6b
+{
6fcf6b
+  gpointer new_mem;
6fcf6b
+
6fcf6b
+  if (mem && byte_size != 0)
6fcf6b
+    {
6fcf6b
+      new_mem = g_malloc (byte_size);
6fcf6b
+      memcpy (new_mem, mem, byte_size);
6fcf6b
+    }
6fcf6b
+  else
6fcf6b
+    new_mem = NULL;
6fcf6b
+
6fcf6b
+  return new_mem;
6fcf6b
+}
6fcf6b
diff --git a/glib/meson.build b/glib/meson.build
6fcf6b
index a2f9da81c..481fd06ff 100644
6fcf6b
--- a/glib/meson.build
6fcf6b
+++ b/glib/meson.build
6fcf6b
@@ -167,6 +167,7 @@ glib_sources = files(
6fcf6b
   'gslist.c',
6fcf6b
   'gstdio.c',
6fcf6b
   'gstrfuncs.c',
6fcf6b
+  'gstrfuncsprivate.h',
6fcf6b
   'gstring.c',
6fcf6b
   'gstringchunk.c',
6fcf6b
   'gtestutils.c',
6fcf6b
diff --git a/glib/tests/strfuncs.c b/glib/tests/strfuncs.c
6fcf6b
index 7e031bdb1..2aa252946 100644
6fcf6b
--- a/glib/tests/strfuncs.c
6fcf6b
+++ b/glib/tests/strfuncs.c
6fcf6b
@@ -32,6 +32,8 @@
6fcf6b
 #include <string.h>
6fcf6b
 #include "glib.h"
6fcf6b
 
6fcf6b
+#include "gstrfuncsprivate.h"
6fcf6b
+
6fcf6b
 #if defined (_MSC_VER) && (_MSC_VER <= 1800)
6fcf6b
 #define isnan(x) _isnan(x)
6fcf6b
 
6fcf6b
@@ -199,6 +201,26 @@ test_is_to_digit (void)
6fcf6b
   #undef TEST_DIGIT
6fcf6b
 }
6fcf6b
 
6fcf6b
+/* Testing g_memdup2() function with various positive and negative cases */
6fcf6b
+static void
6fcf6b
+test_memdup2 (void)
6fcf6b
+{
6fcf6b
+  gchar *str_dup = NULL;
6fcf6b
+  const gchar *str = "The quick brown fox jumps over the lazy dog";
6fcf6b
+
6fcf6b
+  /* Testing negative cases */
6fcf6b
+  g_assert_null (g_memdup2 (NULL, 1024));
6fcf6b
+  g_assert_null (g_memdup2 (str, 0));
6fcf6b
+  g_assert_null (g_memdup2 (NULL, 0));
6fcf6b
+
6fcf6b
+  /* Testing normal usage cases */
6fcf6b
+  str_dup = g_memdup2 (str, strlen (str) + 1);
6fcf6b
+  g_assert_nonnull (str_dup);
6fcf6b
+  g_assert_cmpstr (str, ==, str_dup);
6fcf6b
+
6fcf6b
+  g_free (str_dup);
6fcf6b
+}
6fcf6b
+
6fcf6b
 static void
6fcf6b
 test_strdup (void)
6fcf6b
 {
6fcf6b
@@ -1726,6 +1748,7 @@ main (int   argc,
6fcf6b
   g_test_init (&argc, &argv, NULL);
6fcf6b
 
6fcf6b
   g_test_add_func ("/strfuncs/test-is-to-digit", test_is_to_digit);
6fcf6b
+  g_test_add_func ("/strfuncs/memdup2", test_memdup2);
6fcf6b
   g_test_add_func ("/strfuncs/strdup", test_strdup);
6fcf6b
   g_test_add_func ("/strfuncs/strndup", test_strndup);
6fcf6b
   g_test_add_func ("/strfuncs/strdup-printf", test_strdup_printf);
6fcf6b
-- 
6fcf6b
2.31.1
6fcf6b
6fcf6b
From d6aab169954d9e6e77753dee68e1b3f5932f6dee Mon Sep 17 00:00:00 2001
6fcf6b
From: Philip Withnall <pwithnall@endlessos.org>
6fcf6b
Date: Thu, 4 Feb 2021 13:41:21 +0000
6fcf6b
Subject: [PATCH 2/6] glib: Use g_memdup2() instead of g_memdup() in obvious
6fcf6b
 places
6fcf6b
MIME-Version: 1.0
6fcf6b
Content-Type: text/plain; charset=UTF-8
6fcf6b
Content-Transfer-Encoding: 8bit
6fcf6b
6fcf6b
Convert all the call sites which use `g_memdup()`’s length argument
6fcf6b
trivially (for example, by passing a `sizeof()` or an existing `gsize`
6fcf6b
variable), so that they use `g_memdup2()` instead.
6fcf6b
6fcf6b
In almost all of these cases the use of `g_memdup()` would not have
6fcf6b
caused problems, but it will soon be deprecated, so best port away from
6fcf6b
it
6fcf6b
6fcf6b
In particular, this fixes an overflow within `g_bytes_new()`, identified
6fcf6b
as GHSL-2021-045 (aka CVE-2021-27219) by GHSL team member Kevin Backhouse.
6fcf6b
6fcf6b
Adapted for GLib 2.58 by Simon McVittie.
6fcf6b
6fcf6b
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
6fcf6b
Fixes: CVE-2021-27219
6fcf6b
Fixes: GHSL-2021-045
6fcf6b
Helps: #2319
6fcf6b
(cherry picked from commit 0736b7c1e7cf4232c5d7eb2b0fbfe9be81bd3baa)
6fcf6b
[Backport to 2.58: Omit changes to ghash.c, will be a separate commit]
6fcf6b
[Backport to 2.58: Omit changes to giochannel.c, not needed in this branch]
6fcf6b
[Backport to 2.58: Omit changes to uri test, not needed in this branch]
6fcf6b
Signed-off-by: Simon McVittie <smcv@collabora.com>
6fcf6b
---
6fcf6b
 glib/gbytes.c               | 6 ++++--
6fcf6b
 glib/gdir.c                 | 3 ++-
6fcf6b
 glib/gslice.c               | 3 ++-
6fcf6b
 glib/gtestutils.c           | 3 ++-
6fcf6b
 glib/gvariant.c             | 7 ++++---
6fcf6b
 glib/gvarianttype.c         | 3 ++-
6fcf6b
 glib/tests/array-test.c     | 2 +-
6fcf6b
 glib/tests/option-context.c | 6 ++++--
6fcf6b
 8 files changed, 21 insertions(+), 12 deletions(-)
6fcf6b
6fcf6b
diff --git a/glib/gbytes.c b/glib/gbytes.c
6fcf6b
index 3b14a51cd..5141170d7 100644
6fcf6b
--- a/glib/gbytes.c
6fcf6b
+++ b/glib/gbytes.c
6fcf6b
@@ -33,6 +33,8 @@
6fcf6b
 
6fcf6b
 #include <string.h>
6fcf6b
 
6fcf6b
+#include "gstrfuncsprivate.h"
6fcf6b
+
6fcf6b
 /**
6fcf6b
  * GBytes:
6fcf6b
  *
6fcf6b
@@ -94,7 +96,7 @@ g_bytes_new (gconstpointer data,
6fcf6b
 {
6fcf6b
   g_return_val_if_fail (data != NULL || size == 0, NULL);
6fcf6b
 
6fcf6b
-  return g_bytes_new_take (g_memdup (data, size), size);
6fcf6b
+  return g_bytes_new_take (g_memdup2 (data, size), size);
6fcf6b
 }
6fcf6b
 
6fcf6b
 /**
6fcf6b
@@ -490,7 +492,7 @@ g_bytes_unref_to_data (GBytes *bytes,
6fcf6b
        * Copy: Non g_malloc (or compatible) allocator, or static memory,
6fcf6b
        * so we have to copy, and then unref.
6fcf6b
        */
6fcf6b
-      result = g_memdup (bytes->data, bytes->size);
6fcf6b
+      result = g_memdup2 (bytes->data, bytes->size);
6fcf6b
       *size = bytes->size;
6fcf6b
       g_bytes_unref (bytes);
6fcf6b
     }
6fcf6b
diff --git a/glib/gdir.c b/glib/gdir.c
6fcf6b
index cb4ad0b2f..9d955d57f 100644
6fcf6b
--- a/glib/gdir.c
6fcf6b
+++ b/glib/gdir.c
6fcf6b
@@ -37,6 +37,7 @@
6fcf6b
 #include "gconvert.h"
6fcf6b
 #include "gfileutils.h"
6fcf6b
 #include "gstrfuncs.h"
6fcf6b
+#include "gstrfuncsprivate.h"
6fcf6b
 #include "gtestutils.h"
6fcf6b
 #include "glibintl.h"
6fcf6b
 
6fcf6b
@@ -113,7 +114,7 @@ g_dir_open_with_errno (const gchar *path,
6fcf6b
     return NULL;
6fcf6b
 #endif
6fcf6b
 
6fcf6b
-  return g_memdup (&dir, sizeof dir);
6fcf6b
+  return g_memdup2 (&dir, sizeof dir);
6fcf6b
 }
6fcf6b
 
6fcf6b
 /**
6fcf6b
diff --git a/glib/gslice.c b/glib/gslice.c
6fcf6b
index 454c8a602..8e2359515 100644
6fcf6b
--- a/glib/gslice.c
6fcf6b
+++ b/glib/gslice.c
6fcf6b
@@ -45,6 +45,7 @@
6fcf6b
 #include "gmain.h"
6fcf6b
 #include "gmem.h"               /* gslice.h */
6fcf6b
 #include "gstrfuncs.h"
6fcf6b
+#include "gstrfuncsprivate.h"
6fcf6b
 #include "gutils.h"
6fcf6b
 #include "gtrashstack.h"
6fcf6b
 #include "gtestutils.h"
6fcf6b
@@ -352,7 +353,7 @@ g_slice_get_config_state (GSliceConfig ckey,
6fcf6b
       array[i++] = allocator->contention_counters[address];
6fcf6b
       array[i++] = allocator_get_magazine_threshold (allocator, address);
6fcf6b
       *n_values = i;
6fcf6b
-      return g_memdup (array, sizeof (array[0]) * *n_values);
6fcf6b
+      return g_memdup2 (array, sizeof (array[0]) * *n_values);
6fcf6b
     default:
6fcf6b
       return NULL;
6fcf6b
     }
6fcf6b
diff --git a/glib/gtestutils.c b/glib/gtestutils.c
6fcf6b
index 0447dcda5..14e071fce 100644
6fcf6b
--- a/glib/gtestutils.c
6fcf6b
+++ b/glib/gtestutils.c
6fcf6b
@@ -49,6 +49,7 @@
6fcf6b
 #include "gpattern.h"
6fcf6b
 #include "grand.h"
6fcf6b
 #include "gstrfuncs.h"
6fcf6b
+#include "gstrfuncsprivate.h"
6fcf6b
 #include "gtimer.h"
6fcf6b
 #include "gslice.h"
6fcf6b
 #include "gspawn.h"
6fcf6b
@@ -3397,7 +3398,7 @@ g_test_log_extract (GTestLogBuffer *tbuffer)
6fcf6b
       if (p <= tbuffer->data->str + mlength)
6fcf6b
         {
6fcf6b
           g_string_erase (tbuffer->data, 0, mlength);
6fcf6b
-          tbuffer->msgs = g_slist_prepend (tbuffer->msgs, g_memdup (&msg, sizeof (msg)));
6fcf6b
+          tbuffer->msgs = g_slist_prepend (tbuffer->msgs, g_memdup2 (&msg, sizeof (msg)));
6fcf6b
           return TRUE;
6fcf6b
         }
6fcf6b
 
6fcf6b
diff --git a/glib/gvariant.c b/glib/gvariant.c
6fcf6b
index 8be9ce798..45a1a73dc 100644
6fcf6b
--- a/glib/gvariant.c
6fcf6b
+++ b/glib/gvariant.c
6fcf6b
@@ -33,6 +33,7 @@
6fcf6b
 
6fcf6b
 #include <string.h>
6fcf6b
 
6fcf6b
+#include "gstrfuncsprivate.h"
6fcf6b
 
6fcf6b
 /**
6fcf6b
  * SECTION:gvariant
6fcf6b
@@ -720,7 +721,7 @@ g_variant_new_variant (GVariant *value)
6fcf6b
   g_variant_ref_sink (value);
6fcf6b
 
6fcf6b
   return g_variant_new_from_children (G_VARIANT_TYPE_VARIANT,
6fcf6b
-                                      g_memdup (&value, sizeof value),
6fcf6b
+                                      g_memdup2 (&value, sizeof value),
6fcf6b
                                       1, g_variant_is_trusted (value));
6fcf6b
 }
6fcf6b
 
6fcf6b
@@ -1224,7 +1225,7 @@ g_variant_new_fixed_array (const GVariantType  *element_type,
6fcf6b
       return NULL;
6fcf6b
     }
6fcf6b
 
6fcf6b
-  data = g_memdup (elements, n_elements * element_size);
6fcf6b
+  data = g_memdup2 (elements, n_elements * element_size);
6fcf6b
   value = g_variant_new_from_data (array_type, data,
6fcf6b
                                    n_elements * element_size,
6fcf6b
                                    FALSE, g_free, data);
6fcf6b
@@ -1901,7 +1902,7 @@ g_variant_dup_bytestring (GVariant *value,
6fcf6b
   if (length)
6fcf6b
     *length = size;
6fcf6b
 
6fcf6b
-  return g_memdup (original, size + 1);
6fcf6b
+  return g_memdup2 (original, size + 1);
6fcf6b
 }
6fcf6b
 
6fcf6b
 /**
6fcf6b
diff --git a/glib/gvarianttype.c b/glib/gvarianttype.c
6fcf6b
index c8433e65a..dbbf7d2d1 100644
6fcf6b
--- a/glib/gvarianttype.c
6fcf6b
+++ b/glib/gvarianttype.c
6fcf6b
@@ -28,6 +28,7 @@
6fcf6b
 
6fcf6b
 #include <string.h>
6fcf6b
 
6fcf6b
+#include "gstrfuncsprivate.h"
6fcf6b
 
6fcf6b
 /**
6fcf6b
  * SECTION:gvarianttype
6fcf6b
@@ -1174,7 +1175,7 @@ g_variant_type_new_tuple (const GVariantType * const *items,
6fcf6b
   g_assert (offset < sizeof buffer);
6fcf6b
   buffer[offset++] = ')';
6fcf6b
 
6fcf6b
-  return (GVariantType *) g_memdup (buffer, offset);
6fcf6b
+  return (GVariantType *) g_memdup2 (buffer, offset);
6fcf6b
 }
6fcf6b
 
6fcf6b
 /**
6fcf6b
-- 
6fcf6b
2.31.1
6fcf6b
6fcf6b
From 7e2c2a07508a97b9d75e402afe4749b02a34dd8b Mon Sep 17 00:00:00 2001
6fcf6b
From: Simon McVittie <smcv@collabora.com>
6fcf6b
Date: Thu, 18 Mar 2021 10:31:00 +0000
6fcf6b
Subject: [PATCH 3/6] ghash: Use g_memdup2() instead of g_memdup()
6fcf6b
6fcf6b
Backport of part of commit 0736b7c1e7cf4232c5d7eb2b0fbfe9be81bd3baa
6fcf6b
to the simpler structure of the GHashTable code in glib-2-58.
6fcf6b
6fcf6b
Helps: #2319
6fcf6b
Signed-off-by: Simon McVittie <smcv@collabora.com>
6fcf6b
---
6fcf6b
 glib/ghash.c | 3 ++-
6fcf6b
 1 file changed, 2 insertions(+), 1 deletion(-)
6fcf6b
6fcf6b
diff --git a/glib/ghash.c b/glib/ghash.c
6fcf6b
index 6bb04a50d..608d136f4 100644
6fcf6b
--- a/glib/ghash.c
6fcf6b
+++ b/glib/ghash.c
6fcf6b
@@ -34,6 +34,7 @@
6fcf6b
 
6fcf6b
 #include "glib-private.h"
6fcf6b
 #include "gstrfuncs.h"
6fcf6b
+#include "gstrfuncsprivate.h"
6fcf6b
 #include "gatomic.h"
6fcf6b
 #include "gtestutils.h"
6fcf6b
 #include "gslice.h"
6fcf6b
@@ -967,7 +968,7 @@ g_hash_table_insert_node (GHashTable *hash_table,
6fcf6b
    * split the table.
6fcf6b
    */
6fcf6b
   if (G_UNLIKELY (hash_table->keys == hash_table->values && hash_table->keys[node_index] != new_value))
6fcf6b
-    hash_table->values = g_memdup (hash_table->keys, sizeof (gpointer) * hash_table->size);
6fcf6b
+    hash_table->values = g_memdup2 (hash_table->keys, sizeof (gpointer) * hash_table->size);
6fcf6b
 
6fcf6b
   /* Step 3: Actually do the write */
6fcf6b
   hash_table->values[node_index] = new_value;
6fcf6b
-- 
6fcf6b
2.31.1
6fcf6b
6fcf6b
From 9e0c87610dccd1b0eaca28a3baa521ea6a24f46b Mon Sep 17 00:00:00 2001
6fcf6b
From: Philip Withnall <pwithnall@endlessos.org>
6fcf6b
Date: Thu, 4 Feb 2021 13:39:25 +0000
6fcf6b
Subject: [PATCH 4/6] gobject: Use g_memdup2() instead of g_memdup() in obvious
6fcf6b
 places
6fcf6b
MIME-Version: 1.0
6fcf6b
Content-Type: text/plain; charset=UTF-8
6fcf6b
Content-Transfer-Encoding: 8bit
6fcf6b
6fcf6b
Convert all the call sites which use `g_memdup()`’s length argument
6fcf6b
trivially (for example, by passing a `sizeof()`), so that they use
6fcf6b
`g_memdup2()` instead.
6fcf6b
6fcf6b
In almost all of these cases the use of `g_memdup()` would not have
6fcf6b
caused problems, but it will soon be deprecated, so best port away from
6fcf6b
it.
6fcf6b
6fcf6b
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
6fcf6b
Helps: #2319
6fcf6b
(cherry picked from commit 6110caea45b235420b98cd41d845cc92238f6781)
6fcf6b
---
6fcf6b
 gobject/gsignal.c     | 3 ++-
6fcf6b
 gobject/gtype.c       | 9 +++++----
6fcf6b
 gobject/gtypemodule.c | 3 ++-
6fcf6b
 gobject/tests/param.c | 4 +++-
6fcf6b
 4 files changed, 12 insertions(+), 7 deletions(-)
6fcf6b
6fcf6b
diff --git a/gobject/gsignal.c b/gobject/gsignal.c
6fcf6b
index b22dfcca8..92555eb60 100644
6fcf6b
--- a/gobject/gsignal.c
6fcf6b
+++ b/gobject/gsignal.c
6fcf6b
@@ -28,6 +28,7 @@
6fcf6b
 #include <signal.h>
6fcf6b
 
6fcf6b
 #include "gsignal.h"
6fcf6b
+#include "gstrfuncsprivate.h"
6fcf6b
 #include "gtype-private.h"
6fcf6b
 #include "gbsearcharray.h"
6fcf6b
 #include "gvaluecollector.h"
6fcf6b
@@ -1724,7 +1725,7 @@ g_signal_newv (const gchar       *signal_name,
6fcf6b
   node->single_va_closure_is_valid = FALSE;
6fcf6b
   node->flags = signal_flags & G_SIGNAL_FLAGS_MASK;
6fcf6b
   node->n_params = n_params;
6fcf6b
-  node->param_types = g_memdup (param_types, sizeof (GType) * n_params);
6fcf6b
+  node->param_types = g_memdup2 (param_types, sizeof (GType) * n_params);
6fcf6b
   node->return_type = return_type;
6fcf6b
   node->class_closure_bsa = NULL;
6fcf6b
   if (accumulator)
6fcf6b
diff --git a/gobject/gtype.c b/gobject/gtype.c
6fcf6b
index 275a8b60b..9e663ce52 100644
6fcf6b
--- a/gobject/gtype.c
6fcf6b
+++ b/gobject/gtype.c
6fcf6b
@@ -33,6 +33,7 @@
6fcf6b
 
6fcf6b
 #include "glib-private.h"
6fcf6b
 #include "gconstructor.h"
6fcf6b
+#include "gstrfuncsprivate.h"
6fcf6b
 
6fcf6b
 #ifdef G_OS_WIN32
6fcf6b
 #include <windows.h>
6fcf6b
@@ -1471,7 +1472,7 @@ type_add_interface_Wm (TypeNode             *node,
6fcf6b
   iholder->next = iface_node_get_holders_L (iface);
6fcf6b
   iface_node_set_holders_W (iface, iholder);
6fcf6b
   iholder->instance_type = NODE_TYPE (node);
6fcf6b
-  iholder->info = info ? g_memdup (info, sizeof (*info)) : NULL;
6fcf6b
+  iholder->info = info ? g_memdup2 (info, sizeof (*info)) : NULL;
6fcf6b
   iholder->plugin = plugin;
6fcf6b
 
6fcf6b
   /* create an iface entry for this type */
6fcf6b
@@ -1732,7 +1733,7 @@ type_iface_retrieve_holder_info_Wm (TypeNode *iface,
6fcf6b
         INVALID_RECURSION ("g_type_plugin_*", iholder->plugin, NODE_NAME (iface));
6fcf6b
       
6fcf6b
       check_interface_info_I (iface, instance_type, &tmp_info);
6fcf6b
-      iholder->info = g_memdup (&tmp_info, sizeof (tmp_info));
6fcf6b
+      iholder->info = g_memdup2 (&tmp_info, sizeof (tmp_info));
6fcf6b
     }
6fcf6b
   
6fcf6b
   return iholder;	/* we don't modify write lock upon returning NULL */
6fcf6b
@@ -2013,10 +2014,10 @@ type_iface_vtable_base_init_Wm (TypeNode *iface,
6fcf6b
       IFaceEntry *pentry = type_lookup_iface_entry_L (pnode, iface);
6fcf6b
       
6fcf6b
       if (pentry)
6fcf6b
-	vtable = g_memdup (pentry->vtable, iface->data->iface.vtable_size);
6fcf6b
+	vtable = g_memdup2 (pentry->vtable, iface->data->iface.vtable_size);
6fcf6b
     }
6fcf6b
   if (!vtable)
6fcf6b
-    vtable = g_memdup (iface->data->iface.dflt_vtable, iface->data->iface.vtable_size);
6fcf6b
+    vtable = g_memdup2 (iface->data->iface.dflt_vtable, iface->data->iface.vtable_size);
6fcf6b
   entry->vtable = vtable;
6fcf6b
   vtable->g_type = NODE_TYPE (iface);
6fcf6b
   vtable->g_instance_type = NODE_TYPE (node);
6fcf6b
diff --git a/gobject/gtypemodule.c b/gobject/gtypemodule.c
6fcf6b
index c67f789b1..cf877bc0b 100644
6fcf6b
--- a/gobject/gtypemodule.c
6fcf6b
+++ b/gobject/gtypemodule.c
6fcf6b
@@ -19,6 +19,7 @@
6fcf6b
 
6fcf6b
 #include <stdlib.h>
6fcf6b
 
6fcf6b
+#include "gstrfuncsprivate.h"
6fcf6b
 #include "gtypeplugin.h"
6fcf6b
 #include "gtypemodule.h"
6fcf6b
 
6fcf6b
@@ -436,7 +437,7 @@ g_type_module_register_type (GTypeModule     *module,
6fcf6b
   module_type_info->loaded = TRUE;
6fcf6b
   module_type_info->info = *type_info;
6fcf6b
   if (type_info->value_table)
6fcf6b
-    module_type_info->info.value_table = g_memdup (type_info->value_table,
6fcf6b
+    module_type_info->info.value_table = g_memdup2 (type_info->value_table,
6fcf6b
 						   sizeof (GTypeValueTable));
6fcf6b
 
6fcf6b
   return module_type_info->type;
6fcf6b
diff --git a/gobject/tests/param.c b/gobject/tests/param.c
6fcf6b
index 758289bf8..971cff162 100644
6fcf6b
--- a/gobject/tests/param.c
6fcf6b
+++ b/gobject/tests/param.c
6fcf6b
@@ -2,6 +2,8 @@
6fcf6b
 #include <glib-object.h>
6fcf6b
 #include <stdlib.h>
6fcf6b
 
6fcf6b
+#include "gstrfuncsprivate.h"
6fcf6b
+
6fcf6b
 static void
6fcf6b
 test_param_value (void)
6fcf6b
 {
6fcf6b
@@ -851,7 +853,7 @@ main (int argc, char *argv[])
6fcf6b
             test_path = g_strdup_printf ("/param/implement/subprocess/%d-%d-%d-%d",
6fcf6b
                                          data.change_this_flag, data.change_this_type,
6fcf6b
                                          data.use_this_flag, data.use_this_type);
6fcf6b
-            test_data = g_memdup (&data, sizeof (TestParamImplementData));
6fcf6b
+            test_data = g_memdup2 (&data, sizeof (TestParamImplementData));
6fcf6b
             g_test_add_data_func_full (test_path, test_data, test_param_implement_child, g_free);
6fcf6b
             g_free (test_path);
6fcf6b
           }
6fcf6b
-- 
6fcf6b
2.31.1
6fcf6b
6fcf6b
From d3f7a79540fc1e85eb82c2987e9f7e2dbd93ff74 Mon Sep 17 00:00:00 2001
6fcf6b
From: Philip Withnall <pwithnall@endlessos.org>
6fcf6b
Date: Thu, 4 Feb 2021 13:37:56 +0000
6fcf6b
Subject: [PATCH 5/6] gio: Use g_memdup2() instead of g_memdup() in obvious
6fcf6b
 places
6fcf6b
MIME-Version: 1.0
6fcf6b
Content-Type: text/plain; charset=UTF-8
6fcf6b
Content-Transfer-Encoding: 8bit
6fcf6b
6fcf6b
Convert all the call sites which use `g_memdup()`’s length argument
6fcf6b
trivially (for example, by passing a `sizeof()`), so that they use
6fcf6b
`g_memdup2()` instead.
6fcf6b
6fcf6b
In almost all of these cases the use of `g_memdup()` would not have
6fcf6b
caused problems, but it will soon be deprecated, so best port away from
6fcf6b
it.
6fcf6b
6fcf6b
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
6fcf6b
Helps: #2319
6fcf6b
(cherry picked from commit be8834340a2d928ece82025463ae23dee2c333d0)
6fcf6b
---
6fcf6b
 gio/gdbusconnection.c                 | 5 +++--
6fcf6b
 gio/gdbusinterfaceskeleton.c          | 3 ++-
6fcf6b
 gio/gfile.c                           | 7 ++++---
6fcf6b
 gio/gsettingsschema.c                 | 5 +++--
6fcf6b
 gio/gwin32registrykey.c               | 8 +++++---
6fcf6b
 gio/tests/async-close-output-stream.c | 6 ++++--
6fcf6b
 gio/tests/gdbus-export.c              | 5 +++--
6fcf6b
 gio/win32/gwinhttpfile.c              | 9 +++++----
6fcf6b
 8 files changed, 29 insertions(+), 19 deletions(-)
6fcf6b
6fcf6b
diff --git a/gio/gdbusconnection.c b/gio/gdbusconnection.c
6fcf6b
index 6f7e5fefc..117c8df35 100644
6fcf6b
--- a/gio/gdbusconnection.c
6fcf6b
+++ b/gio/gdbusconnection.c
6fcf6b
@@ -119,6 +119,7 @@
6fcf6b
 #include "gasyncinitable.h"
6fcf6b
 #include "giostream.h"
6fcf6b
 #include "gasyncresult.h"
6fcf6b
+#include "gstrfuncsprivate.h"
6fcf6b
 #include "gtask.h"
6fcf6b
 
6fcf6b
 #ifdef G_OS_UNIX
6fcf6b
@@ -3970,7 +3971,7 @@ _g_dbus_interface_vtable_copy (const GDBusInterfaceVTable *vtable)
6fcf6b
   /* Don't waste memory by copying padding - remember to update this
6fcf6b
    * when changing struct _GDBusInterfaceVTable in gdbusconnection.h
6fcf6b
    */
6fcf6b
-  return g_memdup ((gconstpointer) vtable, 3 * sizeof (gpointer));
6fcf6b
+  return g_memdup2 ((gconstpointer) vtable, 3 * sizeof (gpointer));
6fcf6b
 }
6fcf6b
 
6fcf6b
 static void
6fcf6b
@@ -3987,7 +3988,7 @@ _g_dbus_subtree_vtable_copy (const GDBusSubtreeVTable *vtable)
6fcf6b
   /* Don't waste memory by copying padding - remember to update this
6fcf6b
    * when changing struct _GDBusSubtreeVTable in gdbusconnection.h
6fcf6b
    */
6fcf6b
-  return g_memdup ((gconstpointer) vtable, 3 * sizeof (gpointer));
6fcf6b
+  return g_memdup2 ((gconstpointer) vtable, 3 * sizeof (gpointer));
6fcf6b
 }
6fcf6b
 
6fcf6b
 static void
6fcf6b
diff --git a/gio/gdbusinterfaceskeleton.c b/gio/gdbusinterfaceskeleton.c
6fcf6b
index 96bd520aa..672604c49 100644
6fcf6b
--- a/gio/gdbusinterfaceskeleton.c
6fcf6b
+++ b/gio/gdbusinterfaceskeleton.c
6fcf6b
@@ -27,6 +27,7 @@
6fcf6b
 #include "gdbusprivate.h"
6fcf6b
 #include "gdbusmethodinvocation.h"
6fcf6b
 #include "gdbusconnection.h"
6fcf6b
+#include "gstrfuncsprivate.h"
6fcf6b
 #include "gtask.h"
6fcf6b
 #include "gioerror.h"
6fcf6b
 
6fcf6b
@@ -697,7 +698,7 @@ add_connection_locked (GDBusInterfaceSkeleton *interface_,
6fcf6b
        * properly before building the hooked_vtable, so we create it
6fcf6b
        * once at the last minute.
6fcf6b
        */
6fcf6b
-      interface_->priv->hooked_vtable = g_memdup (g_dbus_interface_skeleton_get_vtable (interface_), sizeof (GDBusInterfaceVTable));
6fcf6b
+      interface_->priv->hooked_vtable = g_memdup2 (g_dbus_interface_skeleton_get_vtable (interface_), sizeof (GDBusInterfaceVTable));
6fcf6b
       interface_->priv->hooked_vtable->method_call = skeleton_intercept_handle_method_call;
6fcf6b
     }
6fcf6b
 
6fcf6b
diff --git a/gio/gfile.c b/gio/gfile.c
6fcf6b
index ff313ebf8..29ebaaa62 100644
6fcf6b
--- a/gio/gfile.c
6fcf6b
+++ b/gio/gfile.c
6fcf6b
@@ -60,6 +60,7 @@
6fcf6b
 #include "gasyncresult.h"
6fcf6b
 #include "gioerror.h"
6fcf6b
 #include "glibintl.h"
6fcf6b
+#include "gstrfuncsprivate.h"
6fcf6b
 
6fcf6b
 
6fcf6b
 /**
6fcf6b
@@ -7734,7 +7735,7 @@ measure_disk_usage_progress (gboolean reporting,
6fcf6b
   g_main_context_invoke_full (g_task_get_context (task),
6fcf6b
                               g_task_get_priority (task),
6fcf6b
                               measure_disk_usage_invoke_progress,
6fcf6b
-                              g_memdup (&progress, sizeof progress),
6fcf6b
+                              g_memdup2 (&progress, sizeof progress),
6fcf6b
                               g_free);
6fcf6b
 }
6fcf6b
 
6fcf6b
@@ -7752,7 +7753,7 @@ measure_disk_usage_thread (GTask        *task,
6fcf6b
                                  data->progress_callback ? measure_disk_usage_progress : NULL, task,
6fcf6b
                                  &result.disk_usage, &result.num_dirs, &result.num_files,
6fcf6b
                                  &error))
6fcf6b
-    g_task_return_pointer (task, g_memdup (&result, sizeof result), g_free);
6fcf6b
+    g_task_return_pointer (task, g_memdup2 (&result, sizeof result), g_free);
6fcf6b
   else
6fcf6b
     g_task_return_error (task, error);
6fcf6b
 }
6fcf6b
@@ -7776,7 +7777,7 @@ g_file_real_measure_disk_usage_async (GFile                        *file,
6fcf6b
 
6fcf6b
   task = g_task_new (file, cancellable, callback, user_data);
6fcf6b
   g_task_set_source_tag (task, g_file_real_measure_disk_usage_async);
6fcf6b
-  g_task_set_task_data (task, g_memdup (&data, sizeof data), g_free);
6fcf6b
+  g_task_set_task_data (task, g_memdup2 (&data, sizeof data), g_free);
6fcf6b
   g_task_set_priority (task, io_priority);
6fcf6b
 
6fcf6b
   g_task_run_in_thread (task, measure_disk_usage_thread);
6fcf6b
diff --git a/gio/gsettingsschema.c b/gio/gsettingsschema.c
6fcf6b
index 17b7e3b01..499944395 100644
6fcf6b
--- a/gio/gsettingsschema.c
6fcf6b
+++ b/gio/gsettingsschema.c
6fcf6b
@@ -20,6 +20,7 @@
6fcf6b
 
6fcf6b
 #include "gsettingsschema-internal.h"
6fcf6b
 #include "gsettings.h"
6fcf6b
+#include "gstrfuncsprivate.h"
6fcf6b
 
6fcf6b
 #include "gvdb/gvdb-reader.h"
6fcf6b
 #include "strinfo.c"
6fcf6b
@@ -1054,9 +1055,9 @@ g_settings_schema_list_children (GSettingsSchema *schema)
6fcf6b
 
6fcf6b
       if (g_str_has_suffix (key, "/"))
6fcf6b
         {
6fcf6b
-          gint length = strlen (key);
6fcf6b
+          gsize length = strlen (key);
6fcf6b
 
6fcf6b
-          strv[j] = g_memdup (key, length);
6fcf6b
+          strv[j] = g_memdup2 (key, length);
6fcf6b
           strv[j][length - 1] = '\0';
6fcf6b
           j++;
6fcf6b
         }
6fcf6b
diff --git a/gio/gwin32registrykey.c b/gio/gwin32registrykey.c
6fcf6b
index c19fede4e..619fd48af 100644
6fcf6b
--- a/gio/gwin32registrykey.c
6fcf6b
+++ b/gio/gwin32registrykey.c
6fcf6b
@@ -28,6 +28,8 @@
6fcf6b
 #include <ntstatus.h>
6fcf6b
 #include <winternl.h>
6fcf6b
 
6fcf6b
+#include "gstrfuncsprivate.h"
6fcf6b
+
6fcf6b
 #ifndef _WDMDDK_
6fcf6b
 typedef enum _KEY_INFORMATION_CLASS {
6fcf6b
   KeyBasicInformation,
6fcf6b
@@ -247,7 +249,7 @@ g_win32_registry_value_iter_copy (const GWin32RegistryValueIter *iter)
6fcf6b
   new_iter->value_name_size = iter->value_name_size;
6fcf6b
 
6fcf6b
   if (iter->value_data != NULL)
6fcf6b
-    new_iter->value_data = g_memdup (iter->value_data, iter->value_data_size);
6fcf6b
+    new_iter->value_data = g_memdup2 (iter->value_data, iter->value_data_size);
6fcf6b
 
6fcf6b
   new_iter->value_data_size = iter->value_data_size;
6fcf6b
 
6fcf6b
@@ -268,8 +270,8 @@ g_win32_registry_value_iter_copy (const GWin32RegistryValueIter *iter)
6fcf6b
   new_iter->value_data_expanded_charsize = iter->value_data_expanded_charsize;
6fcf6b
 
6fcf6b
   if (iter->value_data_expanded_u8 != NULL)
6fcf6b
-    new_iter->value_data_expanded_u8 = g_memdup (iter->value_data_expanded_u8,
6fcf6b
-                                                 iter->value_data_expanded_charsize);
6fcf6b
+    new_iter->value_data_expanded_u8 = g_memdup2 (iter->value_data_expanded_u8,
6fcf6b
+                                                  iter->value_data_expanded_charsize);
6fcf6b
 
6fcf6b
   new_iter->value_data_expanded_u8_size = iter->value_data_expanded_charsize;
6fcf6b
 
6fcf6b
diff --git a/gio/tests/async-close-output-stream.c b/gio/tests/async-close-output-stream.c
6fcf6b
index 5f6620275..d3f97a119 100644
6fcf6b
--- a/gio/tests/async-close-output-stream.c
6fcf6b
+++ b/gio/tests/async-close-output-stream.c
6fcf6b
@@ -24,6 +24,8 @@
6fcf6b
 #include <stdlib.h>
6fcf6b
 #include <string.h>
6fcf6b
 
6fcf6b
+#include "gstrfuncsprivate.h"
6fcf6b
+
6fcf6b
 #define DATA_TO_WRITE "Hello world\n"
6fcf6b
 
6fcf6b
 typedef struct
6fcf6b
@@ -147,9 +149,9 @@ prepare_data (SetupData *data,
6fcf6b
 
6fcf6b
   data->expected_size = g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (data->data_stream));
6fcf6b
 
6fcf6b
-  g_assert_cmpint (data->expected_size, >, 0);
6fcf6b
+  g_assert_cmpuint (data->expected_size, >, 0);
6fcf6b
 
6fcf6b
-  data->expected_output = g_memdup (written, (guint)data->expected_size);
6fcf6b
+  data->expected_output = g_memdup2 (written, data->expected_size);
6fcf6b
 
6fcf6b
   /* then recreate the streams and prepare them for the asynchronous close */
6fcf6b
   destroy_streams (data);
6fcf6b
diff --git a/gio/tests/gdbus-export.c b/gio/tests/gdbus-export.c
6fcf6b
index ef0dddeee..a3c842360 100644
6fcf6b
--- a/gio/tests/gdbus-export.c
6fcf6b
+++ b/gio/tests/gdbus-export.c
6fcf6b
@@ -23,6 +23,7 @@
6fcf6b
 #include <string.h>
6fcf6b
 
6fcf6b
 #include "gdbus-tests.h"
6fcf6b
+#include "gstrfuncsprivate.h"
6fcf6b
 
6fcf6b
 /* all tests rely on a shared mainloop */
6fcf6b
 static GMainLoop *loop = NULL;
6fcf6b
@@ -652,7 +653,7 @@ subtree_introspect (GDBusConnection       *connection,
6fcf6b
       g_assert_not_reached ();
6fcf6b
     }
6fcf6b
 
6fcf6b
-  return g_memdup (interfaces, 2 * sizeof (void *));
6fcf6b
+  return g_memdup2 (interfaces, 2 * sizeof (void *));
6fcf6b
 }
6fcf6b
 
6fcf6b
 static const GDBusInterfaceVTable *
6fcf6b
@@ -708,7 +709,7 @@ dynamic_subtree_introspect (GDBusConnection       *connection,
6fcf6b
 {
6fcf6b
   const GDBusInterfaceInfo *interfaces[2] = { &dyna_interface_info, NULL };
6fcf6b
 
6fcf6b
-  return g_memdup (interfaces, 2 * sizeof (void *));
6fcf6b
+  return g_memdup2 (interfaces, 2 * sizeof (void *));
6fcf6b
 }
6fcf6b
 
6fcf6b
 static const GDBusInterfaceVTable *
6fcf6b
diff --git a/gio/win32/gwinhttpfile.c b/gio/win32/gwinhttpfile.c
6fcf6b
index d5df16d91..f424d21cc 100644
6fcf6b
--- a/gio/win32/gwinhttpfile.c
6fcf6b
+++ b/gio/win32/gwinhttpfile.c
6fcf6b
@@ -29,6 +29,7 @@
6fcf6b
 #include "gio/gfile.h"
6fcf6b
 #include "gio/gfileattribute.h"
6fcf6b
 #include "gio/gfileinfo.h"
6fcf6b
+#include "gstrfuncsprivate.h"
6fcf6b
 #include "gwinhttpfile.h"
6fcf6b
 #include "gwinhttpfileinputstream.h"
6fcf6b
 #include "gwinhttpfileoutputstream.h"
6fcf6b
@@ -393,10 +394,10 @@ g_winhttp_file_resolve_relative_path (GFile      *file,
6fcf6b
   child = g_object_new (G_TYPE_WINHTTP_FILE, NULL);
6fcf6b
   child->vfs = winhttp_file->vfs;
6fcf6b
   child->url = winhttp_file->url;
6fcf6b
-  child->url.lpszScheme = g_memdup (winhttp_file->url.lpszScheme, (winhttp_file->url.dwSchemeLength+1)*2);
6fcf6b
-  child->url.lpszHostName = g_memdup (winhttp_file->url.lpszHostName, (winhttp_file->url.dwHostNameLength+1)*2);
6fcf6b
-  child->url.lpszUserName = g_memdup (winhttp_file->url.lpszUserName, (winhttp_file->url.dwUserNameLength+1)*2);
6fcf6b
-  child->url.lpszPassword = g_memdup (winhttp_file->url.lpszPassword, (winhttp_file->url.dwPasswordLength+1)*2);
6fcf6b
+  child->url.lpszScheme = g_memdup2 (winhttp_file->url.lpszScheme, (winhttp_file->url.dwSchemeLength+1)*2);
6fcf6b
+  child->url.lpszHostName = g_memdup2 (winhttp_file->url.lpszHostName, (winhttp_file->url.dwHostNameLength+1)*2);
6fcf6b
+  child->url.lpszUserName = g_memdup2 (winhttp_file->url.lpszUserName, (winhttp_file->url.dwUserNameLength+1)*2);
6fcf6b
+  child->url.lpszPassword = g_memdup2 (winhttp_file->url.lpszPassword, (winhttp_file->url.dwPasswordLength+1)*2);
6fcf6b
   child->url.lpszUrlPath = wnew_path;
6fcf6b
   child->url.dwUrlPathLength = wcslen (wnew_path);
6fcf6b
   child->url.lpszExtraInfo = NULL;
6fcf6b
-- 
6fcf6b
2.31.1
6fcf6b
6fcf6b
From 661f5edc901219a1a99bb51f171be13063878bd6 Mon Sep 17 00:00:00 2001
6fcf6b
From: Michael Catanzaro <mcatanzaro@redhat.com>
6fcf6b
Date: Thu, 20 May 2021 15:58:53 -0500
6fcf6b
Subject: [PATCH 6/6] gdatainputstream: replace easy use of g_memdup()
6fcf6b
6fcf6b
This code is passing a gsize, so might as well switch this to g_memdup2().
6fcf6b
6fcf6b
This is the only use of g_memdup() in GLib 2.56 that is not part of GLib
6fcf6b
2.58. All other uses analyzed in glib!2000.
6fcf6b
---
6fcf6b
 gio/gdatainputstream.c | 3 ++-
6fcf6b
 1 file changed, 2 insertions(+), 1 deletion(-)
6fcf6b
6fcf6b
diff --git a/gio/gdatainputstream.c b/gio/gdatainputstream.c
6fcf6b
index 9f207b158..ebef7c797 100644
6fcf6b
--- a/gio/gdatainputstream.c
6fcf6b
+++ b/gio/gdatainputstream.c
6fcf6b
@@ -27,6 +27,7 @@
6fcf6b
 #include "gioenumtypes.h"
6fcf6b
 #include "gioerror.h"
6fcf6b
 #include "glibintl.h"
6fcf6b
+#include "gstrfuncsprivate.h"
6fcf6b
 
6fcf6b
 #include <string.h>
6fcf6b
 
6fcf6b
@@ -1082,7 +1083,7 @@ g_data_input_stream_read_async (GDataInputStream    *stream,
6fcf6b
   data = g_slice_new0 (GDataInputStreamReadData);
6fcf6b
   if (stop_chars_len == -1)
6fcf6b
     stop_chars_len = strlen (stop_chars);
6fcf6b
-  data->stop_chars = g_memdup (stop_chars, stop_chars_len);
6fcf6b
+  data->stop_chars = g_memdup2 (stop_chars, stop_chars_len);
6fcf6b
   data->stop_chars_len = stop_chars_len;
6fcf6b
   data->last_saw_cr = FALSE;
6fcf6b
 
6fcf6b
-- 
6fcf6b
2.31.1