Skip to content

Commit

Permalink
Try to detect corrupt eeprom and not crash
Browse files Browse the repository at this point in the history
  • Loading branch information
dkulp committed Nov 18, 2023
1 parent 887a68c commit 9387ce0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/non-gpl/CapeUtils/CapeUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,13 @@ class CapeInfo {

findCapeEEPROM();
if (EEPROM != "") {
parseEEPROM();
processEEPROM();
try {
parseEEPROM();
processEEPROM();
} catch (std::exception& ex) {
corruptEEPROM = true;
printf("Corrupt EEPROM: %s\n", ex.what());
}
}
loadFiles();
std::filesystem::remove_all(outputPath);
Expand All @@ -562,6 +567,9 @@ class CapeInfo {
}

CapeUtils::CapeStatus capeStatus() {
if (corruptEEPROM) {
return CapeUtils::CapeStatus::CORRUPT;
}
if (validSignature) {
if (ORIGEEPROM.find("sys/bus/i2c") != std::string::npos) {
return CapeUtils::CapeStatus::SIGNED;
Expand Down Expand Up @@ -678,7 +686,7 @@ class CapeInfo {
printf("Couldn't get eeprom\n");
}
printf("Copyng eeprom %s -> %s\n", EEPROM.c_str(), "/home/fpp/media/tmp/eeprom.bin");
removeIfExist( "/home/fpp/media/tmp/eeprom.bin");
removeIfExist("/home/fpp/media/tmp/eeprom.bin");
copyFile(EEPROM, "/home/fpp/media/tmp/eeprom.bin");
ORIGEEPROM = EEPROM;
put_file_contents("/home/fpp/media/tmp/eeprom_location.txt", (uint8_t*)ORIGEEPROM.c_str(), ORIGEEPROM.size());
Expand Down Expand Up @@ -1224,6 +1232,7 @@ class CapeInfo {
bool validSignature = false;
bool hasSignature = false;
bool validEpromLocation = true;
bool corruptEEPROM = false;

std::map<std::string, std::vector<uint8_t>> fileMap;
};
Expand Down
1 change: 1 addition & 0 deletions src/non-gpl/CapeUtils/CapeUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class CapeUtils {

enum class CapeStatus {
NOT_PRESENT,
CORRUPT,
UNSIGNED,
SIGNED_GENERIC,
SIGNED
Expand Down
2 changes: 1 addition & 1 deletion src/non-gpl/CapeUtils/fppcapedetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ int main(int argc, char* argv[]) {
std::filesystem::remove_all(entry.path());
}

if (CapeUtils::INSTANCE.initCape(false) == CapeUtils::CapeStatus::NOT_PRESENT) {
if (CapeUtils::INSTANCE.initCape(false) == CapeUtils::CapeStatus::NOT_PRESENT || CapeUtils::INSTANCE.initCape(false) == CapeUtils::CapeStatus::CORRUPT) {
exit(-1);
}
}

0 comments on commit 9387ce0

Please sign in to comment.