Problema:
Acesta este un buffer fix pentru sursa serverului si libthecore, menit sa limiteze overflow-urile, flood-ul de pachete, handshake timeout-ul si abuzurile de conexiune pe IP.
Important:
Valorile adaugate in acest tutorial trebuie ajustate in functie de nevoile serverului vostru.
*Link download / Code:
1) libthecore/src/buffer.c
Deschidem libthecore/src/buffer.c si cautam:
Code:
#define __LIBTHECORE__
#include "stdafx.h"
static LPBUFFER normalized_buffer_pool[32] = { NULL, };
#define DEFAULT_POOL_SIZE 8192
Tot in libthecore/src/buffer.c cautam:
Code:
LPBUFFER buffer_new(int size)
{
if (size < 0) {
return NULL;
}
Tot in libthecore/src/buffer.c cautam:
Code:
void buffer_write(LPBUFFER& buffer, const void *src, int length)Tot in libthecore/src/buffer.c cautam functia:
Code:
void buffer_read_proceed(LPBUFFER buffer, int length)Code:
if (length < buffer->length)
{
if (buffer->read_point + length - buffer->mem_data > buffer->mem_size)
{
sys_err("buffer_read_proceed: buffer overflow! length %d read_point %d", length, buffer->read_point - buffer->mem_data);
abort();
}
buffer->read_point += length;
buffer->length -= length;
Tot in libthecore/src/buffer.c cautam:
Code:
void buffer_write_proceed(LPBUFFER buffer, int length)Tot in libthecore/src/buffer.c cautam:
Code:
void buffer_adjust_size(LPBUFFER& buffer, int add_size)Tot in libthecore/src/buffer.c cautam:
Code:
void buffer_realloc(LPBUFFER& buffer, int length)
{
2) game/src/desc.cpp
Deschidem game/src/desc.cpp si cautam:
Code:
void DESC::Initialize()
{
m_bDestroyed = false;
Tot in game/src/desc.cpp cautam functia:
Code:
bool DESC::Setup(LPFDWATCH _fdw, socket_t _fd, const struct sockaddr_in & c_rSockAddr, DWORD _handle, DWORD _handshake)Code:
m_lpFdw = _fdw;
m_sock = _fd;
Tot in functia DESC::Setup cautam:
Code:
m_lpOutputBuffer = buffer_new(DEFAULT_PACKET_BUFFER_SIZE * 2);Tot in game/src/desc.cpp cautam:
Code:
int DESC::ProcessInput()3) game/src/desc.h
Deschidem game/src/desc.h si cautam:
Code:
LPBUFFER m_lpBufferedOutputBuffer;
LPBUFFER m_lpOutputBuffer;
4) game/src/desc_manager.cpp
Deschidem game/src/desc_manager.cpp si cautam:
Code:
LPDESC DESC_MANAGER::AcceptDesc(LPFDWATCH fdw, socket_t s)Tot in game/src/desc_manager.cpp cautam:
Code:
void DESC_MANAGER::DestroyDesc(LPDESC d, bool bEraseFromSet)
{
Explicatie:
Acest fix adauga mai multe masuri de protectie:
- limita maxima pentru bufferul de retea
- validari suplimentare la alocare, scriere si realloc
- protectie impotriva overflow-urilor in buffer
- reset buffer in loc de abort in anumite cazuri
- limitare flood de pachete pe conexiune
- timeout pentru handshake
- limitare numar de conexiuni per IP
- limitare numar total de accept-uri pe secunda
- limitare accept-uri per IP pe secunda
Pe scurt:
este un fix defensiv pentru stabilitate si pentru reducerea abuzurilor de retea.
Atentie:
Valorile precum:
Code:
MAX_NETWORK_BUFFER
MAX_CONNECTION_PER_IP
MAX_ACCEPT_PER_SEC
MAX_ACCEPT_PER_IP_PER_SEC


la acest mesaj și conținutul se va afișa automat.

