From 92a12ce39b7b49ab4f992066dcafeab98680232f Mon Sep 17 00:00:00 2001
From: Pavel Grunt <pgrunt@redhat.com>
Date: Wed, 1 Jun 2016 10:04:45 +0200
Subject: [PATCH 09/15] spice-uri: Reset SpiceURI before parsing
Avoid using old values after parsing a new uri.
Related: rhbz#1335239
(cherry picked from commit 024eccefba506f57fbff837c6d75864c51ed2add)
---
src/spice-uri.c | 17 +++++++++++++----
tests/uri.c | 1 +
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/src/spice-uri.c b/src/spice-uri.c
index e2c5c9a..1684328 100644
--- a/src/spice-uri.c
+++ b/src/spice-uri.c
@@ -68,6 +68,15 @@ SpiceURI* spice_uri_new(void)
return self;
}
+static void spice_uri_reset(SpiceURI *self)
+{
+ g_clear_pointer(&self->scheme, g_free);
+ g_clear_pointer(&self->hostname, g_free);
+ g_clear_pointer(&self->user, g_free);
+ g_clear_pointer(&self->password, g_free);
+ self->port = 0;
+}
+
G_GNUC_INTERNAL
gboolean spice_uri_parse(SpiceURI *self, const gchar *_uri, GError **error)
{
@@ -76,6 +85,9 @@ gboolean spice_uri_parse(SpiceURI *self, const gchar *_uri, GError **error)
size_t len;
g_return_val_if_fail(self != NULL, FALSE);
+
+ spice_uri_reset(self);
+
g_return_val_if_fail(_uri != NULL, FALSE);
uri = dup = g_strdup(_uri);
@@ -304,10 +316,7 @@ static void spice_uri_finalize(GObject* obj)
SpiceURI *self;
self = G_TYPE_CHECK_INSTANCE_CAST(obj, SPICE_TYPE_URI, SpiceURI);
- g_free(self->scheme);
- g_free(self->hostname);
- g_free(self->user);
- g_free(self->password);
+ spice_uri_reset(self);
G_OBJECT_CLASS (spice_uri_parent_class)->finalize (obj);
}
diff --git a/tests/uri.c b/tests/uri.c
index b68f159..d57f072 100644
--- a/tests/uri.c
+++ b/tests/uri.c
@@ -87,6 +87,7 @@ static void test_spice_uri_ipv4_good(void)
{"https://127.0.0.1", "https", "127.0.0.1", 3129, NULL, NULL, NULL},
{"127.0.0.1", "http", "127.0.0.1", 3128, NULL, NULL, NULL},
{"http://user:password@host:80", "http", "host", 80, "user", "password", NULL},
+ {"https://host:42", "https", "host", 42, NULL, NULL, NULL}, /* tests resetting of username & password */
};
test_spice_uri_good(valid_test_cases, G_N_ELEMENTS(valid_test_cases));
--
2.5.5