From 0475cf691e25ffe50756690d7199d425e200307c Mon Sep 17 00:00:00 2001
From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
Date: Mon, 6 May 2013 12:32:33 -0300
Subject: [PATCH 482/482] Fix net_bootp cmd crash when there isn't network card
Adds a check for a network card available before trying to procedure with bootp.
This fixes the bugzilla bellow:
Bug 960624 - Grub2 crashes when net_bootp command fails
https://bugzilla.redhat.com/show_bug.cgi?id=960624
---
grub-core/net/bootp.c | 6 ++++++
include/grub/err.h | 1 +
2 files changed, 7 insertions(+)
diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c
index af3cb62..26e3be4 100644
--- a/grub-core/net/bootp.c
+++ b/grub-core/net/bootp.c
@@ -483,6 +483,12 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)),
ncards++;
}
+ if (ncards == 0)
+ {
+ err = grub_error (GRUB_ERR_NET_NO_CARD, N_("no network card found"));
+ return err;
+ }
+
ifaces = grub_zalloc (ncards * sizeof (ifaces[0]));
if (!ifaces)
return grub_errno;
diff --git a/include/grub/err.h b/include/grub/err.h
index 0f9b208..9896fcc 100644
--- a/include/grub/err.h
+++ b/include/grub/err.h
@@ -62,6 +62,7 @@ typedef enum
GRUB_ERR_NET_ROUTE_LOOP,
GRUB_ERR_NET_NO_ROUTE,
GRUB_ERR_NET_NO_ANSWER,
+ GRUB_ERR_NET_NO_CARD,
GRUB_ERR_WAIT,
GRUB_ERR_BUG,
GRUB_ERR_NET_PORT_CLOSED,
--
1.8.2.1