Limit maximum IP length in case of corrupted data.

This commit is contained in:
John Preston 2017-09-04 14:53:14 +03:00
parent fbf8cd04b5
commit 5b77bd5aa0
1 changed files with 8 additions and 0 deletions

View File

@ -281,6 +281,14 @@ void DcOptions::constructFromSerialized(const QByteArray &serialized) {
for (auto i = 0; i != count; ++i) {
qint32 id = 0, flags = 0, port = 0, ipSize = 0;
stream >> id >> flags >> port >> ipSize;
// https://stackoverflow.com/questions/1076714/max-length-for-client-ip-address
constexpr auto kMaxIpSize = 45;
if (ipSize > kMaxIpSize) {
LOG(("MTP Error: Bad data inside DcOptions::constructFromSerialized()"));
return;
}
std::string ip(ipSize, ' ');
stream.readRawData(&ip[0], ipSize);