]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Fix string length checks in world.qc and add VM_TEMPSTRING_MAXSIZE
authorterencehill <piuntn@gmail.com>
Sat, 10 Feb 2024 11:50:09 +0000 (12:50 +0100)
committerterencehill <piuntn@gmail.com>
Sat, 10 Feb 2024 11:50:09 +0000 (12:50 +0100)
qcsrc/lib/registry.qh
qcsrc/lib/string.qh
qcsrc/server/world.qc

index be67847a446e63a692d70e6ae4c50a75674eaafd..a610df2044d6745b7ffde1dc6412ce7516cd18b5 100644 (file)
@@ -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)); \
index 3c39b7c0bb8e93a0f94ec95cbd081a41e44ba3e2..72673b2354517e28c5abd96c1cc1eb8f160b5b70 100644 (file)
@@ -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
index 04706f615444d6dd93799473a4ef066b94b30c15..7bbbfa0dd7d9152f8e096f3a778ee0639059bfde 100644 (file)
@@ -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);
 }