Re: [PATCH spice-gtk v4 4/8] spice-uri: Reset SpiceUri before parsing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On Mon, May 30, 2016 at 05:46:46PM +0200, Pavel Grunt wrote:
> Avoid using old values after parsing a new uri.
> 
> Related: rhbz#1335239
> ---
>  src/spice-uri.c        | 17 +++++++++++++----
>  tests/test-spice-uri.c |  4 ++--
>  2 files changed, 15 insertions(+), 6 deletions(-)
> 
> diff --git a/src/spice-uri.c b/src/spice-uri.c
> index 3bdb502..9f793de 100644
> --- a/src/spice-uri.c
> +++ b/src/spice-uri.c
> @@ -97,6 +97,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)
>  {
> @@ -105,6 +114,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);
> @@ -333,10 +345,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/test-spice-uri.c b/tests/test-spice-uri.c
> index 00aeea7..e177723 100644
> --- a/tests/test-spice-uri.c
> +++ b/tests/test-spice-uri.c
> @@ -57,10 +57,10 @@ static void test_spice_uri_ipv4_bad(void)
>  static void test_spice_uri_ipv4_good(void)
>  {
>      const struct test_case valid_test_cases[] = {
> -        {"http://127.0.0.1/";, "http", "127.0.0.1", 3128, NULL, NULL, NULL},
> +        {"http://user:password@host:80";, "http", "host", 80, "user", "password", NULL},
> +        {"http://127.0.0.1/";, "http", "127.0.0.1", 3128, NULL, NULL, NULL}, /* reset user & password */
>          {"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},

Why this changes here in the test-spice-uri? I see you moving a test and
including a comment... I would say that this belongs to the first patch?

>      };
>  
>      guint i;
> -- 
> 2.8.3
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@xxxxxxxxxxxxxxxxxxxxx
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]