[gupnp] Avoid a crash in gupnp_root_device_constructor()
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gupnp] Avoid a crash in gupnp_root_device_constructor()
- Date: Sun, 30 Apr 2017 04:20:07 +0000 (UTC)
commit 47c1514285d1229533c9c0e933f6a627db02f3f4
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-error.h | 2 ++
libgupnp/gupnp-root-device.c | 14 ++++++++++++--
3 files changed, 18 insertions(+), 3 deletions(-)
---
diff --git a/libgupnp/gupnp-context.c b/libgupnp/gupnp-context.c
index 6296684..47a5cb6 100644
--- a/libgupnp/gupnp-context.c
+++ b/libgupnp/gupnp-context.c
@@ -628,7 +628,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-error.h b/libgupnp/gupnp-error.h
index ba0bfb0..3816492 100644
--- a/libgupnp/gupnp-error.h
+++ b/libgupnp/gupnp-error.h
@@ -128,6 +128,7 @@ gupnp_rootdevice_error_quark (void) G_GNUC_CONST;
* @GUPNP_ROOT_DEVICE_ERROR_NO_CONTEXT: No #GUPnPContext was passed to the root device.
* @GUPNP_ROOT_DEVICE_ERROR_NO_DESCRIPTION_PATH: Device description path was missing
* @GUPNP_ROOT_DEVICE_ERROR_NO_DESCRIPTION_FOLDER: Description folder was missing
+ * @GUPNP_ROOT_DEVICE_ERROR_NO_NETWORK: Network interface is not usable
*
* #GError codes used for errors during #GUPnPRootDevice creation
*/
@@ -135,6 +136,7 @@ typedef enum {
GUPNP_ROOT_DEVICE_ERROR_NO_CONTEXT,
GUPNP_ROOT_DEVICE_ERROR_NO_DESCRIPTION_PATH,
GUPNP_ROOT_DEVICE_ERROR_NO_DESCRIPTION_FOLDER,
+ GUPNP_ROOT_DEVICE_ERROR_NO_NETWORK,
GUPNP_ROOT_DEVICE_ERROR_FAIL
} GUPnPRootdeviceError;
diff --git a/libgupnp/gupnp-root-device.c b/libgupnp/gupnp-root-device.c
index 55a2740..4112e94 100644
--- a/libgupnp/gupnp-root-device.c
+++ b/libgupnp/gupnp-root-device.c
@@ -333,6 +333,15 @@ gupnp_root_device_initable_init (GInitable *initable,
return FALSE;
}
+ uri = _gupnp_context_get_server_uri (context);
+ if (uri == NULL) {
+ g_set_error_literal (error,
+ GUPNP_ROOT_DEVICE_ERROR,
+ GUPNP_ROOT_DEVICE_ERROR_NO_NETWORK,
+ "Network interface is not usable");
+
+ return FALSE;
+ }
if (g_path_is_absolute (device->priv->description_path))
desc_path = g_strdup (device->priv->description_path);
@@ -401,10 +410,8 @@ gupnp_root_device_initable_init (GInitable *initable,
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);
@@ -440,6 +447,9 @@ gupnp_root_device_initable_init (GInitable *initable,
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]