[U-Boot] [PATCH 1/1] flash: Check info pointer in flash_protect().

Mark Tomlinson mark.tomlinson at alliedtelesis.co.nz
Tue May 18 07:26:35 CEST 2010


Some calls to flash_protect() do not check that info is not
NULL. This change prevents this from causing random memory to
be stomped on.
---
 common/flash.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/common/flash.c b/common/flash.c
index eb4b2f5..dc376ee 100644
--- a/common/flash.c
+++ b/common/flash.c
@@ -43,15 +43,19 @@ extern flash_info_t  flash_info[]; /* info for FLASH chips */
 void
 flash_protect (int flag, ulong from, ulong to, flash_info_t *info)
 {
-	ulong b_end = info->start[0] + info->size - 1;	/* bank end address */
-	short s_end = info->sector_count - 1;	/* index of last sector */
+	ulong b_end;	/* bank end address */
+	short s_end;	/* index of last sector */
 	int i;
 
 	/* Do nothing if input data is bad. */
-	if (info->sector_count == 0 || info->size == 0 || to < from) {
+	if (!info || info->sector_count == 0 || info->size == 0 ||
+	    to < from) {
 		return;
 	}
 
+	b_end = info->start[0] + info->size - 1;
+	s_end = info->sector_count - 1;
+
 	debug ("flash_protect %s: from 0x%08lX to 0x%08lX\n",
 		(flag & FLAG_PROTECT_SET) ? "ON" :
 			(flag & FLAG_PROTECT_CLEAR) ? "OFF" : "???",
-- 
1.6.3


NOTICE: This message contains privileged and confidential
information intended only for the use of the addressee
named above. If you are not the intended recipient of
this message you are hereby notified that you must not
disseminate, copy or take any action in reliance on it.
If you have received this message in error please
notify Allied Telesis Labs Ltd immediately.
Any views expressed in this message are those of the
individual sender, except where the sender has the
authority to issue and specifically states them to
be the views of Allied Telesis Labs.


More information about the U-Boot mailing list