From: Gerhard Sittig Date: Wed, 5 Jun 2013 14:51:05 +0200 Subject: [U-Boot] [PATCH v2 1/7] ac14xx: fix a potential NULL deref in diagnostics In-Reply-To: <1370436671-12422-1-git-send-email-gsi@denx.de> References: <1370257851-27583-1-git-send-email-gsi@denx.de> <1370436671-12422-1-git-send-email-gsi@denx.de> Message-ID: <1370436671-12422-2-git-send-email-gsi@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 --- board/ifm/ac14xx/ac14xx.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/board/ifm/ac14xx/ac14xx.c b/board/ifm/ac14xx/ac14xx.c index 7442591..f200b45 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; -- 1.7.10.4