diff mbox series

[U-Boot,04/11] efi_selftest: error handling in SNP test

Message ID 20171008045735.8137-5-xypron.glpk@gmx.de
State Accepted
Commit fdd04563cedb6abbc013821c123f5d7ef3078c31
Delegated to: Alexander Graf
Headers show
Series efi_loader: implement SetWatchdogTimer | expand

Commit Message

Heinrich Schuchardt Oct. 8, 2017, 4:57 a.m. UTC
Avoid NULL pointer dereference after setup failed due to a
missing network.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 lib/efi_selftest/efi_selftest_snp.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Simon Glass Oct. 9, 2017, 4:48 a.m. UTC | #1
On 7 October 2017 at 22:57, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
> Avoid NULL pointer dereference after setup failed due to a
> missing network.
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
>  lib/efi_selftest/efi_selftest_snp.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
diff mbox series

Patch

diff --git a/lib/efi_selftest/efi_selftest_snp.c b/lib/efi_selftest/efi_selftest_snp.c
index 638be0147d..bdd6ce20da 100644
--- a/lib/efi_selftest/efi_selftest_snp.c
+++ b/lib/efi_selftest/efi_selftest_snp.c
@@ -198,7 +198,7 @@  static int setup(const efi_handle_t handle,
 	 */
 	ret = boottime->set_timer(timer, EFI_TIMER_PERIODIC, 10000000);
 	if (ret != EFI_SUCCESS) {
-		efi_st_error("Failed to locate simple network protocol\n");
+		efi_st_error("Failed to set timer\n");
 		return EFI_ST_FAILURE;
 	}
 	/*
@@ -206,6 +206,7 @@  static int setup(const efi_handle_t handle,
 	 */
 	ret = boottime->locate_protocol(&efi_net_guid, NULL, (void **)&net);
 	if (ret != EFI_SUCCESS) {
+		net = NULL;
 		efi_st_error("Failed to locate simple network protocol\n");
 		return EFI_ST_FAILURE;
 	}
@@ -273,6 +274,12 @@  static int execute(void)
 	 */
 	unsigned int timeout = 10;
 
+	/* Setup may have failed */
+	if (!net || !timer) {
+		efi_st_error("Cannot execute test after setup failure\n");
+		return EFI_ST_FAILURE;
+	}
+
 	/*
 	 * Send DHCP discover message
 	 */