Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1mZh6d-0004s8-Ii for mharc-grub-devel@gnu.org; Sun, 10 Oct 2021 18:15:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59466) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZh6c-0004rz-CX for grub-devel@gnu.org; Sun, 10 Oct 2021 18:15:42 -0400 Received: from mail2.cableone.syn-alias.com ([69.168.106.66]:51725 helo=mail.cableone.net) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZh6a-0008Qa-7Z for grub-devel@gnu.org; Sun, 10 Oct 2021 18:15:42 -0400 X-Authed-Username: c2JhbG91c2VrQGNhYmxlb25lLm5ldA== Authentication-Results: smtp02.lapis.bos.sync.lan smtp.user=sbalousek@cableone.net; auth=pass (LOGIN) Received: from [24.119.7.206] ([24.119.7.206:53778] helo=wickedloop.com) by mail.cableone.net (envelope-from ) (ecelerity 3.6.25.56547 r(Core:3.6.25.0)) with ESMTPSA (cipher=DHE-RSA-AES128-GCM-SHA256) id 62/19-11107-80663616; Sun, 10 Oct 2021 18:15:36 -0400 Message-ID: <60f727f2-f3dd-3ad3-9300-4c2da765dc06@wickedloop.com> Date: Sun, 10 Oct 2021 15:15:34 -0700 MIME-Version: 1.0 Subject: Re: [PATCH] net: Allow use of non-standard TCP/IP ports for HTTP protocol. Content-Language: en-US-large To: Daniel Kiper Cc: grub-devel@gnu.org References: <20210905225742.15458-1-sbalousek@wickedloop.com> <20210928142747.gsqbvoni3jjnpijy@tomti.i.net-space.pl> From: Stephen Balousek In-Reply-To: <20210928142747.gsqbvoni3jjnpijy@tomti.i.net-space.pl> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Vade-Verdict: clean X-Vade-Analysis-1: gggruggvucftvghtrhhoucdtuddrgedvtddrvddthedgtdeiucetufdoteggodetrfdotffvucfrrhho X-Vade-Analysis-2: fhhilhgvmecuufgjpfetvefqtfdpuffrmfdpqfgfvfenuceurghilhhouhhtmecufedtudenucesvcft X-Vade-Analysis-3: vggtihhpihgvnhhtshculddquddttddmnecujfgurhepkfffggfuvfhfhfgjtgfgsehtkeertddttdej X-Vade-Analysis-4: necuhfhrohhmpefuthgvphhhvghnuceurghlohhushgvkhcuoehssggrlhhouhhsvghkseifihgtkhgv X-Vade-Analysis-5: ughlohhophdrtghomheqnecuggftrfgrthhtvghrnhepgedvjefhuefggeduhefgvdelheeghefggeeu X-Vade-Analysis-6: tdekvedvjeeikeelfeetjeeltddunecuffhomhgrihhnpeifihgtkhgvughlohhophdrtghomhenucfk X-Vade-Analysis-7: phepvdegrdduudelrdejrddvtdeinecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgv X-Vade-Analysis-8: thepvdegrdduudelrdejrddvtdeipdhhvghlohepfihitghkvggulhhoohhprdgtohhmpdhmrghilhhf X-Vade-Analysis-9: rhhomhepshgsrghlohhushgvkhesfihitghkvggulhhoohhprdgtohhmpdhrtghpthhtohepghhruhgs X-Vade-Analysis-10: qdguvghvvghlsehgnhhurdhorhhgpdhrtghpthhtohepughkihhpvghrsehnvghtqdhsphgrtggvrdhp X-Vade-Analysis-11: lhdphhhoshhtpehsmhhtphdrlhgrphhishdrsghoshdrshihnhgtrdhlrghnpdhsphhfpehnvghuthhr X-Vade-Analysis-12: rghlpdgukhhimheppdhnsggprhgtphhtthhopedvpdetuhhthhdqfghsvghrpehssggrlhhouhhsvghk X-Vade-Analysis-13: segtrggslhgvohhnvgdrnhgvth X-Vade-Client: LAPIS Received-SPF: none client-ip=69.168.106.66; envelope-from=sbalousek@wickedloop.com; helo=mail.cableone.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Oct 2021 22:15:42 -0000 Hi Daniel, Thank you for the review. This is my first submission to the project, and I apologize for my lack of familiarity with the conventions and guidelines. I reworked the patch with your suggested changes, and I also included an attempt at some changes for the documentation. I am not completely sure how to submit a revised patch to the mailing list and still maintain the email thread, so I am appending the new patch to this message. Thanks again, - Steve On 9/28/21 07:27, Daniel Kiper wrote: > On Sun, Sep 05, 2021 at 03:57:42PM -0700, Stephen Balousek wrote: >> Allow the use of HTTP servers listening on ports other 80. This is done >> with an extension to the http notation of either: >> >> (http[,server[,port]]) >> >> - or - >> >> (http[,server[:port]]) >> >> Signed-off-by: Stephen Balousek >> --- >> grub-core/net/http.c | 43 +++++++++++++++++++++++++++++++++++++++---- >> 1 file changed, 39 insertions(+), 4 deletions(-) >> >> diff --git a/grub-core/net/http.c b/grub-core/net/http.c >> index b616cf40b..87e496e7f 100644 >> --- a/grub-core/net/http.c >> +++ b/grub-core/net/http.c >> @@ -312,6 +312,9 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial) >> int i; >> struct grub_net_buff *nb; >> grub_err_t err; >> + char *server_name; >> + char *port_string; >> + long port_number; > s/long/unsigned long/g > >> nb = grub_netbuff_alloc (GRUB_NET_TCP_RESERVE_SIZE >> + sizeof ("GET ") - 1 >> @@ -390,10 +393,42 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial) >> grub_netbuff_put (nb, 2); >> grub_memcpy (ptr, "\r\n", 2); >> >> - data->sock = grub_net_tcp_open (file->device->net->server, >> - HTTP_PORT, http_receive, >> - http_err, NULL, >> - file); >> + port_string = grub_strrchr(file->device->net->server, ','); > Missing space between grub_strrchr and "(". Same thing should be fixed > in the functions calls below. > >> + if (!port_string) > if (port_string == NULL) > >> + { >> + port_string = grub_strrchr(file->device->net->server, ':'); >> + if (grub_strchr(port_string + 1, ']')) > You blindly assume port_string is not NULL here. > >> + { >> + port_string = 0; > port_string = NULL; > >> + } > You do not need these curly brackets. > >> + } >> + if (port_string) > if (port_string != NULL) > >> + { >> + port_number = grub_strtol(port_string + 1, 0, 10); > Please use grub_strtoul() instead of grub_strtol() and handle all errors > properly. The strtoul man page is your friend. > >> + if (port_number <= 0 || port_number > 65535) >> + { >> + return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("invalid port number `%s'"), port_string + 1); >> + } > Please drop these curly brackets. > >> + server_name = grub_strdup(file->device->net->server); > grub_strdup() may return NULL... > >> + server_name[port_string - file->device->net->server] = 0; > s/0/'\0'/ > >> + } >> + else >> + { >> + port_number = HTTP_PORT; >> + server_name = file->device->net->server; >> + } >> + >> + data->sock = grub_net_tcp_open (server_name, >> + port_number, http_receive, >> + http_err, NULL, >> + file); >> + >> + if (server_name != file->device->net->server) >> + { >> + grub_free(server_name); >> + } > Please drop these curly brackets. > > Daniel From 3efc9a7f00a3e8f96609ee95262e87e61d42ce44 Mon Sep 17 00:00:00 2001 From: Stephen Balousek Date: Sun, 10 Oct 2021 15:12:20 -0700 Subject: [PATCH] http: Allow use of non-standard TCP/IP ports To: grub-devel@gnu.org Allow the use of HTTP servers listening on ports other 80. This is done with an extension to the http notation:   (http[,server[,port]])  - or -   (http[,server[:port]]) Signed-off-by: Stephen Balousek ---  docs/grub.texi       | 12 ++++++++++++  grub-core/net/http.c | 37 +++++++++++++++++++++++++++++++++++--  2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/docs/grub.texi b/docs/grub.texi index 99d0a0149..dbafe80d2 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -3011,6 +3011,18 @@ environment variable @samp{net_default_server} is used.  Before using the network drive, you must initialize the network.  @xref{Network}, for more information. +For the @samp{http} network protocol, @code{@var{server}} may specify a +port number other than the default value of @samp{80}. The server name +and port number are separated by either @samp{,} or @samp{:}: + +@itemize @bullet +@item +@code{(http,@var{server},@var{port})} + +@item +@code{(http,@var{server}:@var{port})} +@end itemize +  If you boot GRUB from a CD-ROM, @samp{(cd)} is available. @xref{Making  a GRUB bootable CD-ROM}, for details. diff --git a/grub-core/net/http.c b/grub-core/net/http.c index b616cf40b..eb07e333a 100644 --- a/grub-core/net/http.c +++ b/grub-core/net/http.c @@ -312,6 +312,9 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial)    int i;    struct grub_net_buff *nb;    grub_err_t err; +  char *server_name; +  char *port_string; +  unsigned long port_number;    nb = grub_netbuff_alloc (GRUB_NET_TCP_RESERVE_SIZE                 + sizeof ("GET ") - 1 @@ -390,10 +393,40 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial)    grub_netbuff_put (nb, 2);    grub_memcpy (ptr, "\r\n", 2); -  data->sock = grub_net_tcp_open (file->device->net->server, -                  HTTP_PORT, http_receive, +  port_string = grub_strrchr (file->device->net->server, ','); +  if (port_string == NULL) +    { +      port_string = grub_strrchr (file->device->net->server, ':'); +      if (port_string != NULL && grub_strchr (port_string + 1, ']') != NULL) +      port_string = NULL; +    } +  if (port_string != NULL) +    { +      port_number = grub_strtoul (port_string + 1, 0, 10); +      if (port_number == 0 && grub_errno == GRUB_ERR_BAD_NUMBER) +      return grub_error (GRUB_ERR_BAD_NUMBER, N_("non-numeric or invalid port number `%s'"), port_string + 1); +      if (port_number == 0 || port_number > 65535) +      return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("port number `%s' not in the range of 1 to 65535"), port_string + 1); + +      server_name = grub_strdup (file->device->net->server); +      if (server_name == NULL) +      return grub_errno; +      server_name[port_string - file->device->net->server] = '\0'; +    } +  else +    { +      port_number = HTTP_PORT; +      server_name = file->device->net->server; +    } + +  data->sock = grub_net_tcp_open (server_name, +                  port_number, http_receive,                    http_err, NULL,                    file); + +  if (server_name != file->device->net->server) +      grub_free (server_name); +    if (!data->sock)      {        grub_netbuff_free (nb); -- 2.33.0