2
0
mirror of https://github.com/rehlds/rehlds.git synced 2025-01-04 02:55:50 +03:00

Implemented strcpy_safe which is safe to use with overlapping src and dst buffers

Use strcpy_safe in Info_ functions
This commit is contained in:
dreamstalker 2015-06-14 23:08:03 +04:00
parent 34686c3819
commit 3cd4a52567
4 changed files with 81 additions and 73 deletions

View File

@ -33,6 +33,12 @@ char serverinfo[MAX_INFO_STRING];
char gpszVersionString[32];
char gpszProductString[32];
char* strcpy_safe(char* dst, char* src) {
int len = strlen(src);
memmove(dst, src, len + 1);
return dst;
}
/* <e875> ../engine/common.c:80 */
char *Info_Serverinfo(void)

View File

@ -170,6 +170,9 @@ NOBODY uint64 Q_strtoull(char *str);
#endif // Q_functions
//strcpy that works correctly with overlapping src and dst buffers
char* strcpy_safe(char* dst, char* src);
int build_number(void);
char *Info_Serverinfo(void);

View File

@ -30,7 +30,6 @@
// NOTE: This file contains a lot of fixes that are not covered by REHLDS_FIXES define.
// TODO: Most of the Info_ functions can be speedup via removing unneded copy of key and values.
// TODO: We have a problem with Q_strcpy, because it maps to strcpy which have undefined behavior when strings overlaps (possibly we need to use memmove solution here)
/*
===============
@ -179,7 +178,7 @@ void Info_RemoveKey(char *s, const char *key)
// Compare keys
if (!Q_strncmp(key, pkey, cmpsize))
{
Q_strcpy(start, s); // remove this part
strcpy_safe(start, s); // remove this part
s = start; // continue searching
}
}
@ -245,7 +244,7 @@ void Info_RemovePrefixedKeys(char *s, const char prefix)
if (pkey[0] == prefix)
{
Q_strcpy(start, s); // remove this part
strcpy_safe(start, s); // remove this part
s = start; // continue searching
}
}