mirror of
https://github.com/edubart/otclient.git
synced 2025-04-29 17:19:20 +02:00
Fix out-of-bounds access in Platform::getCPUName (#1115)
This commit is contained in:
parent
c6d0fc0f71
commit
72cc4b2fb0
@ -130,12 +130,13 @@ std::string Platform::getCPUName()
|
|||||||
std::ifstream in("/proc/cpuinfo");
|
std::ifstream in("/proc/cpuinfo");
|
||||||
while(getline(in, line)) {
|
while(getline(in, line)) {
|
||||||
auto strs = stdext::split(line, ":");
|
auto strs = stdext::split(line, ":");
|
||||||
std::string first = strs[0];
|
if(strs.size() == 2) {
|
||||||
std::string second = strs[1];
|
stdext::trim(strs[0]);
|
||||||
stdext::trim(first);
|
if(strs[0] == "model name") {
|
||||||
stdext::trim(second);
|
stdext::trim(strs[1]);
|
||||||
if(strs.size() == 2 && first == "model name")
|
return strs[1];
|
||||||
return second;
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
@ -146,12 +147,13 @@ double Platform::getTotalSystemMemory()
|
|||||||
std::ifstream in("/proc/meminfo");
|
std::ifstream in("/proc/meminfo");
|
||||||
while(getline(in, line)) {
|
while(getline(in, line)) {
|
||||||
auto strs = stdext::split(line, ":");
|
auto strs = stdext::split(line, ":");
|
||||||
std::string first = strs[0];
|
if(strs.size() == 2) {
|
||||||
std::string second = strs[1];
|
stdext::trim(strs[0]);
|
||||||
stdext::trim(first);
|
if(strs[0] == "MemTotal") {
|
||||||
stdext::trim(second);
|
stdext::trim(strs[1]);
|
||||||
if(strs.size() == 2 && first == "MemTotal")
|
return stdext::unsafe_cast<double>(strs[1].substr(0, strs[1].length() - 3)) * 1000;
|
||||||
return stdext::unsafe_cast<double>(second.substr(0, second.length() - 3)) * 1000.0;
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -161,8 +163,7 @@ std::string Platform::getOSName()
|
|||||||
std::string line;
|
std::string line;
|
||||||
std::ifstream in("/etc/issue");
|
std::ifstream in("/etc/issue");
|
||||||
if(getline(in, line)) {
|
if(getline(in, line)) {
|
||||||
std::size_t end = line.find('\\');
|
auto res = line.substr(0, line.find('\\'));
|
||||||
std::string res = line.substr(0, end);
|
|
||||||
stdext::trim(res);
|
stdext::trim(res);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user