1From dc8c4d4dc234311b3099e7f1efadf5d9733c81e9 Mon Sep 17 00:00:00 2001 2From: Fabrice Fontaine <fontaine.fabrice@gmail.com> 3Date: Fri, 21 Aug 2020 21:29:00 +0200 4Subject: [PATCH] Drop UpnpInit 5 6UpnpInit has been dropped from libupnp 1.14.x as it can't be fixed 7against CallStranger a.k.a. CVE-2020-12695 so replace it by UpnpInit2 8which is available since version 1.6.7 and 9https://github.com/pupnp/pupnp/commit/2bcbdffd89a70364147d345ec5e70a3fce5cbc29 10 11Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com> 12[Upstream status: 13https://github.com/hzeller/gmrender-resurrect/pull/214] 14--- 15 dist-scripts/centos7/README.md | 2 +- 16 dist-scripts/debian/gmediarender.1 | 8 ++------ 17 dist-scripts/fedora/README.md | 2 +- 18 src/main.c | 13 ++++--------- 19 src/upnp_device.c | 18 +++++++++--------- 20 src/upnp_device.h | 2 +- 21 6 files changed, 18 insertions(+), 27 deletions(-) 22 23diff --git a/dist-scripts/centos7/README.md b/dist-scripts/centos7/README.md 24index 278d777..ed82fb6 100644 25--- a/dist-scripts/centos7/README.md 26+++ b/dist-scripts/centos7/README.md 27@@ -45,7 +45,7 @@ Additional configuration is also recommended, sice there's no configuration file 28 # vi /etc/systemd/system/gmediarender.service.d/customize.conf # or nano, or emacs, or whatever editor you like 29 [Service] 30 ExecStart= 31- ExecStart=/usr/bin/gmediarender --port=49494 --ip-address=<your_IP_address> -f "DLNA Renderer GMediaRender" 32+ ExecStart=/usr/bin/gmediarender --port=49494 --interface-name=<your_interface_name> -f "DLNA Renderer GMediaRender" 33 34 # systemctl daemon-reload 35 # systemctl start gmediarender.service 36diff --git a/dist-scripts/debian/gmediarender.1 b/dist-scripts/debian/gmediarender.1 37index 96123ff..b2b1359 100644 38--- a/dist-scripts/debian/gmediarender.1 39+++ b/dist-scripts/debian/gmediarender.1 40@@ -50,12 +50,8 @@ Usually, it is desirable for the renderer 41 to show up on controllers under a recognisable and unique name. This is 42 the option to set that name. 43 .TP 44-.B \-I, \-\-ip\-address \fI\<ip-address\>\fP 45-The local IP address the service is running and advertised on. 46- 47-This can 48-only be a single address, and must be explicitly specified (i.e. not 49-0.0.0.0). 50+.B \-I, \-\-interface\-name \fI\<interface-name\>\fP 51+The local interface name the service is running and advertised on. 52 .TP 53 .B \-p, \-\-port \fI\<port>\fP 54 Port to listen to. [49152..65535]. 55diff --git a/dist-scripts/fedora/README.md b/dist-scripts/fedora/README.md 56index 7b9ea4b..45aa536 100644 57--- a/dist-scripts/fedora/README.md 58+++ b/dist-scripts/fedora/README.md 59@@ -43,7 +43,7 @@ Additional configuration is also recommended, sice there's no configuration file 60 # vi /etc/systemd/system/gmediarender.service.d/customize.conf # or nano, or emacs, or whatever editor you like 61 [Service] 62 ExecStart= 63- ExecStart=/usr/bin/gmediarender --port=49494 --ip-address=<your_IP_address> -f "DLNA Renderer GMediaRender" 64+ ExecStart=/usr/bin/gmediarender --port=49494 --interface-name=<your_interface_name> -f "DLNA Renderer GMediaRender" 65 66 # systemctl daemon-reload 67 # systemctl start gmediarender.service 68diff --git a/src/main.c b/src/main.c 69index ef720e3..2030c49 100644 70--- a/src/main.c 71+++ b/src/main.c 72@@ -69,11 +69,7 @@ static gboolean show_transport_scpd = FALSE; 73 static gboolean show_outputs = FALSE; 74 static gboolean daemon_mode = FALSE; 75 76-// IP-address seems strange in libupnp: they actually don't bind to 77-// that address, but to INADDR_ANY (miniserver.c in upnp library). 78-// Apparently they just use this for the advertisement ? Anyway, 0.0.0.0 would 79-// not work. 80-static const gchar *ip_address = NULL; 81+static const gchar *interface_name = NULL; 82 static int listen_port = 49494; 83 84 #ifdef GMRENDER_UUID 85@@ -92,9 +88,8 @@ static const gchar *mime_filter = NULL; 86 static GOptionEntry option_entries[] = { 87 { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, 88 "Output version information and exit", NULL }, 89- { "ip-address", 'I', 0, G_OPTION_ARG_STRING, &ip_address, 90- "The local IP address the service is running and advertised " 91- "(only one, 0.0.0.0 won't work)", NULL }, 92+ { "interface-name", 'I', 0, G_OPTION_ARG_STRING, &interface_name, 93+ "The local interface name the service is running and advertised", NULL }, 94 // The following is not very reliable, as libupnp does not set 95 // SO_REUSEADDR by default, so it might increment (sending patch). 96 { "port", 'p', 0, G_OPTION_ARG_INT, &listen_port, 97@@ -302,7 +297,7 @@ int main(int argc, char **argv) 98 listen_port); 99 return EXIT_FAILURE; 100 } 101- device = upnp_device_init(upnp_renderer, ip_address, listen_port); 102+ device = upnp_device_init(upnp_renderer, interface_name, listen_port); 103 if (device == NULL) { 104 Log_error("main", "ERROR: Failed to initialize UPnP device"); 105 return EXIT_FAILURE; 106diff --git a/src/upnp_device.c b/src/upnp_device.c 107index db65e4f..3151238 100644 108--- a/src/upnp_device.c 109+++ b/src/upnp_device.c 110@@ -416,13 +416,13 @@ static UPNP_CALLBACK(event_handler, EventType, event, userdata) 111 112 static gboolean initialize_device(struct upnp_device_descriptor *device_def, 113 struct upnp_device *result_device, 114- const char *ip_address, 115+ const char *interface_name, 116 unsigned short port) 117 { 118 int rc; 119 char *buf; 120 121- rc = UpnpInit(ip_address, port); 122+ rc = UpnpInit2(interface_name, port); 123 /* There have been situations reported in which UPNP had issues 124 * initializing right after network came up. #129 125 */ 126@@ -430,13 +430,13 @@ static gboolean initialize_device(struct upnp_device_descriptor *device_def, 127 static const int kRetryTimeMs = 1000; 128 while (rc != UPNP_E_SUCCESS && retries_left--) { 129 usleep(kRetryTimeMs * 1000); 130- Log_error("upnp", "UpnpInit(ip=%s, port=%d) Error: %s (%d). Retrying... (%ds)", 131- ip_address, port, UpnpGetErrorMessage(rc), rc, retries_left); 132- rc = UpnpInit(ip_address, port); 133+ Log_error("upnp", "UpnpInit2(interface=%s, port=%d) Error: %s (%d). Retrying... (%ds)", 134+ interface_name, port, UpnpGetErrorMessage(rc), rc, retries_left); 135+ rc = UpnpInit2(interface_name, port); 136 } 137 if (UPNP_E_SUCCESS != rc) { 138- Log_error("upnp", "UpnpInit(ip=%s, port=%d) Error: %s (%d). Giving up.", 139- ip_address, port, UpnpGetErrorMessage(rc), rc); 140+ Log_error("upnp", "UpnpInit2(interface=%s, port=%d) Error: %s (%d). Giving up.", 141+ interface_name, port, UpnpGetErrorMessage(rc), rc); 142 return FALSE; 143 } 144 Log_info("upnp", "Registered IP=%s port=%d\n", 145@@ -483,7 +483,7 @@ static gboolean initialize_device(struct upnp_device_descriptor *device_def, 146 } 147 148 struct upnp_device *upnp_device_init(struct upnp_device_descriptor *device_def, 149- const char *ip_address, 150+ const char *interface_name, 151 unsigned short port) 152 { 153 int rc; 154@@ -516,7 +516,7 @@ struct upnp_device *upnp_device_init(struct upnp_device_descriptor *device_def, 155 webserver_register_buf(srv->scpd_url, buf, "text/xml"); 156 } 157 158- if (!initialize_device(device_def, result_device, ip_address, port)) { 159+ if (!initialize_device(device_def, result_device, interface_name, port)) { 160 UpnpFinish(); 161 free(result_device); 162 return NULL; 163diff --git a/src/upnp_device.h b/src/upnp_device.h 164index 3e635e1..8c8e783 100644 165--- a/src/upnp_device.h 166+++ b/src/upnp_device.h 167@@ -49,7 +49,7 @@ struct upnp_device; 168 struct action_event; 169 170 struct upnp_device *upnp_device_init(struct upnp_device_descriptor *device_def, 171- const char *ip_address, 172+ const char *interface_name, 173 unsigned short port); 174 175 void upnp_device_shutdown(struct upnp_device *device); 176