From bb840ceafffd72150b0033d92bf47c2f79352dff Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Fri, 30 Oct 2015 08:47:24 +0000 Subject: [PATCH] Do not assume that the compressed XML data will be NUL terminated In most cases this is out of chance, but in some random cases the gzip decompressor decides to reuse the input buffer as a decompression buffer, which means we get junk data after the decompressed text. To solve this, just truncate the data at the reported size, and then feed this into the XML parser. Fixes: https://github.com/hughsie/fwupd/issues/36 --- src/fu-main.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/fu-main.c b/src/fu-main.c index 58085bfbf..9832f4789 100644 --- a/src/fu-main.c +++ b/src/fu-main.c @@ -701,6 +701,7 @@ fu_main_daemon_update_metadata (FuMainPrivate *priv, gint fd, gint fd_sig, GErro guint i; gsize size; GPtrArray *apps; + g_autofree gchar *xml = NULL; g_autoptr(AsStore) store = NULL; g_autoptr(GBytes) bytes = NULL; g_autoptr(GBytes) bytes_raw = NULL; @@ -764,9 +765,9 @@ fu_main_daemon_update_metadata (FuMainPrivate *priv, gint fd, gint fd_sig, GErro /* load the store locally until we know it is valid */ store = as_store_new (); - if (!as_store_from_xml (store, - g_bytes_get_data (bytes, NULL), - NULL, error)) + data = g_bytes_get_data (bytes, &size); + xml = g_strndup ((const gchar *) data, size); + if (!as_store_from_xml (store, xml, NULL, error)) return FALSE; /* add the new application from the store */