From: Jaroslav Kysela Date: Sat, 2 Dec 2017 18:52:13 +0000 (+0100) Subject: url: fix urlrecompose() X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0b24fb8837d2d8cdad8ebddc371d5618ec564b34;p=thirdparty%2Ftvheadend.git url: fix urlrecompose() --- diff --git a/src/url.c b/src/url.c index e79236446..74ba6e653 100644 --- a/src/url.c +++ b/src/url.c @@ -60,12 +60,12 @@ urlrecompose( url_t *url ) size_t len; char *raw, port[16]; - len = strlen(url->scheme) + 4 + + len = (url->scheme ? strlen(url->scheme) : 0) + 4 + (url->user && url->pass ? ((url->user ? strlen(url->user) + 2 : 0) + (url->pass ? strlen(url->pass) : 0)) : 0 ) + - strlen(url->host) + + (url->host ? strlen(url->host) : 0) + (url->port > 0 ? 6 : 0) + (url->path ? strlen(url->path) : 0) + (url->query ? strlen(url->query) : 0); @@ -74,12 +74,15 @@ urlrecompose( url_t *url ) return -ENOMEM; if (url->port > 0 && url->port <= 65535) snprintf(port, sizeof(port), ":%d", url->port); + else + port[0] = '\0'; snprintf(raw, len, "%s%s%s%s%s%s%s", url->scheme ?: "", url->scheme ? "://" : "", url->host ?: "", port, url->path ?: "", (url->query && url->query[0]) ? "?" : "", url->query ?: ""); + free(url->raw); url->raw = raw; return 0; }