Commit a4e8d9f5f957c7e3972ca9d25f17de5f8acd8244

Authored by Mike Frysinger
Committed by Wolfgang Denk
1 parent 9ed4a9582f

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 <vapier@gentoo.org>

Showing 1 changed file with 6 additions and 3 deletions Side-by-side Diff

... ... @@ -43,14 +43,17 @@
43 43 void
44 44 flash_protect (int flag, ulong from, ulong to, flash_info_t *info)
45 45 {
46   - ulong b_end = info->start[0] + info->size - 1; /* bank end address */
47   - short s_end = info->sector_count - 1; /* index of last sector */
  46 + ulong b_end;
  47 + short s_end;
48 48 int i;
49 49  
50 50 /* Do nothing if input data is bad. */
51   - if (info->sector_count == 0 || info->size == 0 || to < from) {
  51 + if (!info || info->sector_count == 0 || info->size == 0 || to < from) {
52 52 return;
53 53 }
  54 +
  55 + s_end = info->sector_count - 1; /* index of last sector */
  56 + b_end = info->start[0] + info->size - 1; /* bank end address */
54 57  
55 58 debug ("flash_protect %s: from 0x%08lX to 0x%08lX\n",
56 59 (flag & FLAG_PROTECT_SET) ? "ON" :