Missing Validation of String Length
This commit is contained in:
@ -106,7 +106,10 @@ bool SMART::parseModelFamily(string sLine, string &modelFamily)
|
|||||||
if (found != string::npos)
|
if (found != string::npos)
|
||||||
{
|
{
|
||||||
sLine.erase(0U, sLine.find(": ") + 3U);
|
sLine.erase(0U, sLine.find(": ") + 3U);
|
||||||
|
if (sLine.length() >= 3U)
|
||||||
|
{
|
||||||
sLine.erase(sLine.length() - 3U, 3U);
|
sLine.erase(sLine.length() - 3U, 3U);
|
||||||
|
}
|
||||||
modelFamily = sLine;
|
modelFamily = sLine;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -129,7 +132,10 @@ bool SMART::parseModelName(string sLine, string &modelName)
|
|||||||
if (found != string::npos)
|
if (found != string::npos)
|
||||||
{
|
{
|
||||||
sLine.erase(0U, sLine.find(": ") + 3U);
|
sLine.erase(0U, sLine.find(": ") + 3U);
|
||||||
|
if (sLine.length() >= 3U)
|
||||||
|
{
|
||||||
sLine.erase(sLine.length() - 3U, 3U);
|
sLine.erase(sLine.length() - 3U, 3U);
|
||||||
|
}
|
||||||
modelName = sLine;
|
modelName = sLine;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -152,7 +158,10 @@ bool SMART::parseSerial(string sLine, string &serial)
|
|||||||
if (found != string::npos)
|
if (found != string::npos)
|
||||||
{
|
{
|
||||||
sLine.erase(0, sLine.find(": ") + 3);
|
sLine.erase(0, sLine.find(": ") + 3);
|
||||||
sLine.erase(sLine.length() - 3, 3);
|
if (sLine.length() >= 3U)
|
||||||
|
{
|
||||||
|
sLine.erase(sLine.length() - 3U, 3U);
|
||||||
|
}
|
||||||
serial = sLine;
|
serial = sLine;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -175,7 +184,10 @@ bool SMART::parseCapacity(string sLine, uint64_t &capacity)
|
|||||||
if (found != string::npos)
|
if (found != string::npos)
|
||||||
{
|
{
|
||||||
sLine.erase(0, sLine.find(": ") + 2);
|
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);
|
capacity = stol(sLine);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -198,7 +210,10 @@ bool SMART::parseErrorCount(string sLine, uint32_t &errorCount)
|
|||||||
if (found != string::npos)
|
if (found != string::npos)
|
||||||
{
|
{
|
||||||
sLine.erase(0U, sLine.find(": ") + 2U);
|
sLine.erase(0U, sLine.find(": ") + 2U);
|
||||||
|
if (sLine.length() >= 2U)
|
||||||
|
{
|
||||||
sLine.erase(sLine.length() - 2U, 2U);
|
sLine.erase(sLine.length() - 2U, 2U);
|
||||||
|
}
|
||||||
errorCount = stol(sLine);
|
errorCount = stol(sLine);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -221,7 +236,10 @@ bool SMART::parsePowerOnHours(string sLine, uint32_t &powerOnHours)
|
|||||||
if (found != string::npos)
|
if (found != string::npos)
|
||||||
{
|
{
|
||||||
sLine.erase(0U, sLine.find(": ") + 2U);
|
sLine.erase(0U, sLine.find(": ") + 2U);
|
||||||
|
if (sLine.length() >= 1U)
|
||||||
|
{
|
||||||
sLine.erase(sLine.length() - 1U, 1U);
|
sLine.erase(sLine.length() - 1U, 1U);
|
||||||
|
}
|
||||||
powerOnHours = stol(sLine);
|
powerOnHours = stol(sLine);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -244,7 +262,10 @@ bool SMART::parsePowerCycles(string sLine, uint32_t &powerCycles)
|
|||||||
if (found != string::npos)
|
if (found != string::npos)
|
||||||
{
|
{
|
||||||
sLine.erase(0, sLine.find(": ") + 2);
|
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);
|
powerCycles = stol(sLine);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -267,7 +288,10 @@ bool SMART::parseTemperature(string sLine, uint32_t &temperature)
|
|||||||
if (found != string::npos)
|
if (found != string::npos)
|
||||||
{
|
{
|
||||||
sLine.erase(0U, sLine.find(": ") + 2U);
|
sLine.erase(0U, sLine.find(": ") + 2U);
|
||||||
|
if (sLine.length() >= 1U)
|
||||||
|
{
|
||||||
sLine.erase(sLine.length() - 1U, 2U);
|
sLine.erase(sLine.length() - 1U, 2U);
|
||||||
|
}
|
||||||
if (sLine == "{")
|
if (sLine == "{")
|
||||||
{
|
{
|
||||||
temperature = 0U; // this drive doesn't support temperature
|
temperature = 0U; // this drive doesn't support temperature
|
||||||
|
|||||||
Reference in New Issue
Block a user