summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Georg <mail@jensge.org>2021-07-03 19:08:51 +0200
committerJens Georg <mail@jensge.org>2021-07-03 19:08:51 +0200
commit587f3f0e01d4ffd03024a4895f991271abb0b556 (patch)
tree96eaef356ba37cae80d654a21b481e273c2ef003
parentb6c27fa9470098b3038d19e60c94ac65fec288b9 (diff)
downloadgupnp-587f3f0e01d4ffd03024a4895f991271abb0b556.tar.gz
service,context: Re-use is_ours from GSSDP
Drop the custom implementation in Context.
-rw-r--r--libgupnp/gupnp-context-private.h3
-rw-r--r--libgupnp/gupnp-context.c26
-rw-r--r--libgupnp/gupnp-service.c13
-rw-r--r--meson.build2
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
@@ -28,9 +28,6 @@ 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);
gboolean
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
@@ -1673,32 +1673,6 @@ gupnp_context_rewrite_uri_to_uri (GUPnPContext *context, const char *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,
guint context_port)
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')