Sanitize the name with a maximum buffer size limit

This commit is contained in:
smallmodel 2024-12-08 12:51:14 +01:00 committed by GitHub
parent 5801af34bb
commit 333c452f44
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 9 additions and 6 deletions

View file

@ -2580,7 +2580,7 @@ void CL_CheckUserinfo( void ) {
// send a reliable userinfo update if needed
if(cvar_modifiedFlags & CVAR_USERINFO)
{
if (Com_SanitizeName(name->string, szSanitizedName)) {
if (Com_SanitizeName(name->string, szSanitizedName, sizeof(szSanitizedName))) {
Cvar_Set("name", szSanitizedName);
}

View file

@ -772,7 +772,7 @@ void G_ClientUserinfoChanged(gentity_t *ent, const char *u)
clientnum = ent - g_entities;
if (gi.SanitizeName(s, client->pers.netname)) {
if (gi.SanitizeName(s, client->pers.netname, sizeof(client->pers.netname))) {
gi.Printf("WARNING: had to sanitize the name for client %i\n", clientnum);
}

View file

@ -478,7 +478,7 @@ typedef struct gameImport_s {
void (*HudDrawAlpha)(int info, float alpha);
void (*HudDrawString)(int info, const char *string);
void (*HudDrawFont)(int info, const char *fontName);
qboolean (*SanitizeName)(const char *oldName, char *newName);
qboolean (*SanitizeName)(const char *oldName, char *newName, size_t bufferSize);
//
// Added in OPM

View file

@ -2372,11 +2372,14 @@ void Com_Shutdown (void) {
}
qboolean Com_SanitizeName( const char *pszOldName, char *pszNewName )
qboolean Com_SanitizeName( const char *pszOldName, char *pszNewName, size_t bufferSize )
{
int i;
qboolean bBadName = qfalse;
const char *p = pszOldName;
size_t maxLength;
maxLength = (bufferSize / sizeof(char)) - 1;
if( *pszOldName && *pszOldName <= ' ' )
{
@ -2389,7 +2392,7 @@ qboolean Com_SanitizeName( const char *pszOldName, char *pszNewName )
}
i = 0;
for( i = 0; *p && *p >= ' '; p++, i++ )
for( i = 0; *p && *p >= ' ' && i < maxLength; p++, i++ )
{
if( *p == '~' || *p == '`' )
{

View file

@ -1155,7 +1155,7 @@ void Com_Init( char *commandLine );
void Com_Frame( void );
void Com_Shutdown( void );
qboolean Com_SanitizeName( const char *pszOldName, char *pszNewName );
qboolean Com_SanitizeName( const char *pszOldName, char *pszNewName, size_t bufferSize );
const char *Com_GetArchiveFileName( const char *filename, const char *extension );
const char *Com_GetArchiveFolder();
void Com_WipeSavegame( const char *savename );