1
0
mirror of https://github.com/OpenTTD/OpenTTD.git synced 2025-08-19 12:39:11 +00:00

Fix: comparison of narrow type to wide type in loop (potential for infinite loops)

This commit is contained in:
Rubidium
2021-05-10 23:43:52 +02:00
committed by rubidium42
parent 031e91de6e
commit bb9121dbd4
10 changed files with 21 additions and 20 deletions

View File

@@ -374,14 +374,13 @@ uint64 Packet::Recv_uint64()
*/
void Packet::Recv_string(char *buffer, size_t size, StringValidationSettings settings)
{
PacketSize pos;
char *bufp = buffer;
const char *last = buffer + size - 1;
/* Don't allow reading from a closed socket */
if (cs->HasClientQuit()) return;
pos = this->pos;
size_t pos = this->pos;
while (--size > 0 && pos < this->Size() && (*buffer++ = this->buffer[pos++]) != '\0') {}
if (size == 0 || pos == this->Size()) {
@@ -391,7 +390,9 @@ void Packet::Recv_string(char *buffer, size_t size, StringValidationSettings set
while (pos < this->Size() && this->buffer[pos] != '\0') pos++;
pos++;
}
this->pos = pos;
assert(pos <= std::numeric_limits<PacketSize>::max());
this->pos = static_cast<PacketSize>(pos);
str_validate(bufp, last, settings);
}