[gupnp/gupnp-1.0] Avoid a crash in gupnp_root_device_constructor()



commit f970f35ab725cc428d069ce354e1b6889f110a4a
Author: Sven Neumann <neumann teufel de>
Date:   Tue Mar 28 09:39:54 2017 +0200

    Avoid a crash in gupnp_root_device_constructor()
    
    The network interface used by GUPnPContext might not be usable
    at the point where gupnp_root_device_constructor() is run, which
    resulted in warnings and a crash when the code tried to use a
    SoupURI pointer that was NULL.
    
    Handle this by letting the GUPnPRootDevice construction fail.
    
    Signed-off-by: Sven Neumann <neumann teufel de>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=780640

 libgupnp/gupnp-context.c     |    5 ++++-
 libgupnp/gupnp-root-device.c |   12 ++++++++++--
 2 files changed, 14 insertions(+), 3 deletions(-)
---
diff --git a/libgupnp/gupnp-context.c b/libgupnp/gupnp-context.c
index 2919ab3..75bea6d 100644
--- a/libgupnp/gupnp-context.c
+++ b/libgupnp/gupnp-context.c
@@ -629,7 +629,10 @@ _gupnp_context_get_server_uri (GUPnPContext *context)
         if (context->priv->server_uri == NULL)
                 context->priv->server_uri = make_server_uri (context);
 
-        return soup_uri_copy (context->priv->server_uri);
+        if (context->priv->server_uri)
+                return soup_uri_copy (context->priv->server_uri);
+
+        return NULL;
 }
 
 /**
diff --git a/libgupnp/gupnp-root-device.c b/libgupnp/gupnp-root-device.c
index cf207fc..19cfd24 100644
--- a/libgupnp/gupnp-root-device.c
+++ b/libgupnp/gupnp-root-device.c
@@ -341,6 +341,13 @@ gupnp_root_device_constructor (GType                  type,
                 return NULL;
         }
 
+        uri = _gupnp_context_get_server_uri (context);
+        if (uri == NULL) {
+                g_warning ("Network interface is not usable");
+
+                return NULL;
+        }
+
         if (g_path_is_absolute (description_path))
                 desc_path = g_strdup (description_path);
         else
@@ -421,10 +428,8 @@ gupnp_root_device_constructor (GType                  type,
         gupnp_context_host_path (context, device->priv->description_dir, "");
 
         /* Generate full location */
-        uri = _gupnp_context_get_server_uri (context);
         soup_uri_set_path (uri, relative_location);
         location = soup_uri_to_string (uri, FALSE);
-        soup_uri_free (uri);
 
         g_free (relative_location);
 
@@ -458,6 +463,9 @@ gupnp_root_device_constructor (GType                  type,
 
  DONE:
         /* Cleanup */
+        if (uri)
+                soup_uri_free (uri);
+
         g_free (desc_path);
         g_free (location);
 


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