mirror of https://github.com/axmolengine/axmol.git
avoid to access invalid memory when received data length is the same as buffer size
This commit is contained in:
parent
66217b7bd1
commit
b7b74f2328
|
@ -1946,6 +1946,12 @@ static void serverEntryPoint(unsigned int port)
|
|||
|
||||
listen(s, 1);
|
||||
|
||||
|
||||
#define MAX_RECEIVED_SIZE 1024
|
||||
#define BUF_SIZE MAX_RECEIVED_SIZE + 1
|
||||
|
||||
char buf[BUF_SIZE] = {0};
|
||||
int readBytes = 0;
|
||||
while (true) {
|
||||
clientSocket = accept(s, NULL, NULL);
|
||||
|
||||
|
@ -1962,10 +1968,8 @@ static void serverEntryPoint(unsigned int port)
|
|||
inData = "connected";
|
||||
// process any input, send any output
|
||||
clearBuffers();
|
||||
|
||||
char buf[1024] = {0};
|
||||
int readBytes = 0;
|
||||
while ((readBytes = (int)::recv(clientSocket, buf, sizeof(buf), 0)) > 0)
|
||||
|
||||
while ((readBytes = (int)::recv(clientSocket, buf, MAX_RECEIVED_SIZE, 0)) > 0)
|
||||
{
|
||||
buf[readBytes] = '\0';
|
||||
// TRACE_DEBUGGER_SERVER("debug server : received command >%s", buf);
|
||||
|
@ -1979,6 +1983,9 @@ static void serverEntryPoint(unsigned int port)
|
|||
cc_closesocket(clientSocket);
|
||||
}
|
||||
} // while(true)
|
||||
|
||||
#undef BUF_SIZE
|
||||
#undef MAX_RECEIVED_SIZE
|
||||
}
|
||||
|
||||
bool JSBDebug_BufferWrite(JSContext* cx, unsigned argc, jsval* vp)
|
||||
|
|
Loading…
Reference in New Issue