mirror of https://github.com/ioquake/ioq3.git
Fix Overlapping src and dest for strcpy in Client Code
This commit is contained in:
parent
5d60f6035a
commit
a1207f1637
|
@ -618,7 +618,7 @@ intptr_t CL_CgameSystemCalls( intptr_t *args ) {
|
|||
Com_Memcpy( VMA(1), VMA(2), args[3] );
|
||||
return 0;
|
||||
case CG_STRNCPY:
|
||||
strncpy( VMA(1), VMA(2), args[3] );
|
||||
CL_Strncpy( VMA(1), VMA(2), args[3] );
|
||||
return args[1];
|
||||
case CG_SIN:
|
||||
return FloatAsInt( sin( VMF(1) ) );
|
||||
|
|
|
@ -4708,3 +4708,21 @@ qboolean CL_CDKeyValidate( const char *key, const char *checksum ) {
|
|||
return qfalse;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
CL_Strncpy
|
||||
=================
|
||||
Safe reimplementation of strncpy against overlapping src & dest
|
||||
*/
|
||||
|
||||
char *CL_Strncpy(char *dest, const char *src, unsigned long n){
|
||||
unsigned long length = strlen(src);
|
||||
if(n > length){
|
||||
memmove(dest, src, length);
|
||||
memset(dest+length,0,n-length);
|
||||
}else{
|
||||
memmove(dest, src, n);
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
|
|
@ -1005,7 +1005,7 @@ intptr_t CL_UISystemCalls( intptr_t *args ) {
|
|||
return 0;
|
||||
|
||||
case UI_STRNCPY:
|
||||
strncpy( VMA(1), VMA(2), args[3] );
|
||||
CL_Strncpy( VMA(1), VMA(2), args[3] );
|
||||
return args[1];
|
||||
|
||||
case UI_SIN:
|
||||
|
|
|
@ -485,6 +485,8 @@ void CL_InitRef( void );
|
|||
qboolean CL_CDKeyValidate( const char *key, const char *checksum );
|
||||
int CL_ServerStatus( char *serverAddress, char *serverStatusString, int maxLen );
|
||||
|
||||
char *CL_Strncpy(char *dest, const char *src, unsigned long n);
|
||||
|
||||
qboolean CL_CheckPaused(void);
|
||||
|
||||
//
|
||||
|
|
Loading…
Reference in New Issue