From 28d0d7035ee3099935ef264db40a86142c098ec5 Mon Sep 17 00:00:00 2001 From: Samuel Mendoza-Jonas Date: Thu, 17 Jan 2019 13:32:24 +1100 Subject: lib/url: Include port in pb_url_to_string() And include a pxe-parser test which uses a port in the path prefix to exercise this. This could cause PXE discovery failures if parameters such as pathprefix included a port in the URL. Signed-off-by: Samuel Mendoza-Jonas --- lib/url/url.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'lib/url/url.c') diff --git a/lib/url/url.c b/lib/url/url.c index 44e9ac4..b74018d 100644 --- a/lib/url/url.c +++ b/lib/url/url.c @@ -265,14 +265,21 @@ int addr_scheme(const char *address) char *pb_url_to_string(struct pb_url *url) { const struct pb_scheme_info *scheme = pb_url_scheme_info(url->scheme); + char *str, *port; assert(scheme); + port = url->port ? talloc_asprintf(url, ":%s", url->port) : NULL; + if (scheme->has_host && addr_scheme(url->host) == AF_INET6) - return talloc_asprintf(url, "%s://[%s]%s", scheme->str, - url->host, url->path); + str = talloc_asprintf(url, "%s://[%s]%s%s", scheme->str, + url->host, port ?: "", url->path); else - return talloc_asprintf(url, "%s://%s%s", scheme->str, - scheme->has_host ? url->host : "", url->path); + str = talloc_asprintf(url, "%s://%s%s%s", scheme->str, + scheme->has_host ? url->host : "", + port ?: "", url->path); + + talloc_free(port); + return str; } static void pb_url_update_full(struct pb_url *url) -- cgit v1.2.1