[gupnp/wip/phako/55: 2/3] service,context: Re-use is_ours from GSSDP
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gupnp/wip/phako/55: 2/3] service,context: Re-use is_ours from GSSDP
- Date: Sat, 3 Jul 2021 17:31:01 +0000 (UTC)
commit 587f3f0e01d4ffd03024a4895f991271abb0b556
Author: Jens Georg <mail jensge org>
Date: Sat Jul 3 19:08:51 2021 +0200
service,context: Re-use is_ours from GSSDP
Drop the custom implementation in Context.
libgupnp/gupnp-context-private.h | 3 ---
libgupnp/gupnp-context.c | 26 --------------------------
libgupnp/gupnp-service.c | 13 +++----------
meson.build | 2 +-
4 files changed, 4 insertions(+), 40 deletions(-)
---
diff --git a/libgupnp/gupnp-context-private.h b/libgupnp/gupnp-context-private.h
index 397d14f..e5cd507 100644
--- a/libgupnp/gupnp-context-private.h
+++ b/libgupnp/gupnp-context-private.h
@@ -27,9 +27,6 @@ G_GNUC_INTERNAL SoupURI *
gupnp_context_rewrite_uri_to_uri (GUPnPContext *context,
const char *uri);
-G_GNUC_INTERNAL gboolean
-gupnp_context_ip_is_ours (GUPnPContext *context, const char *address);
-
G_GNUC_INTERNAL gboolean
gupnp_context_validate_host_header (GUPnPContext *context, const char *host);
diff --git a/libgupnp/gupnp-context.c b/libgupnp/gupnp-context.c
index 7cf8ba5..efec13f 100644
--- a/libgupnp/gupnp-context.c
+++ b/libgupnp/gupnp-context.c
@@ -1672,32 +1672,6 @@ gupnp_context_rewrite_uri_to_uri (GUPnPContext *context, const char *uri)
return soup_uri;
}
-gboolean
-gupnp_context_ip_is_ours (GUPnPContext *context, const char *address)
-{
- // TODO: Could easily be in GSSDPClient, which does something similar
- gboolean retval = FALSE;
- GInetAddress *addr = NULL;
- GInetAddressMask *mask = NULL;
-
- addr = g_inet_address_new_from_string (address);
-
- // Link-local addresses are reachable
- if (g_inet_address_get_is_link_local (addr)) {
- retval = TRUE;
- goto out;
- }
-
- mask = gssdp_client_get_address_mask (GSSDP_CLIENT (context));
- retval = g_inet_address_mask_matches (mask, addr);
- g_object_unref (mask);
-
-out:
- g_object_unref (addr);
-
- return retval;
-}
-
gboolean
validate_host_header (const char *host_header,
const char *host_ip,
diff --git a/libgupnp/gupnp-service.c b/libgupnp/gupnp-service.c
index db67d85..b441dd1 100644
--- a/libgupnp/gupnp-service.c
+++ b/libgupnp/gupnp-service.c
@@ -1196,29 +1196,22 @@ add_subscription_callback (GUPnPContext *context,
const char *callback)
{
SoupURI *local_uri = NULL;
- char *host = NULL;
- char *index = NULL;
local_uri = gupnp_context_rewrite_uri_to_uri (context, callback);
if (local_uri == NULL) {
return list;
}
+ const char *host = soup_uri_get_host (local_uri);
+ GSocketAddress *address = g_inet_socket_address_new_from_string (host, 0);
- host = g_strdup (soup_uri_get_host (local_uri));
- index = g_strrstr(host, "%");
- // Cut off network index
- if (index != NULL) {
- *index = '\0';
- }
// CVE-2020-12695: Ignore subscription call-backs that are not "in
// our network segment"
- if (gupnp_context_ip_is_ours (context, host)) {
+ if (gssdp_client_can_reach (GSSDP_CLIENT (context), G_INET_SOCKET_ADDRESS (address))) {
list = g_list_append (list, local_uri);
} else {
g_warning ("%s is not in our network; ignoring", callback);
}
- g_free (host);
return list;
}
diff --git a/meson.build b/meson.build
index 0b8f298..68b43f5 100644
--- a/meson.build
+++ b/meson.build
@@ -21,7 +21,7 @@ conf.set('GLIB_VERSION_MAX_ALLOWED', 'GLIB_VERSION_' + glib_version.underscorify
subdir('internal')
guul = subproject('guul', default_options : ['default_library=static'])
-gssdp_dep = dependency('gssdp-1.2', version : '>= 1.2.3', default_options: ['sniffer=false'])
+gssdp_dep = dependency('gssdp-1.2', version : '>= 1.3.0', default_options: ['sniffer=false'])
gio_unix = dependency('gio-unix-2.0', version: '>= 2.44', required: host_machine.system() != 'windows')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]