From 1c3300d4bb8ebaa1023185759d4e34d46321631f Mon Sep 17 00:00:00 2001 From: Garux Date: Mon, 18 Sep 2023 21:30:15 +0600 Subject: [PATCH] be safe while doing copy to EntityClass::flagnames --- libs/eclasslib.h | 4 ++-- radiant/eclass_def.cpp | 2 +- radiant/eclass_fgd.cpp | 4 ++-- radiant/eclass_xml.cpp | 2 +- radiant/entityinspector.cpp | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libs/eclasslib.h b/libs/eclasslib.h index c57c90fc..a926456b 100644 --- a/libs/eclasslib.h +++ b/libs/eclasslib.h @@ -264,8 +264,8 @@ inline EntityClass* Eclass_Alloc(){ e->has_angles = false; e->has_angles_key = false; e->has_direction_key = false; - memset( e->flagnames, 0, MAX_FLAGS * 32 ); - memset( e->flagAttributes, 0, MAX_FLAGS * sizeof( EntityClassAttribute* ) ); + memset( e->flagnames, 0, sizeof( e->flagnames ) ); + memset( e->flagAttributes, 0, sizeof( e->flagAttributes ) ); e->maxs = Vector3( -1,-1,-1 ); e->mins = Vector3( 1, 1, 1 ); diff --git a/radiant/eclass_def.cpp b/radiant/eclass_def.cpp index c32ebb21..c78ce069 100644 --- a/radiant/eclass_def.cpp +++ b/radiant/eclass_def.cpp @@ -268,7 +268,7 @@ EntityClass *Eclass_InitFromText( const char *text ){ if ( !p ) { break; } - strcpy( e->flagnames[i], Get_COM_Token() ); + strncpy( e->flagnames[i], Get_COM_Token(), std::size( e->flagnames[i] ) - 1 ); } } diff --git a/radiant/eclass_fgd.cpp b/radiant/eclass_fgd.cpp index eefab4ad..dde5973a 100644 --- a/radiant/eclass_fgd.cpp +++ b/radiant/eclass_fgd.cpp @@ -353,7 +353,7 @@ void EntityClassFGD_parseClass( Tokeniser& tokeniser, bool fixedsize, bool isBas ASSERT_MESSAGE( EntityClassFGD_parseToken( tokeniser, ":" ), PARSE_ERROR ); const char* name = tokeniser.getToken(); - strcpy( entityClass->flagnames[bit], name ); + strncpy( entityClass->flagnames[bit], name, std::size( entityClass->flagnames[bit] ) - 1 ); EntityClassAttribute *attribute = &EntityClass_insertAttribute( *entityClass, name, EntityClassAttribute( "flag", name ) ).second; entityClass->flagAttributes[bit] = attribute; { @@ -656,7 +656,7 @@ void EntityClassFGD_resolveInheritance( EntityClass* derivedClass ){ for( size_t flag = 0; flag < MAX_FLAGS; ++flag ){ if( !string_empty( parentClass->flagnames[flag] ) && string_empty( derivedClass->flagnames[flag] ) ){ - strcpy( derivedClass->flagnames[flag], parentClass->flagnames[flag] ); + strncpy( derivedClass->flagnames[flag], parentClass->flagnames[flag], std::size( derivedClass->flagnames[flag] ) - 1 ); derivedClass->flagAttributes[flag] = parentClass->flagAttributes[flag]; } } diff --git a/radiant/eclass_xml.cpp b/radiant/eclass_xml.cpp index 4b04fc3d..13b68d56 100644 --- a/radiant/eclass_xml.cpp +++ b/radiant/eclass_xml.cpp @@ -211,7 +211,7 @@ public: std::size_t bit = atoi( element.attribute( "bit" ) ); ASSERT_MESSAGE( bit < MAX_FLAGS, "invalid flag bit" ); ASSERT_MESSAGE( string_empty( entityClass->flagnames[bit] ), "non-unique flag bit" ); - strcpy( entityClass->flagnames[bit], key ); + strncpy( entityClass->flagnames[bit], key, std::size( entityClass->flagnames[bit] ) - 1 ); entityClass->flagAttributes[bit] = m_attribute; } else if( entityClass->fixedsize && string_equal( type, "model" ) ){ diff --git a/radiant/entityinspector.cpp b/radiant/entityinspector.cpp index c5be9524..4dd0eb39 100644 --- a/radiant/entityinspector.cpp +++ b/radiant/entityinspector.cpp @@ -856,7 +856,7 @@ void SpawnFlags_setEntityClass( EntityClass* eclass ){ // do a first pass to count the spawn flags, don't touch the widgets, we don't know in what state they are for ( int i = 0; i < MAX_FLAGS; i++ ) { - if ( eclass->flagnames[i][0] != 0 && strcmp( eclass->flagnames[i],"-" ) ) { + if ( eclass->flagnames[i][0] != 0 && strcmp( eclass->flagnames[i], "-" ) ) { spawn_table[g_spawnflag_count++] = i; } // hide all boxes