facebookarchive / RakNet

RakNet is a cross platform, open source, C++ networking engine for game programmers.
Other
3.3k stars 1.02k forks source link

in TCPInterface::Connect, there may access array overflow #69

Open heroboy opened 9 years ago

heroboy commented 9 years ago
    int newRemoteClientIndex=-1;
    for (newRemoteClientIndex=0; newRemoteClientIndex < remoteClientsLength; newRemoteClientIndex++)
    {
        remoteClients[newRemoteClientIndex].isActiveMutex.Lock();
        if (remoteClients[newRemoteClientIndex].isActive==false)
        {
            remoteClients[newRemoteClientIndex].SetActive(true);
            remoteClients[newRemoteClientIndex].isActiveMutex.Unlock();
            break;
        }
        remoteClients[newRemoteClientIndex].isActiveMutex.Unlock();
    }
    if (newRemoteClientIndex==-1)
        return UNASSIGNED_SYSTEM_ADDRESS;

if all removeClients is inactive then newRemoteClientIndex==remoteClientsLength. But the code doesn't check for that. And use newRemoteClientIndex as usual.