Skip to content
Snippets Groups Projects
Commit 457b761d authored by Hanicef's avatar Hanicef
Browse files

Fix segfault when sending excessively large netcmds

parent 1ae07f83
Branches
Tags
1 merge request!2568Lift NetXCmd limits
...@@ -64,6 +64,12 @@ void SendNetXCmd(netxcmd_t id, const void *param, size_t nparam) ...@@ -64,6 +64,12 @@ void SendNetXCmd(netxcmd_t id, const void *param, size_t nparam)
{ {
textcmdbuf_t *buf = textcmdbuf; textcmdbuf_t *buf = textcmdbuf;
if (2+nparam > MAXTEXTCMD)
{
CONS_Alert(CONS_ERROR, M_GetText("packet too large to fit NetXCmd, cannot add netcmd %d! (size: %s, max: %d)\n"), id, sizeu1(2+nparam), MAXTEXTCMD);
return;
}
// for future reference: if (cv_debug) != debug disabled. // for future reference: if (cv_debug) != debug disabled.
CONS_Alert(CONS_NOTICE, M_GetText("NetXCmd buffer full, delaying netcmd %d... (size: %d, needed: %s)\n"), id, localtextcmd[0], sizeu1(nparam)); CONS_Alert(CONS_NOTICE, M_GetText("NetXCmd buffer full, delaying netcmd %d... (size: %d, needed: %s)\n"), id, localtextcmd[0], sizeu1(nparam));
if (buf == NULL) if (buf == NULL)
...@@ -79,16 +85,16 @@ void SendNetXCmd(netxcmd_t id, const void *param, size_t nparam) ...@@ -79,16 +85,16 @@ void SendNetXCmd(netxcmd_t id, const void *param, size_t nparam)
buf = buf->next; buf = buf->next;
if (buf->cmd[0]+2+nparam > MAXTEXTCMD) if (buf->cmd[0]+2+nparam > MAXTEXTCMD)
{
WriteNetXCmd(buf->cmd, id, param, nparam);
}
else
{ {
buf->next = Z_Malloc(sizeof(textcmdbuf_t), PU_STATIC, NULL); buf->next = Z_Malloc(sizeof(textcmdbuf_t), PU_STATIC, NULL);
buf->next->cmd[0] = 0; buf->next->cmd[0] = 0;
buf->next->next = NULL; buf->next->next = NULL;
WriteNetXCmd(buf->next->cmd, id, param, nparam); WriteNetXCmd(buf->next->cmd, id, param, nparam);
} }
else
{
WriteNetXCmd(buf->cmd, id, param, nparam);
}
return; return;
} }
WriteNetXCmd(localtextcmd, id, param, nparam); WriteNetXCmd(localtextcmd, id, param, nparam);
...@@ -101,6 +107,12 @@ void SendNetXCmd2(netxcmd_t id, const void *param, size_t nparam) ...@@ -101,6 +107,12 @@ void SendNetXCmd2(netxcmd_t id, const void *param, size_t nparam)
{ {
textcmdbuf_t *buf = textcmdbuf2; textcmdbuf_t *buf = textcmdbuf2;
if (2+nparam > MAXTEXTCMD)
{
CONS_Alert(CONS_ERROR, M_GetText("packet too large to fit NetXCmd, cannot add netcmd %d! (size: %s, max: %d)\n"), id, sizeu1(2+nparam), MAXTEXTCMD);
return;
}
// for future reference: if (cv_debug) != debug disabled. // for future reference: if (cv_debug) != debug disabled.
CONS_Alert(CONS_NOTICE, M_GetText("NetXCmd buffer full, delaying netcmd %d... (size: %d, needed: %s)\n"), id, localtextcmd2[0], sizeu1(nparam)); CONS_Alert(CONS_NOTICE, M_GetText("NetXCmd buffer full, delaying netcmd %d... (size: %d, needed: %s)\n"), id, localtextcmd2[0], sizeu1(nparam));
if (buf == NULL) if (buf == NULL)
...@@ -116,16 +128,16 @@ void SendNetXCmd2(netxcmd_t id, const void *param, size_t nparam) ...@@ -116,16 +128,16 @@ void SendNetXCmd2(netxcmd_t id, const void *param, size_t nparam)
buf = buf->next; buf = buf->next;
if (buf->cmd[0]+2+nparam > MAXTEXTCMD) if (buf->cmd[0]+2+nparam > MAXTEXTCMD)
{
WriteNetXCmd(buf->cmd, id, param, nparam);
}
else
{ {
buf->next = Z_Malloc(sizeof(textcmdbuf_t), PU_STATIC, NULL); buf->next = Z_Malloc(sizeof(textcmdbuf_t), PU_STATIC, NULL);
buf->next->cmd[0] = 0; buf->next->cmd[0] = 0;
buf->next->next = NULL; buf->next->next = NULL;
WriteNetXCmd(buf->next->cmd, id, param, nparam); WriteNetXCmd(buf->next->cmd, id, param, nparam);
} }
else
{
WriteNetXCmd(buf->cmd, id, param, nparam);
}
return; return;
} }
WriteNetXCmd(localtextcmd2, id, param, nparam); WriteNetXCmd(localtextcmd2, id, param, nparam);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment