Skip to content

Commit

Permalink
ssb: Fix range check in sprom write
Browse files Browse the repository at this point in the history
The range check in the sprom image parser hex2sprom() is broken.
One sprom word is 4 hex characters.
This fixes the check and also adds much better sanity checks to the code.
We better make sure the image is OK by doing some sanity checks to avoid
bricking the device by accident.

Signed-off-by: Michael Buesch <mb@bu3sch.de>
Cc: stable@kernel.org
Signed-off-by: John W. Linville <linville@tuxdriver.com>
  • Loading branch information
Michael Buesch authored and John W. Linville committed Nov 23, 2009
1 parent 3ba6018 commit e33761e
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions drivers/ssb/sprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

#include "ssb_private.h"

#include <linux/ctype.h>


static const struct ssb_sprom *fallback_sprom;

Expand All @@ -33,17 +35,27 @@ static int sprom2hex(const u16 *sprom, char *buf, size_t buf_len,
static int hex2sprom(u16 *sprom, const char *dump, size_t len,
size_t sprom_size_words)
{
char tmp[5] = { 0 };
int cnt = 0;
char c, tmp[5] = { 0 };
int err, cnt = 0;
unsigned long parsed;

if (len < sprom_size_words * 2)
/* Strip whitespace at the end. */
while (len) {
c = dump[len - 1];
if (!isspace(c) && c != '\0')
break;
len--;
}
/* Length must match exactly. */
if (len != sprom_size_words * 4)
return -EINVAL;

while (cnt < sprom_size_words) {
memcpy(tmp, dump, 4);
dump += 4;
parsed = simple_strtoul(tmp, NULL, 16);
err = strict_strtoul(tmp, 16, &parsed);
if (err)
return err;
sprom[cnt++] = swab16((u16)parsed);
}

Expand Down

0 comments on commit e33761e

Please sign in to comment.