From 13b557fcbd3f54abe785774aebc283092f2d508c Mon Sep 17 00:00:00 2001 From: havoc Date: Fri, 24 Feb 2006 06:03:21 +0000 Subject: [PATCH] added InfoString_Print modified InfoString_GetValue and InfoString_SetValue to reject " characters git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6025 d7cf8633-e32d-0410-b094-e92efae38249 --- common.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/common.c b/common.c index 1bec373b..efbe9bad 100644 --- a/common.c +++ b/common.c @@ -1274,6 +1274,11 @@ void InfoString_GetValue(const char *buffer, const char *key, char *value, size_ Con_Printf("InfoString_GetValue: key name \"%s\" contains \\ which is not possible in an infostring\n", key); return; } + if (strchr(key, '\"')) + { + Con_Printf("InfoString_SetValue: key name \"%s\" contains \" which is not allowed in an infostring\n", key); + return; + } if (!key[0]) { Con_Printf("InfoString_GetValue: can not look up a key with no name\n"); @@ -1310,6 +1315,11 @@ void InfoString_SetValue(char *buffer, size_t bufferlength, const char *key, con Con_Printf("InfoString_SetValue: \"%s\" \"%s\" contains \\ which is not possible to store in an infostring\n", key, value); return; } + if (strchr(key, '\"') || strchr(value, '\"')) + { + Con_Printf("InfoString_SetValue: \"%s\" \"%s\" contains \" which is not allowed in an infostring\n", key, value); + return; + } if (!key[0]) { Con_Printf("InfoString_SetValue: can not set a key with no name\n"); @@ -1348,6 +1358,35 @@ void InfoString_SetValue(char *buffer, size_t bufferlength, const char *key, con } } +void InfoString_Print(char *buffer) +{ + int i; + char key[2048]; + char value[2048]; + while (*buffer) + { + if (*buffer != '\\') + { + Con_Printf("InfoString_Print: corrupt string\n"); + return; + } + for (buffer++, i = 0;*buffer && *buffer != '\\';buffer++) + if (i < (int)sizeof(key)-1) + key[i++] = *buffer; + key[i] = 0; + if (*buffer != '\\') + { + Con_Printf("InfoString_Print: corrupt string\n"); + return; + } + for (buffer++, i = 0;*buffer && *buffer != '\\';buffer++) + if (i < (int)sizeof(value)-1) + value[i++] = *buffer; + value[i] = 0; + // empty value is an error case + Con_Printf("%20s %s\n", key, value[0] ? value : "NO VALUE"); + } +} //======================================================== // strlcat and strlcpy, from OpenBSD -- 2.39.2