Missing Validation of String Length

This commit is contained in:
2025-12-09 21:51:47 +01:00
parent 2c45158ee8
commit e5506fd67e

View File

@ -36,10 +36,10 @@ void SMART::readSMARTData(Drive *drive)
sCMD.append(drive->getPath());
const char *cpComand = sCMD.c_str();
//Logger::logThis()->info(cpComand);
// Logger::logThis()->info(cpComand);
FILE *outputfileSmart = popen(cpComand, "r");
size_t len = 0U; // length of found line
size_t len = 0U; // length of found line
char *cLine = NULL; // found line
uint8_t status = 255U;
@ -63,7 +63,7 @@ void SMART::readSMARTData(Drive *drive)
if (status == 0U)
{
// Found S.M.A.R.T. data with this command
//Logger::logThis()->info("Found S.M.A.R.T. data with this command");
// Logger::logThis()->info("Found S.M.A.R.T. data with this command");
break;
}
}
@ -106,7 +106,10 @@ bool SMART::parseModelFamily(string sLine, string &modelFamily)
if (found != string::npos)
{
sLine.erase(0U, sLine.find(": ") + 3U);
sLine.erase(sLine.length() - 3U, 3U);
if (sLine.length() >= 3U)
{
sLine.erase(sLine.length() - 3U, 3U);
}
modelFamily = sLine;
return true;
}
@ -129,7 +132,10 @@ bool SMART::parseModelName(string sLine, string &modelName)
if (found != string::npos)
{
sLine.erase(0U, sLine.find(": ") + 3U);
sLine.erase(sLine.length() - 3U, 3U);
if (sLine.length() >= 3U)
{
sLine.erase(sLine.length() - 3U, 3U);
}
modelName = sLine;
return true;
}
@ -152,7 +158,10 @@ bool SMART::parseSerial(string sLine, string &serial)
if (found != string::npos)
{
sLine.erase(0, sLine.find(": ") + 3);
sLine.erase(sLine.length() - 3, 3);
if (sLine.length() >= 3U)
{
sLine.erase(sLine.length() - 3U, 3U);
}
serial = sLine;
return true;
}
@ -175,7 +184,10 @@ bool SMART::parseCapacity(string sLine, uint64_t &capacity)
if (found != string::npos)
{
sLine.erase(0, sLine.find(": ") + 2);
sLine.erase(sLine.length() - 1, 1);
if (sLine.length() >= 1U)
{
sLine.erase(sLine.length() - 1U, 1U);
}
capacity = stol(sLine);
return true;
}
@ -198,7 +210,10 @@ bool SMART::parseErrorCount(string sLine, uint32_t &errorCount)
if (found != string::npos)
{
sLine.erase(0U, sLine.find(": ") + 2U);
sLine.erase(sLine.length() - 2U, 2U);
if (sLine.length() >= 2U)
{
sLine.erase(sLine.length() - 2U, 2U);
}
errorCount = stol(sLine);
return true;
}
@ -221,7 +236,10 @@ bool SMART::parsePowerOnHours(string sLine, uint32_t &powerOnHours)
if (found != string::npos)
{
sLine.erase(0U, sLine.find(": ") + 2U);
sLine.erase(sLine.length() - 1U, 1U);
if (sLine.length() >= 1U)
{
sLine.erase(sLine.length() - 1U, 1U);
}
powerOnHours = stol(sLine);
return true;
}
@ -244,7 +262,10 @@ bool SMART::parsePowerCycles(string sLine, uint32_t &powerCycles)
if (found != string::npos)
{
sLine.erase(0, sLine.find(": ") + 2);
sLine.erase(sLine.length() - 2, 2);
if (sLine.length() >= 2U)
{
sLine.erase(sLine.length() - 2U, 2U);
}
powerCycles = stol(sLine);
return true;
}
@ -267,7 +288,10 @@ bool SMART::parseTemperature(string sLine, uint32_t &temperature)
if (found != string::npos)
{
sLine.erase(0U, sLine.find(": ") + 2U);
sLine.erase(sLine.length() - 1U, 2U);
if (sLine.length() >= 1U)
{
sLine.erase(sLine.length() - 1U, 2U);
}
if (sLine == "{")
{
temperature = 0U; // this drive doesn't support temperature