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