Re: [PATCH spice-gtk 6/9] session: parse spice+unix:// URI

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

 



Hey,

On Tue, Jan 13, 2015 at 05:38:25PM +0100, Marc-André Lureau wrote:
> ---
>  gtk/spice-session.c | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/gtk/spice-session.c b/gtk/spice-session.c
> index 6f04a1a..ecc9e86 100644
> --- a/gtk/spice-session.c
> +++ b/gtk/spice-session.c
> @@ -349,6 +349,7 @@ spice_session_finalize(GObject *gobject)
>  }
>  
>  #define URI_SCHEME_SPICE "spice://"
> +#define URI_SCHEME_SPICE_UNIX "spice+unix://"
>  #define URI_QUERY_START ";?"
>  #define URI_QUERY_SEP   ";&"
>  
> @@ -383,10 +384,15 @@ static int spice_parse_uri(SpiceSession *session, const char *original_uri)
>  
>      uri = g_strdup(original_uri);
>  
> +    if (g_str_has_prefix(uri, URI_SCHEME_SPICE_UNIX)) {
> +        path = g_strdup(uri + strlen(URI_SCHEME_SPICE_UNIX));
> +        goto end;
> +    }
> +
>      /* Break up the URI into its various parts, scheme, authority,
>       * path (ignored) and query
>       */
> -    if (strncmp(uri, URI_SCHEME_SPICE, strlen(URI_SCHEME_SPICE)) != 0) {
> +    if (!g_str_has_prefix(uri, URI_SCHEME_SPICE)) {
>          g_warning("Expected a URI scheme of '%s' in URI '%s'",
>                    URI_SCHEME_SPICE, uri);
>          goto fail;
> @@ -489,14 +495,17 @@ static int spice_parse_uri(SpiceSession *session, const char *original_uri)
>          goto fail;
>      }
>  
> +end:
>      /* parsed ok -> apply */
>      g_free(uri);
>      g_free(unescaped_path);
> +    g_free(s->unix_path);
>      g_free(s->host);
>      g_free(s->port);
>      g_free(s->tls_port);
>      g_free(s->username);
>      g_free(s->password);
> +    s->unix_path = path;

If you reuse 'path', spicy --uri spice://foo/bar/baz?port=5900 will
cause s->unix_path to be set (and since in this case, 'path' is not a
malloc'ed string, this will crash sooner or later when you try to free
s->unix_path). Looks good otherwise.

>      s->host = host;
>      s->port = port;
>      s->tls_port = tls_port;
> @@ -507,6 +516,7 @@ static int spice_parse_uri(SpiceSession *session, const char *original_uri)
>  fail:
>      g_free(uri);
>      g_free(unescaped_path);
> +    g_free(path);

'path' must not be freed when it's set by :

if (path && !(g_str_equal(path, "") || g_str_equal(path, "/"))) {
    g_warning("Unexpected path data '%s' for URI '%s'", path, uri);
    /* don't fail, just ignore */

Christophe

Attachment: pgpbNTb5jQ4w1.pgp
Description: PGP signature

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://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]