Advertisement

problems with memcpy

Started by May 16, 2002 02:05 AM
9 comments, last by Lsman11 22 years, 8 months ago
im using tcp/ip with my game server, and i am constantly receiving packets from the client (when they press an input). Anyway, after i transfer 64kb, my server crashes, and it shows me the assembly for memcpy. All this action is going on within a thread. Any ideas? Am i blowing the stack ? I know memcpy doesnt do overflow checks, any ideas to prevent this ? note: packet size about 140 bytes, i can send around 445 before it crashes. Thanks!! Luis
Luis
You''re getting a buffer overflow somehow. Memcpy is trying to put too much into the destination buffer.

You''d have to post the relevant code.

Ben


IcarusIndie.com [ The Rabbit Hole | The Labyrinth | Programming | Gang Wars | The Wall]
Advertisement
Code Snipet...

while(1) //Run Thread Forever
{

stConnection stConnectionBuffer2; //Buffer For Incoming Data
char szPacketBuffer2[32768];
stConnection connectPacket2;
if (timer_1) //Only Run Every .1 Seconds
{

iBytesReceived = 0;
iBytesReceived = Clients[c_position].vGetPacket(szPacketBuffer2);

if(iBytesReceived)
{
memcpy(&stConnectionBuffer2,szPacketBuffer2,sizeof(stConnectionBuffer2));
msg = stConnectionBuffer2.status;
...and so on

Any ideas how to prevent this crash ? Thanks..

Luis
Luis
What does stConnectionBuffer2 look like?


Edit: I meant... what does stConnection look like?


[edited by - Khaile on May 16, 2002 7:10:55 AM]
My Stuff : [ Whispers in Akarra (online rpg) || L33T WAR (multiplayer game) || The Asteroid Menace (another game) ]
Here are my structs:

struct stConnection
{
stPacketHeader stHeader;
int port; //Returns the Port number
int status; //Returns if the User logged in correctly
int ID; //ID in the Current Game
char user[50];
char pass[50];
};

struct stPacketHeader
{
int iType;
int iLength;
int iID;
int iCheckSum;
int iSender;
};

Thanks for the help. ; )

Luis
Luis
Did you make sure you actually received the whole packet, and not just part of one?
Advertisement
well, it works fine 445 times, and then once 64kb have been transferred, it crashes.

Luis
Luis
Do you have a log file?

You should try memcpying the packet contents to a string and then outputing each byte into a log along with the length to see what's going on.

...sizeof(stConnectionBuffer2));

why not make use of iBytesRecieved?

You're basically copying an entire struct everytime which is more data than the packet actually contains. Also you aren't ZeroMemorying your struct OR the buffer so you're getting a lot of crap put into it. That may be causing your problems. It'd be a good idea to clean that up even if it isn't.

Ben



IcarusIndie.com [ The Rabbit Hole | The Labyrinth | Programming | Gang Wars | The Wall]


[edited by - KalvinB on May 16, 2002 3:58:50 PM]
Should i ZeroMemory something AFter i memcpy it ??

Luis
Luis
When you create a data type you need to zero it out before you put anything into it.

Ben




IcarusIndie.com [ The Rabbit Hole | The Labyrinth | Programming | Gang Wars | The Wall]

This topic is closed to new replies.

Advertisement