grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] net: Allow use of non-standard TCP/IP ports for HTTP protoco


From: Daniel Kiper
Subject: Re: [PATCH] net: Allow use of non-standard TCP/IP ports for HTTP protocol.
Date: Tue, 28 Sep 2021 16:27:47 +0200
User-agent: NeoMutt/20170113 (1.7.2)

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 <sbalousek@wickedloop.com>
> ---
>  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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]