flash_protect: check for NULL flash info
PATCH 1/1 flash_protect: check for NULL flash info
If a flash is unable to be detected, and then someone calls flash_protect on it (like the common code does in flash_init), the flash_protect logic will dereference a NULL pointer.
Since flash_protect already does sanity checking on the info structs, add a NULL pointer check in there.
Signed-off-by Mike Frysinger <[email protected]>
--- common/flash.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-)
common/flash.c +6 -3
@@ -43,15 +43,18 @@ 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; +short s_end;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 ; } + s_end = info->sector_count -1 ;/* index of last sector */ + b_end = info->start[0 ] + info->size -1 ;/* bank end address */ + debug ("flash_protect %s: from 0x%08lX to 0x%08lX\n", (flag & FLAG_PROTECT_SET) ? "ON" : (flag & FLAG_PROTECT_CLEAR) ? "OFF" : "???",
Signature · 1 line
1.7.2
Wolfgang Denk
AppliedPATCH 1/1 flash_protect: check for NULL flash info
Dear Mike Frysinger,
Quoted 11 lines · In message <[email protected]> you wrote:
If a flash is unable to be detected, and then someone calls
flash_protecton it (like the common code does inflash_init), theflash_protectlogic will dereference a NULL pointer.Since
flash_protectalready does sanity checking on the info structs, add a NULL pointer check in there.Signed-off-by Mike Frysinger <[email protected]>--- common/flash.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk
Signature · 8 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Hello! I'm from outer space, and I've made myself look like a signa-
ture. While you are reading this, I'm having sex with your eyes. I
know it feels good to you, because you're smiling. I'm very horny, so
send me to someone else when you've had enough. Thanks!
Sincerely, A Stranger in a Strange Land