From: Jaroslav Kysela Date: Mon, 22 May 2017 16:36:50 +0000 (+0200) Subject: m3u: fix m3u-url decoding X-Git-Tag: v4.2.3~64 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=04267ace9bcd132ee6b3f25e1940cc80c57d77fc;p=thirdparty%2Ftvheadend.git m3u: fix m3u-url decoding --- diff --git a/src/misc/m3u.c b/src/misc/m3u.c index ec1698579..076fa2f96 100644 --- a/src/misc/m3u.c +++ b/src/misc/m3u.c @@ -76,15 +76,15 @@ static char *until_eol(char *d) */ static int is_full_url(const char *url) { - return - strncmp(url, "file://", 7) == 0 || - strncmp(url, "pipe://", 7) == 0 || - strncmp(url, "http://", 7) == 0 || - strncmp(url, "https://", 8) == 0 || - strncmp(url, "rtsp://", 7) == 0 || - strncmp(url, "rtsps://", 8) == 0 || - strncmp(url, "udp://", 6) == 0 || - strncmp(url, "rtp://", 6) == 0; + if (strncmp(url, "file://", 7) == 0) return 7; + if (strncmp(url, "pipe://", 7) == 0) return 7; + if (strncmp(url, "http://", 7) == 0) return 7; + if (strncmp(url, "https://", 8) == 0) return 8; + if (strncmp(url, "rtsp://", 7) == 0) return 7; + if (strncmp(url, "rtsps://", 8) == 0) return 8; + if (strncmp(url, "udp://", 6) == 0) return 6; + if (strncmp(url, "rtp://", 6) == 0) return 6; + return 0; } /* @@ -94,22 +94,19 @@ static const char *get_url (char *buf, size_t buflen, const char *rel, const char *url) { char *url2, *p; + int l; if (url == NULL) return rel; - if (!is_full_url(url) || is_full_url(rel)) + if ((l = is_full_url(url)) == 0 || is_full_url(rel)) return rel; - if (rel[0] == '/') { - snprintf(buf, buflen, "%s%s", url, rel + 1); - } else { - url2 = strdupa(url); - p = strrchr(url2, '/'); - if (p == NULL) - return rel; - *(p + 1) = '\0'; - snprintf(buf, buflen, "%s%s", url2, rel); - } + url2 = strdupa(url); + p = strchr(url2 + l, '/'); + if (p == NULL) + return rel; + *(p + (rel[0] == '/' ? 0 : 1)) = '\0'; + snprintf(buf, buflen, "%s%s", url2, rel); return buf; }