From patchwork Thu Jan 17 02:45:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Mendoza-Jonas X-Patchwork-Id: 1026381 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43g7tB5Pq0z9sDP for ; Thu, 17 Jan 2019 13:53:06 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=mendozajonas.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="HX9q8faE"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="f25WCvtG"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 43g7tB3xpjzDqlZ for ; Thu, 17 Jan 2019 13:53:06 +1100 (AEDT) X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=mendozajonas.com (client-ip=66.111.4.29; helo=out5-smtp.messagingengine.com; envelope-from=sam@mendozajonas.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=mendozajonas.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="HX9q8faE"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="f25WCvtG"; dkim-atps=neutral X-Greylist: delayed 452 seconds by postgrey-1.36 at bilbo; Thu, 17 Jan 2019 13:52:57 AEDT Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 43g7t11HMYzDq5f for ; Thu, 17 Jan 2019 13:52:57 +1100 (AEDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id ABADE2856C; Wed, 16 Jan 2019 21:45:22 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 16 Jan 2019 21:45:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= mendozajonas.com; h=from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; s=fm2; bh=LUCn/E01clQoh yMX7TBCKZsRdeYAReYT0W/60lFFZ7E=; b=HX9q8faEOAs9tf/A/6ggqinGGQEDj 01QIVDzGAWltmVCJ80Oj3CqvsHDe6+JX4mjeXgdNinY2jXW2ZYAFWWLXWBPMyGkU i/QpD9UjPHYX5s6kDR51FqKkiMnd3oORTo16BdKFDAuh+lPBm/p2oQKnk0obzpY9 bqnubGJGHt9n69Aj+3ts706mp6liY3/wJBOOo8pgGuklH0wAuoXLlufX0PfIF2IO wJ1rVXLmbhGpZ0NdBoAonbOfGtpioVVG57vaLiVjv74efUFLHyXNLopGo+oUw1Wf la+aBdRqiNCTax5EFDZhYIvFmYlL24otOFO8yZSa4X9Dpgk9aH8plw87w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=LUCn/E01clQohyMX7 TBCKZsRdeYAReYT0W/60lFFZ7E=; b=f25WCvtGPr9YvxYBqWQSe35WfhVuu69V5 mThfD9yXHm5c3iE+hIYIV0VdlwnZuNXGDGl3/rb9LFPUw+fG+rOA2sdvvCTFZvMZ /gPWGD4hW4ij7rZmuuBD7Hdzu52qGIGryTqHKYUJMnbmlUrD851Xh2eUexbEtTCF W0LORuI1HormeVeVvJDjPrRI7w+H7f882qEnkcEAHJ1OBppsnBasJ5OYd0jQcdo9 cH2AzBIA7S0XwTAelU2HHpYPRkfX6zqnd1W1bz2sBBVX2vB+XKO71mCic+NPFwSJ /3cLpIkdJ50+CNBcTQr+QKHUp1oPPoS3J353dTVMLVym7MAUib9rw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledrgeeigdeglecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfhuthenuceurghilhhouhhtmecufedt tdenucenucfjughrpefhvffufffkofgggfestdekredtredttdenucfhrhhomhepufgrmh huvghlucfovghnughoiigrqdflohhnrghsuceoshgrmhesmhgvnhguohiirghjohhnrghs rdgtohhmqeenucfkphepuddvvddrleelrdekvddruddtnecurfgrrhgrmhepmhgrihhlfh hrohhmpehsrghmsehmvghnughoiigrjhhonhgrshdrtghomhenucevlhhushhtvghrufhi iigvpedt X-ME-Proxy: Received: from v4.ozlabs.ibm.com (unknown [122.99.82.10]) by mail.messagingengine.com (Postfix) with ESMTPA id 512C2E453B; Wed, 16 Jan 2019 21:45:21 -0500 (EST) From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH] lib/url: Include port in pb_url_to_string() Date: Thu, 17 Jan 2019 13:45:12 +1100 Message-Id: <20190117024512.24538-1-sam@mendozajonas.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Samuel Mendoza-Jonas Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" 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 +++++++--- test/parser/Makefile.am | 1 + test/parser/test-pxe-pathprefix-port.c | 40 ++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 test/parser/test-pxe-pathprefix-port.c diff --git a/lib/url/url.c b/lib/url/url.c index 44e9ac40..b74018dd 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) diff --git a/test/parser/Makefile.am b/test/parser/Makefile.am index 483add90..f9083bd6 100644 --- a/test/parser/Makefile.am +++ b/test/parser/Makefile.am @@ -75,6 +75,7 @@ parser_TESTS = \ test/parser/test-pxe-non-url-pathprefix-with-conf \ test/parser/test-pxe-pathprefix-discover \ test/parser/test-pxe-pathprefix-discover-mac \ + test/parser/test-pxe-pathprefix-port \ test/parser/test-pxe-path-resolve-relative \ test/parser/test-pxe-path-resolve-absolute \ test/parser/test-pxe-discover-bootfile-root \ diff --git a/test/parser/test-pxe-pathprefix-port.c b/test/parser/test-pxe-pathprefix-port.c new file mode 100644 index 00000000..c7d018e0 --- /dev/null +++ b/test/parser/test-pxe-pathprefix-port.c @@ -0,0 +1,40 @@ + +#include "parser-test.h" + +#if 0 /* PARSER_EMBEDDED_CONFIG */ +default linux + +label linux +kernel ./kernel +append command line +initrd /initrd +#endif + +void run_test(struct parser_test *test) +{ + struct discover_boot_option *opt; + struct discover_context *ctx; + + test_read_conf_embedded_url(test, + "http://host:8080/path/to/pxelinux.cfg/default"); + + test_set_event_source(test); + test_set_event_param(test->ctx->event, "ip", "192.168.0.1"); + test_set_event_param(test->ctx->event, "pxepathprefix", + "http://host:8080/path/to/"); + + test_run_parser(test, "pxe"); + + ctx = test->ctx; + + check_boot_option_count(ctx, 1); + opt = get_boot_option(ctx, 0); + + check_name(opt, "linux"); + check_args(opt, "command line"); + + check_resolved_url_resource(opt->boot_image, + "http://host:8080/path/to/./kernel"); + check_resolved_url_resource(opt->initrd, + "http://host:8080/path/to/initrd"); +}