- add additional checks for valid firmware config file size;
This commit is contained in:
mtabachenko 2013-04-25 13:53:07 +00:00
parent 79ed5b8117
commit 69d4b84110
1 changed files with 23 additions and 17 deletions

View File

@ -572,29 +572,35 @@ bool CFIRMWARE::load()
fp = fopen(MMU.fw.userfile, "rb"); fp = fopen(MMU.fw.userfile, "rb");
if (fp) if (fp)
{ {
char buf[0x300]; fseek(fp, 0, SEEK_END);
memset(buf, 0, 0x300); if (ftell(fp) == (0x100 + 0x1D6 + 0x300))
if (fread(buf, 1, 0x100, fp) == 0x100)
{ {
printf("- loaded from %s:\n", MMU.fw.userfile); fseek(fp, 0, SEEK_SET);
memcpy(&data[0x3FE00], &buf[0], 0x100); char buf[0x301];
memcpy(&data[0x3FF00], &buf[0], 0x100); memset(buf, 0, sizeof(buf));
printf(" * User settings\n"); if (fread(buf, 1, 0x100, fp) == 0x100)
memset(buf, 0, 0x100);
if (fread(buf, 1, 0x1D6, fp) == 0x1D6)
{ {
memcpy(&data[0x002A], &buf[0], 0x1D6); printf("- loaded firmware config from %s:\n", MMU.fw.userfile);
printf(" * WiFi settings\n"); memcpy(&data[0x3FE00], &buf[0], 0x100);
memcpy(&data[0x3FF00], &buf[0], 0x100);
memset(buf, 0, 0x1D6); printf(" * User settings\n");
if (fread(buf, 1, 0x300, fp) == 0x300) memset(buf, 0, sizeof(buf));
if (fread(buf, 1, 0x1D6, fp) == 0x1D6)
{ {
memcpy(&data[0x3FA00], &buf[0], 0x300); memcpy(&data[0x002A], &buf[0], 0x1D6);
printf(" * WiFi AP settings\n"); printf(" * WiFi settings\n");
memset(buf, 0, sizeof(buf));
if (fread(buf, 1, 0x300, fp) == 0x300)
{
memcpy(&data[0x3FA00], &buf[0], 0x300);
printf(" * WiFi AP settings\n");
}
} }
} }
} }
else
printf("- failed loading firmware config from %s (wrong file size)\n", MMU.fw.userfile);
fclose(fp); fclose(fp);
} }
printf("\n"); printf("\n");