mirror of
https://github.com/flatpak/flatpak.git
synced 2026-05-18 05:38:34 -04:00
Replace calls to g_memdup() with g_memdup2()
g_memdup() is subject to an integer overflow on 64-bit machines if the object being copied is larger than UINT_MAX bytes. I suspect none of these objects can actually be that large in practice, but it's easier to replace all the calls than it is to assess whether we need to replace them. A backport in libglnx is used on systems where GLib is older than 2.68.x. Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
committed by
Simon McVittie
parent
7a144248f2
commit
1eed25617c
@@ -129,7 +129,7 @@ static GVariant *
|
||||
new_bytearray (const guchar *data,
|
||||
gsize len)
|
||||
{
|
||||
gpointer data_copy = g_memdup (data, len);
|
||||
gpointer data_copy = g_memdup2 (data, len);
|
||||
GVariant *ret = g_variant_new_from_data (G_VARIANT_TYPE ("ay"), data_copy,
|
||||
len, FALSE, g_free, data_copy);
|
||||
|
||||
|
||||
@@ -555,8 +555,8 @@ parse_completion_line_to_argv (const char *initial_completion_line,
|
||||
|
||||
/* Make a shallow copy of argv, which will be our "working set" */
|
||||
completion->argc = completion->original_argc;
|
||||
completion->argv = g_memdup (completion->original_argv,
|
||||
sizeof (gchar *) * (completion->original_argc + 1));
|
||||
completion->argv = g_memdup2 (completion->original_argv,
|
||||
sizeof (gchar *) * (completion->original_argc + 1));
|
||||
|
||||
return parse_result;
|
||||
}
|
||||
|
||||
@@ -13002,7 +13002,7 @@ populate_hash_table_from_refs_map (GHashTable *ret_all_refs,
|
||||
continue; /* New timestamp is older, skip this commit */
|
||||
}
|
||||
|
||||
new_timestamp = g_memdup (×tamp, sizeof (guint64));
|
||||
new_timestamp = g_memdup2 (×tamp, sizeof (guint64));
|
||||
}
|
||||
|
||||
g_hash_table_replace (ret_all_refs, g_steal_pointer (&decomposed), ostree_checksum_from_bytes (csum_bytes));
|
||||
|
||||
@@ -3662,7 +3662,7 @@ _ostree_repo_static_delta_superblock_digest (OstreeRepo *repo,
|
||||
g_checksum_get_digest (checksum, digest, &len);
|
||||
|
||||
return g_variant_new_from_data (G_VARIANT_TYPE ("ay"),
|
||||
g_memdup (digest, len), len,
|
||||
g_memdup2 (digest, len), len,
|
||||
FALSE, g_free, FALSE);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user