From be05be50692b8fce50dd95eccb69be1c4d3933b6 Mon Sep 17 00:00:00 2001 From: "[CST] Focus" Date: Tue, 18 Jun 2013 16:23:51 +0400 Subject: [PATCH] system/flashtool.cpp: prevent crash on invalid mtdData access, ie pos = -1 if system-fs not found; change sysfs name on apollo --- src/system/flashtool.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/system/flashtool.cpp b/src/system/flashtool.cpp index 2d380bdf0..1a57987f0 100644 --- a/src/system/flashtool.cpp +++ b/src/system/flashtool.cpp @@ -577,22 +577,30 @@ std::string CMTDInfo::getMTDName(const int pos) { // TODO: check /proc/mtd specification to determine mtdname encoding - return FILESYSTEM_ENCODING_TO_UTF8_STRING(mtdData[pos]->name); + if (pos >= 0) + return FILESYSTEM_ENCODING_TO_UTF8_STRING(mtdData[pos]->name); + return ""; } std::string CMTDInfo::getMTDFileName(const int pos) { - return mtdData[pos]->filename; + if (pos >= 0) + return mtdData[pos]->filename; + return ""; } int CMTDInfo::getMTDSize(const int pos) { - return mtdData[pos]->size; + if (pos >= 0) + return mtdData[pos]->size; + return 0; } int CMTDInfo::getMTDEraseSize(const int pos) { - return mtdData[pos]->erasesize; + if (pos >= 0) + return mtdData[pos]->erasesize; + return 0; } int CMTDInfo::findMTDNumber(const std::string & filename) @@ -624,7 +632,11 @@ int CMTDInfo::getMTDEraseSize( const std::string & filename ) std::string CMTDInfo::findMTDsystem() { +#ifdef BOXMODEL_APOLLO + std::string sysfs = "root0"; +#else std::string sysfs = "systemFS"; +#endif for(int i = 0; i < getMTDCount(); i++) { if(getMTDName(i) == sysfs) {