[epiphany] sync-crypto: Clarify memory ownership
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] sync-crypto: Clarify memory ownership
- Date: Mon, 21 Nov 2016 19:49:09 +0000 (UTC)
commit 15c52b192a31591ebc8d5bdc77907f67cc2be034
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Mon Nov 21 11:40:02 2016 -0600
sync-crypto: Clarify memory ownership
We were sometimes leaking hash; this fixes that. Also, we had a
use-after-free here using the SoupURI after it had already been freed.
https://bugzilla.gnome.org/show_bug.cgi?id=774804
src/sync/ephy-sync-crypto.c | 22 ++++++++++------------
1 files changed, 10 insertions(+), 12 deletions(-)
---
diff --git a/src/sync/ephy-sync-crypto.c b/src/sync/ephy-sync-crypto.c
index b92fad6..d6a3918 100644
--- a/src/sync/ephy-sync-crypto.c
+++ b/src/sync/ephy-sync-crypto.c
@@ -627,22 +627,23 @@ ephy_sync_crypto_compute_hawk_header (const char *url,
g_return_val_if_fail (key != NULL, NULL);
ts = ephy_sync_utils_current_time_seconds ();
- hash = options ? options->hash : NULL;
+ hash = options ? g_strdup (options->hash) : NULL;
payload = options ? options->payload : NULL;
timestamp = options ? options->timestamp : NULL;
uri = soup_uri_new (url);
- resource = (char *)soup_uri_get_path (uri);
+ resource = soup_uri_get_query (uri) == NULL ? g_strdup (soup_uri_get_path (uri))
+ : g_strconcat (soup_uri_get_path (uri),
+ "?",
+ soup_uri_get_query (uri),
+ NULL);
if (options != NULL && options->nonce != NULL) {
- nonce = options->nonce;
+ nonce = g_strdup (options->nonce);
} else {
nonce = g_malloc0 (NONCE_LEN + 1);
ephy_sync_crypto_random_hex_gen (NULL, NONCE_LEN, (guint8 *)nonce);
}
- if (soup_uri_get_query (uri) != NULL)
- resource = g_strconcat (resource, "?", soup_uri_get_query (uri), NULL);
-
if (timestamp != NULL) {
char *local_time_offset;
gint64 offset;
@@ -707,12 +708,9 @@ ephy_sync_crypto_compute_hawk_header (const char *url,
}
soup_uri_free (uri);
-
- if (options == NULL || options->nonce == NULL)
- g_free (nonce);
-
- if (soup_uri_get_query (uri) != NULL)
- g_free (resource);
+ g_free (hash);
+ g_free (nonce);
+ g_free (resource);
return ephy_sync_crypto_hawk_header_new (header, artifacts);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]