From: Garux Date: Sat, 29 Sep 2018 18:34:03 +0000 (+0300) Subject: fix some strncpy use X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=502b368658d02c5d073f39e84ead0a23624c1acf;p=xonotic%2Fnetradiant.git fix some strncpy use Note by illwieckz: partial cherry-pick, vfsListShaderFiles is missing upstream --- diff --git a/libs/picomodel/pm_3ds.c b/libs/picomodel/pm_3ds.c index c6ac1531..c27644b2 100644 --- a/libs/picomodel/pm_3ds.c +++ b/libs/picomodel/pm_3ds.c @@ -722,8 +722,8 @@ static picoModel_t *_3ds_load( PM_PARAMS_LOAD ){ return NULL; } /* get model's base name (eg. jeep from c:\models\jeep.3ds) */ - memset( basename,0,sizeof( basename ) ); - strncpy( basename,_pico_nopath( fileName ),sizeof( basename ) ); + memset( basename, 0, sizeof( basename ) ); + strncpy( basename, _pico_nopath( fileName ), sizeof( basename ) - 1 ); _pico_setfext( basename, NULL ); /* initialize persistant vars (formerly static) */ diff --git a/libs/picomodel/pm_ase.c b/libs/picomodel/pm_ase.c index 1244eb35..101a7d2d 100644 --- a/libs/picomodel/pm_ase.c +++ b/libs/picomodel/pm_ase.c @@ -511,7 +511,7 @@ static picoModel_t *_ase_load( PM_PARAMS_LOAD ){ PicoSetModelFileName( model, fileName ); /* initialize some stuff */ - memset( lastNodeName,0,sizeof( lastNodeName ) ); + memset( lastNodeName, 0, sizeof( lastNodeName ) ); /* parse ase model file */ while ( 1 ) @@ -540,7 +540,7 @@ static picoModel_t *_ase_load( PM_PARAMS_LOAD ){ } /* remember node name */ - strncpy( lastNodeName,ptr,sizeof( lastNodeName ) ); + strncpy( lastNodeName, ptr, sizeof( lastNodeName ) - 1 ); } /* model mesh (originally contained within geomobject) */ else if ( !_pico_stricmp( p->token,"*mesh" ) ) { diff --git a/libs/picomodel/pm_fm.c b/libs/picomodel/pm_fm.c index 79fff8b9..a4b8a11b 100644 --- a/libs/picomodel/pm_fm.c +++ b/libs/picomodel/pm_fm.c @@ -198,7 +198,8 @@ static picoModel_t *_fm_load( PM_PARAMS_LOAD ){ fm_vert_normal_t *vert; - char skinname[FM_SKINPATHSIZE]; + char skinname[FM_SKINPATHSIZE + 1]; + skinname[FM_SKINPATHSIZE] = '\0'; fm_t fm; fm_header_t *fm_head; fm_st_t *texCoord; diff --git a/libs/picomodel/pm_lwo.c b/libs/picomodel/pm_lwo.c index 37f2b60b..6431dc2b 100644 --- a/libs/picomodel/pm_lwo.c +++ b/libs/picomodel/pm_lwo.c @@ -100,7 +100,8 @@ static picoModel_t *_lwo_load( PM_PARAMS_LOAD ){ lwPolygon *pol; lwPolVert *v; lwVMapPt *vm; - char name[ 256 ]; + char name[256]; + name[255] = '\0'; int i, j, k, numverts; picoModel_t *picoModel; @@ -231,7 +232,7 @@ static picoModel_t *_lwo_load( PM_PARAMS_LOAD ){ } /* detox and set shader name */ - strncpy( name, surface->name, sizeof( name ) ); + strncpy( name, surface->name, sizeof( name ) - 1 ); _pico_first_token( name ); _pico_setfext( name, NULL ); _pico_unixify( name ); diff --git a/libs/picomodel/pm_md2.c b/libs/picomodel/pm_md2.c index c984e42e..31c8a8ff 100644 --- a/libs/picomodel/pm_md2.c +++ b/libs/picomodel/pm_md2.c @@ -326,7 +326,8 @@ static picoModel_t *_md2_load( PM_PARAMS_LOAD ){ index_DUP_LUT_t *p_index_LUT_DUPS; md2Triangle_t *p_md2Triangle; - char skinname[ MD2_MAX_SKINNAME ]; + char skinname[ MD2_MAX_SKINNAME + 1 ]; + skinname[ MD2_MAX_SKINNAME] = '\0'; md2_t *md2; md2St_t *texCoord; md2Frame_t *frame; diff --git a/plugins/md3model/md2.cpp b/plugins/md3model/md2.cpp index e18ef2f6..bb481bed 100644 --- a/plugins/md3model/md2.cpp +++ b/plugins/md3model/md2.cpp @@ -233,7 +233,8 @@ void MD2Surface_read( Model& model, const byte* buffer, ArchiveFile& file ){ char skinname[MD2_MAX_SKINNAME]; char skinnameRelative[MD2_MAX_SKINNAME]; - char path[MD2_MAX_SKINNAME]; + char path[MD2_MAX_SKINNAME + 1]; + path[MD2_MAX_SKINNAME] = '\0'; int i = MD2_MAX_SKINNAME; PointerInputStream inputStream( buffer + header.ofs_skins ); inputStream.read( reinterpret_cast( skinnameRelative ), MD2_MAX_SKINNAME );