use safe strings more

This commit is contained in:
Garux 2021-01-21 18:41:16 +03:00
parent 0ab896b84a
commit b0e62198ba
4 changed files with 8 additions and 12 deletions

View File

@ -164,7 +164,7 @@ void SwapBSPFile( void ){
{ {
if ( doingBSP ){ if ( doingBSP ){
si = ShaderInfoForShader( bspShaders[ i ].shader ); si = ShaderInfoForShader( bspShaders[ i ].shader );
if ( si->remapShader && si->remapShader[ 0 ] ) { if ( !strEmptyOrNull( si->remapShader ) ) {
strcpy( bspShaders[ i ].shader, si->remapShader ); strcpy( bspShaders[ i ].shader, si->remapShader );
} }
} }

View File

@ -835,7 +835,7 @@ for ( i = 0; i < brush->numSides; i++ )
static void ConvertPatch( FILE *f, int num, bspDrawSurface_t *ds, vec3_t origin ){ static void ConvertPatch( FILE *f, int num, bspDrawSurface_t *ds, vec3_t origin ){
int x, y; int x, y;
bspShader_t *shader; bspShader_t *shader;
char *texture; const char *texture;
bspDrawVert_t *dv; bspDrawVert_t *dv;
vec3_t xyz; vec3_t xyz;

View File

@ -116,6 +116,8 @@
#define Q3MAP2_EXPERIMENTAL_SNAP_PLANE_FIX 1 #define Q3MAP2_EXPERIMENTAL_SNAP_PLANE_FIX 1
/* general */ /* general */
// actual shader name length limit depends on game engine and name use manner (plain texture/custom shader)
// now checking it for strlen() < MAX_QPATH (so it's null terminated), though this check may be not enough/too much, depending on the use case
#define MAX_QPATH 64 #define MAX_QPATH 64
#define MAX_IMAGES 512 #define MAX_IMAGES 512

View File

@ -829,7 +829,6 @@ shaderInfo_t *ShaderInfoForShader( const char *shaderName ){
int i; int i;
int deprecationDepth; int deprecationDepth;
shaderInfo_t *si; shaderInfo_t *si;
char shader[ MAX_QPATH ];
/* dummy check */ /* dummy check */
if ( strEmptyOrNull( shaderName ) ) { if ( strEmptyOrNull( shaderName ) ) {
@ -838,11 +837,7 @@ shaderInfo_t *ShaderInfoForShader( const char *shaderName ){
} }
/* strip off extension */ /* strip off extension */
// actual shader name length limit depends on game engine and name use manner (plain texture/custom shader) auto shader = String64()( PathExtensionless( shaderName ) );
// so this check may be not enough/too much, depending on the use case
if( strcpyQ( shader, shaderName, MAX_QPATH ) >= MAX_QPATH )
Error( "Shader name too long: %s", shaderName );
StripExtension( shader );
/* search for it */ /* search for it */
deprecationDepth = 0; deprecationDepth = 0;
@ -853,12 +848,11 @@ shaderInfo_t *ShaderInfoForShader( const char *shaderName ){
/* check if shader is deprecated */ /* check if shader is deprecated */
if ( deprecationDepth < MAX_SHADER_DEPRECATION_DEPTH && !strEmptyOrNull( si->deprecateShader ) ) { if ( deprecationDepth < MAX_SHADER_DEPRECATION_DEPTH && !strEmptyOrNull( si->deprecateShader ) ) {
/* override name */ /* override name */
strcpy( shader, si->deprecateShader ); shader( PathExtensionless( si->deprecateShader ) );
StripExtension( shader );
/* increase deprecation depth */ /* increase deprecation depth */
deprecationDepth++; deprecationDepth++;
if ( deprecationDepth == MAX_SHADER_DEPRECATION_DEPTH ) { if ( deprecationDepth == MAX_SHADER_DEPRECATION_DEPTH ) {
Sys_Warning( "Max deprecation depth of %i is reached on shader '%s'\n", MAX_SHADER_DEPRECATION_DEPTH, shader ); Sys_Warning( "Max deprecation depth of %i is reached on shader '%s'\n", MAX_SHADER_DEPRECATION_DEPTH, shader.c_str() );
} }
/* search again from beginning */ /* search again from beginning */
i = -1; i = -1;
@ -878,7 +872,7 @@ shaderInfo_t *ShaderInfoForShader( const char *shaderName ){
/* allocate a default shader */ /* allocate a default shader */
si = AllocShaderInfo(); si = AllocShaderInfo();
si->shader << shader; si->shader = shader;
LoadShaderImages( si ); LoadShaderImages( si );
FinishShader( si ); FinishShader( si );