From: Gerhard Sittig <gsi@denx.de>
Date: Wed, 5 Jun 2013 12:51:05 +0000 (+0200)
Subject: ac14xx: fix a potential NULL deref in diagnostics
X-Git-Tag: v2025.01-rc5-pxa1908~16142^2~6
X-Git-Url: http://git.dujemihanovic.xyz/img/html/static/git-logo.png?a=commitdiff_plain;h=186f9c130faa3e228b0db7f45de359748f78b1c3;p=u-boot.git

ac14xx: fix a potential NULL deref in diagnostics

getenv() immediately after setenv() may perfectly legally return NULL, so
make sure to not deference an invalid pointer when creating diagnostic output

Signed-off-by: Gerhard Sittig <gsi@denx.de>
---

diff --git a/board/ifm/ac14xx/ac14xx.c b/board/ifm/ac14xx/ac14xx.c
index 74425912d6..f200b45f10 100644
--- a/board/ifm/ac14xx/ac14xx.c
+++ b/board/ifm/ac14xx/ac14xx.c
@@ -209,6 +209,7 @@ static int read_eeprom(void)
 int mac_read_from_eeprom(void)
 {
 	const u8 *mac;
+	const char *mac_txt;
 
 	if (read_eeprom()) {
 		printf("I2C EEPROM read failed.\n");
@@ -230,8 +231,11 @@ int mac_read_from_eeprom(void)
 
 	if (mac && is_valid_ether_addr(mac)) {
 		eth_setenv_enetaddr("ethaddr", mac);
-		printf("DIAG: %s() MAC value [%s]\n",
-			__func__, getenv("ethaddr"));
+		mac_txt = getenv("ethaddr");
+		if (mac_txt)
+			printf("DIAG: MAC value [%s]\n", mac_txt);
+		else
+			printf("DIAG: failed to setup MAC env\n");
 	}
 
 	return 0;