Menu

#1 access invalid memory

open
nobody
None
5
2010-06-04
2010-06-04
jamie
No

openfive-in-row/pissrv/src/Game.cpp
void Game::sendMessage(int player, std::string msg)
{
msg += '\n';

size_t total = msg.size();
char* mem = (char*) alloca(total);
memcpy(mem, msg.data(), msg.size());
mem[msg.size()] = 0; //access invalid memory

write(m_sockets[player], mem, total);
}

proposal:
void Game::sendMessage(int player, std::string msg)
{
msg += '\n';
write(m_sockets[player], msg.c_str(), msg.size());
}

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.