diff mbox series

[v3,05/15] efi_loader: add IPv4() to device path to text protocol

Message ID 20241111210959.560738-6-adrianox@gmail.com
State Superseded, archived
Delegated to: Heinrich Schuchardt
Headers show
Series efi_loader: efi http and ipconfig drivers | expand

Commit Message

Adriano Cordova Nov. 11, 2024, 9:09 p.m. UTC
From: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

Implement Ipv4() node support in the device path to text protocol.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Signed-off-by: Adriano Cordova <adrianox@gmail.com>
---

(no changes since v2)

 lib/efi_loader/efi_device_path_to_text.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

Comments

Ilias Apalodimas Nov. 13, 2024, 10:37 a.m. UTC | #1
Hi Heinrich,

On Mon, 11 Nov 2024 at 23:10, Adriano Cordova <adrianox@gmail.com> wrote:
>
> From: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
>
> Implement Ipv4() node support in the device path to text protocol.
>
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> Signed-off-by: Adriano Cordova <adrianox@gmail.com>
> ---
>
> (no changes since v2)
>
>  lib/efi_loader/efi_device_path_to_text.c | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
>
> diff --git a/lib/efi_loader/efi_device_path_to_text.c b/lib/efi_loader/efi_device_path_to_text.c
> index 0c7b30a26e..481a9712d9 100644
> --- a/lib/efi_loader/efi_device_path_to_text.c
> +++ b/lib/efi_loader/efi_device_path_to_text.c
> @@ -8,6 +8,7 @@
>  #include <blk.h>
>  #include <efi_loader.h>
>  #include <malloc.h>
> +#include <net.h>
>
>  #define MAC_OUTPUT_LEN 22
>  #define UNKNOWN_OUTPUT_LEN 23
> @@ -170,6 +171,28 @@ static char *dp_msging(char *s, struct efi_device_path *dp)
>
>                 break;
>         }
> +       case DEVICE_PATH_SUB_TYPE_MSG_IPV4: {
> +               struct efi_device_path_ipv4 *idp =
> +                       (struct efi_device_path_ipv4 *)dp;
> +
> +               s += sprintf(s, "IPv4(%pI4,", &idp->remote_ip_address);
> +               switch (idp->protocol) {
> +               case IPPROTO_TCP:
> +                       s += sprintf(s, "TCP,");
> +               case IPPROTO_UDP:
> +                       s += sprintf(s, "UDP,");
> +               default:
> +                       s += sprintf(s, "0x%x,", idp->protocol);
> +               }
> +               s += sprintf(s, idp->static_ip_address ? "Static" : "DHCP");
> +               s += sprintf(s, ",%pI4", &idp->local_ip_address);
> +               if (idp->dp.length == sizeof(struct efi_device_path_ipv4))
> +                       s += sprintf(s, ",%pI4,%pI4", &idp->gateway_ip_address,
> +                                    &idp->subnet_mask);
> +               s += sprintf(s, ")");

How confident are we that the produced device path won't overflow?
IIRC we only have 512 of space there and sprintf isn't the best tool
to catch overflows.

Thanks
/Ilias
> +
> +               break;
> +       }
>         case DEVICE_PATH_SUB_TYPE_MSG_USB_CLASS: {
>                 struct efi_device_path_usb_class *ucdp =
>                         (struct efi_device_path_usb_class *)dp;
> --
> 2.43.0
>
diff mbox series

Patch

diff --git a/lib/efi_loader/efi_device_path_to_text.c b/lib/efi_loader/efi_device_path_to_text.c
index 0c7b30a26e..481a9712d9 100644
--- a/lib/efi_loader/efi_device_path_to_text.c
+++ b/lib/efi_loader/efi_device_path_to_text.c
@@ -8,6 +8,7 @@ 
 #include <blk.h>
 #include <efi_loader.h>
 #include <malloc.h>
+#include <net.h>
 
 #define MAC_OUTPUT_LEN 22
 #define UNKNOWN_OUTPUT_LEN 23
@@ -170,6 +171,28 @@  static char *dp_msging(char *s, struct efi_device_path *dp)
 
 		break;
 	}
+	case DEVICE_PATH_SUB_TYPE_MSG_IPV4: {
+		struct efi_device_path_ipv4 *idp =
+			(struct efi_device_path_ipv4 *)dp;
+
+		s += sprintf(s, "IPv4(%pI4,", &idp->remote_ip_address);
+		switch (idp->protocol) {
+		case IPPROTO_TCP:
+			s += sprintf(s, "TCP,");
+		case IPPROTO_UDP:
+			s += sprintf(s, "UDP,");
+		default:
+			s += sprintf(s, "0x%x,", idp->protocol);
+		}
+		s += sprintf(s, idp->static_ip_address ? "Static" : "DHCP");
+		s += sprintf(s, ",%pI4", &idp->local_ip_address);
+		if (idp->dp.length == sizeof(struct efi_device_path_ipv4))
+			s += sprintf(s, ",%pI4,%pI4", &idp->gateway_ip_address,
+				     &idp->subnet_mask);
+		s += sprintf(s, ")");
+
+		break;
+	}
 	case DEVICE_PATH_SUB_TYPE_MSG_USB_CLASS: {
 		struct efi_device_path_usb_class *ucdp =
 			(struct efi_device_path_usb_class *)dp;