From: lordhavoc Date: Mon, 29 Oct 2001 07:17:36 +0000 (+0000) Subject: fixed ED_Print so that it can not cause buffer overflows on large entities X-Git-Tag: RELEASE_0_2_0_RC1~756 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=8c61e260dba4f24b58116db5e2065ab7e32a2b2a;p=xonotic%2Fdarkplaces.git fixed ED_Print so that it can not cause buffer overflows on large entities git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@976 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/pr_edict.c b/pr_edict.c index 23872816..382394dd 100644 --- a/pr_edict.c +++ b/pr_edict.c @@ -545,6 +545,7 @@ For debugging ============= */ // LordHavoc: optimized this to print out much more quickly (tempstring) +// LordHavoc: changed to print out every 4096 characters (incase there are a lot of fields to print) void ED_Print (edict_t *ed) { int l; @@ -553,7 +554,7 @@ void ED_Print (edict_t *ed) int i, j; char *name; int type; - char tempstring[8192]; // temporary string buffer + char tempstring[8192], tempstring2[260]; // temporary string buffers if (ed->free) { @@ -581,15 +582,36 @@ void ED_Print (edict_t *ed) if (j == type_size[type]) continue; + if (strlen(name) > 256) + { + strncpy(tempstring2, name, 256); + tempstring2[256] = tempstring2[257] = tempstring2[258] = '.'; + tempstring2[259] = 0; + name = tempstring2; + } strcat(tempstring, name); for (l = strlen(name);l < 14;l++) strcat(tempstring, " "); strcat(tempstring, " "); - strcat(tempstring, PR_ValueString(d->type, (eval_t *)v)); + name = PR_ValueString(d->type, (eval_t *)v); + if (strlen(name) > 256) + { + strncpy(tempstring2, name, 256); + tempstring2[256] = tempstring2[257] = tempstring2[258] = '.'; + tempstring2[259] = 0; + name = tempstring2; + } + strcat(tempstring, name); strcat(tempstring, "\n"); + if (strlen(tempstring) >= 4096) + { + Con_Printf("%s", tempstring); + tempstring[0] = 0; + } } - Con_Printf(tempstring); + if (tempstring[0]) + Con_Printf("%s", tempstring); } /*