From: terencehill Date: Sat, 10 Feb 2024 11:50:09 +0000 (+0100) Subject: Fix string length checks in world.qc and add VM_TEMPSTRING_MAXSIZE X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=94d74449f36b5750f1d1450b02c3817f179211b1;p=xonotic%2Fxonotic-data.pk3dir.git Fix string length checks in world.qc and add VM_TEMPSTRING_MAXSIZE --- diff --git a/qcsrc/lib/registry.qh b/qcsrc/lib/registry.qh index be67847a4..a610df204 100644 --- a/qcsrc/lib/registry.qh +++ b/qcsrc/lib/registry.qh @@ -184,7 +184,7 @@ void Registry_send(string id, string hash); if (++group_idx < 50) /* this is to reduce strlen calls */ \ continue; \ int group_len = strlen(group); \ - if (str_len + 1 + group_len >= 16383) /* exceeding max string length? */ \ + if (str_len + 1 + group_len >= VM_TEMPSTRING_MAXSIZE) \ { \ /* keep previous digests and replace current string with its digest */ \ s = strcat(substring(s, 0, digests_len), ":", digest_hex("MD4", s)); \ diff --git a/qcsrc/lib/string.qh b/qcsrc/lib/string.qh index 3c39b7c0b..72673b235 100644 --- a/qcsrc/lib/string.qh +++ b/qcsrc/lib/string.qh @@ -4,6 +4,9 @@ #include "sort.qh" #include "oo.qh" +// this is not exactly 16KiB (16384 bytes) because one byte is reserved for the \0 terminator +#define VM_TEMPSTRING_MAXSIZE 16383 + // string logic // // true: is truthy diff --git a/qcsrc/server/world.qc b/qcsrc/server/world.qc index 04706f615..7bbbfa0dd 100644 --- a/qcsrc/server/world.qc +++ b/qcsrc/server/world.qc @@ -332,8 +332,11 @@ void cvar_changes_init() if(adding) { + if (cvar_changes == "") + cvar_changes = "// this server runs at modified server settings:\n"; + cvar_changes = strcat(cvar_changes, k, " \"", v, "\" // \"", d, "\"\n"); - if(strlen(cvar_changes) > 16384) + if(strlen(cvar_changes) >= VM_TEMPSTRING_MAXSIZE) { cvar_changes = "// too many settings have been changed to show them here\n"; adding = 0; @@ -546,8 +549,11 @@ void cvar_changes_init() if(pureadding) { + if (cvar_purechanges == "") + cvar_purechanges = "// this server runs at modified gameplay settings:\n"; + cvar_purechanges = strcat(cvar_purechanges, k, " \"", v, "\" // \"", d, "\"\n"); - if(strlen(cvar_purechanges) > 16384) + if(strlen(cvar_purechanges) >= VM_TEMPSTRING_MAXSIZE) { cvar_purechanges = "// too many settings have been changed to show them here\n"; pureadding = 0; @@ -562,15 +568,13 @@ void cvar_changes_init() // though. } buf_del(h); + if(cvar_changes == "") cvar_changes = "// this server runs at default server settings\n"; - else - cvar_changes = strcat("// this server runs at modified server settings:\n", cvar_changes); cvar_changes = strzone(cvar_changes); + if(cvar_purechanges == "") cvar_purechanges = "// this server runs at default gameplay settings\n"; - else - cvar_purechanges = strcat("// this server runs at modified gameplay settings:\n", cvar_purechanges); cvar_purechanges = strzone(cvar_purechanges); }