utils: fix segfault in iwinfo_hardware_id_from_mtd()

Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
This commit is contained in:
Jo-Philipp Wich 2015-06-01 06:23:14 +02:00
parent e8a1e7d224
commit ade8b1b299

View file

@ -177,8 +177,8 @@ int iwinfo_hardware_id_from_mtd(struct iwinfo_hardware_id *id)
FILE *mtd; FILE *mtd;
uint16_t *bc; uint16_t *bc;
int fd; int fd, off;
unsigned int len, off; unsigned int len;
char buf[128]; char buf[128];
if (!(mtd = fopen("/proc/mtd", "r"))) if (!(mtd = fopen("/proc/mtd", "r")))
@ -186,7 +186,7 @@ int iwinfo_hardware_id_from_mtd(struct iwinfo_hardware_id *id)
while (fgets(buf, sizeof(buf), mtd) != NULL) while (fgets(buf, sizeof(buf), mtd) != NULL)
{ {
if (fscanf(mtd, "mtd%u: %x %*x %127s", &off, &len, buf) < 3 || if (fscanf(mtd, "mtd%d: %x %*x %127s", &off, &len, buf) < 3 ||
(strcmp(buf, "\"boardconfig\"") && strcmp(buf, "\"EEPROM\"") && (strcmp(buf, "\"boardconfig\"") && strcmp(buf, "\"EEPROM\"") &&
strcmp(buf, "\"factory\""))) strcmp(buf, "\"factory\"")))
{ {