char *Info_FindLargestKey( char *s, int maxsize ) { char key[256]; char value[256]; char *o; int l; static char largest_key[256]; int largest_size = 0; *largest_key = 0; if (*s == '\\') s++; while (*s) { int size = 0; o = key; while (*s && *s != '\\') *o++ = *s++; l = o - key; *o = 0; size = strlen( key ); if (!*s) { return largest_key; } o = value; s++; while (*s && *s != '\\') *o++ = *s++; *o = 0; if (*s) s++; size += strlen( value ); if ( (size > largest_size) && !Info_IsKeyImportant(key) ) { largest_size = size; strcpy( largest_key, key ); } } return largest_key; }
void Info_SetValueForStarKey ( char *s, const char *key, const char *value, int maxsize ) { char news[1024], *v; int c; if (strstr (key, "\\") || strstr (value, "\\") ) { return; } if (strstr (key, "..") || strstr (value, "..") ) { // Con_Printf ("Can't use keys or values with a ..\n"); return; } if (strstr (key, "\"") || strstr (value, "\"") ) { return; } if (strlen(key) > MAX_KV_LEN || strlen(value) > MAX_KV_LEN) { return; } Info_RemoveKey (s, key); if (!value || !strlen(value)) return; sprintf (news, "\\%s\\%s", key, value); if ( (int)(strlen(news) + strlen(s)) >= maxsize) { // no more room in buffer to add key/value if ( Info_IsKeyImportant( key ) ) { // keep removing the largest key/values until we have room char *largekey; do { largekey = Info_FindLargestKey( s, maxsize ); Info_RemoveKey( s, largekey ); } while ( ((int)(strlen(news) + strlen(s)) >= maxsize) && *largekey != 0 ); if ( largekey[0] == 0 ) { // no room to add setting return; } } else { // no room to add setting return; } } // only copy ascii values s += strlen(s); v = news; while (*v) { c = (unsigned char)*v++; // Strip out high ascii characters c &= 127; if (c > 13) { *s++ = c; } } *s = 0; }
/* <41063> ../engine/info.c:275 */ void Info_SetValueForStarKey(char *s, const char *key, const char *value, int maxsize) { char newArray[MAX_INFO_STRING]; char *v; int c; if (!key || !value) { Con_Printf("Keys and values can't be null\n"); return; } if (key[0] == 0) { Con_Printf("Keys can't be an empty string\n"); return; } if (Q_strstr(key, "\\") || Q_strstr(value, "\\")) { Con_Printf("Can't use keys or values with a \\\n"); return; } if (Q_strstr(key, "..") || Q_strstr(value, "..")) { // TODO: Why silently return? //Con_Printf("Can't use keys or values with a ..\n"); return; } if (Q_strstr(key, "\"") || Q_strstr(value, "\"")) { Con_Printf("Can't use keys or values with a \"\n"); return; } int keyLen = Q_strlen(key); int valueLan = Q_strlen(value); if (keyLen >= MAX_KV_LEN || valueLan >= MAX_KV_LEN) { Con_Printf("Keys and values must be < %i characters\n", MAX_KV_LEN); return; } if (!Q_UnicodeValidate(key) || !Q_UnicodeValidate(value)) { Con_Printf("Keys and values must be valid utf8 text\n"); return; } // Remove current key/value and return if we doesn't specified to set a value Info_RemoveKey(s, key); if (value[0] == 0) { return; } // Create key/value pair Q_snprintf(newArray, MAX_INFO_STRING - 1, "\\%s\\%s", key, value); newArray[MAX_INFO_STRING - 1] = 0; int neededLength = Q_strlen(newArray); if ((int)Q_strlen(s) + neededLength >= maxsize) { // no more room in the buffer to add key/value if (!Info_IsKeyImportant(key)) { // no room to add setting Con_Printf("Info string length exceeded\n"); return; } // keep removing the largest key/values until we have a room char *largekey; do { largekey = Info_FindLargestKey(s, maxsize); if (largekey[0] == 0) { // no room to add setting Con_Printf("Info string length exceeded\n"); return; } Info_RemoveKey(s, largekey); } while ((int)Q_strlen(s) + neededLength >= maxsize); } // auto lowercase team bool lowerCaseValue = Q_stricmp(key, "team") == 0; s += Q_strlen(s); v = newArray; while (*v) { c = (unsigned char)*v++; if (lowerCaseValue) { c = tolower(c); } *s++ = c; } *s = 0; }
/* <40f88> ../engine/info.c:216 */ char *Info_FindLargestKey(char *s, int maxsize) { static char largest_key[MAX_KV_LEN]; char key[MAX_KV_LEN]; char value[MAX_KV_LEN]; char *c; int nCount; int largest_size = 0; largest_key[0] = 0; while (*s) { if (*s == '\\') { s++; // skip the slash } // Copy a key nCount = 0; c = key; while (*s != '\\') { if (!*s) // key should end with a \, not a NULL, return this key, so it will be deleted as wrong { *c = 0; Q_strcpy(largest_key, key); return largest_key; } if (nCount >= MAX_KV_LEN) // oversized key, return this key, so it will be deleted as wrong { *c = 0; Q_strcpy(largest_key, key); return largest_key; } *c++ = *s++; nCount++; } *c = 0; s++; // skip the slash // Get length int size = c - key; // Copy a value nCount = 0; c = value; while (*s != '\\') { if (!*s) { break; // allow value to be ended with NULL } if (nCount >= MAX_KV_LEN) // oversized value, return this key, so it will be deleted as wrong { *c = 0; Q_strcpy(largest_key, key); return largest_key; } *c++ = *s++; nCount++; } *c = 0; // Add length size += c - value; if (size > largest_size && !Info_IsKeyImportant(key)) { largest_size = size; Q_strcpy(largest_key, key); } } return largest_key; }