From 8e563d6c4a1ed5c0d6524eaf3f805a539e3a7198 Mon Sep 17 00:00:00 2001 From: myT Date: Thu, 26 May 2022 17:22:20 +0200 Subject: [PATCH] fixed Info_Print crashing when a token is too long too long being >= 512 but < BIG_INFO_KEY/BIG_INFO_VALUE Info_NextPair will still crash when key/value string lengths exceed BIG_INFO_KEY/BIG_INFO_VALUE --- changelog.txt | 2 ++ code/qcommon/common.cpp | 61 +++++++++++++++++------------------------ 2 files changed, 27 insertions(+), 36 deletions(-) diff --git a/changelog.txt b/changelog.txt index 309933b..7913832 100644 --- a/changelog.txt +++ b/changelog.txt @@ -60,6 +60,8 @@ chg: with r_backend GL3, depth fade with MSAA now requires GLSL 4.00 at a minimu chg: with r_backend GL3, alpha to coverage now requires GLSL 4.00 at a minimum +fix: /systeminfo /serverinfo /clientinfo /dumpuser would crash when tokens were too long + fix: with r_lightmap 1 and r_dynamiclight 1, lighting transparent surfaces could crash fix: r_vertexLight 1 no longer applies to non-lightmapped surfaces diff --git a/code/qcommon/common.cpp b/code/qcommon/common.cpp index 03d2e08..c222d55 100644 --- a/code/qcommon/common.cpp +++ b/code/qcommon/common.cpp @@ -490,46 +490,35 @@ static qbool Com_AddStartupCommands() //============================================================================ -void Info_Print( const char *s ) { - char key[512]; - char value[512]; - char *o; - int l; +void Info_Print( const char* string ) +{ + char key[BIG_INFO_KEY]; + char value[BIG_INFO_VALUE]; + const char* const valueMissing = "missing value"; - if (*s == '\\') - s++; - while (*s) - { - o = key; - while (*s && *s != '\\') - *o++ = *s++; - - l = o - key; - if (l < 20) - { - Com_Memset (o, ' ', 20-l); - key[20] = 0; - } - else - *o = 0; - Com_Printf ("%s", key); - - if (!*s) - { - Com_Printf ("MISSING VALUE\n"); - return; + const char* s = string; + int width = 0; + while (*s != '\0') { + Info_NextPair(&s, key, value); + if (key[0] == '\0') { + break; } - o = value; - s++; - while (*s && *s != '\\') - *o++ = *s++; - *o = 0; + const int l = strlen(key); + width = max(width, l); + }; + width += 2; - if (*s) - s++; - Com_Printf ("%s\n", value); - } + s = string; + while (*s != '\0') { + Info_NextPair(&s, key, value); + if (key[0] == '\0') { + break; + } + + const char* const valuePtr = value[0] != '\0' ? value : valueMissing; + Com_Printf(S_COLOR_CVAR "%-*s " S_COLOR_VAL "%s\n", width, key, valuePtr); + }; }