* Is it safe to read from the packet, i.e. didn't we run over the buffer? * In case \c close_connection is true, the connection will be closed when one would * overrun the buffer. When it is false, the connection remains untouched. * @param bytes_to_read The amount of bytes we want to try to read. * @param close_connection Whether to close the connection if one cannot read that amount. * @
| 217 | * @return True if that is safe, otherwise false. |
| 218 | */ |
| 219 | bool Packet::CanReadFromPacket(size_t bytes_to_read, bool close_connection) |
| 220 | { |
| 221 | /* Don't allow reading from a quit client/client who send bad data */ |
| 222 | if (this->cs->HasClientQuit()) return false; |
| 223 | |
| 224 | /* Check if variable is within packet-size */ |
| 225 | if (this->pos + bytes_to_read > this->Size()) { |
| 226 | if (close_connection) this->cs->NetworkSocketHandler::MarkClosed(); |
| 227 | return false; |
| 228 | } |
| 229 | |
| 230 | return true; |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * Check whether the packet, given the position of the "write" pointer, has read |
no test coverage detected