mirror of
https://github.com/rehlds/rehlds.git
synced 2025-01-06 03:55:32 +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:
parent
34686c3819
commit
3cd4a52567
@ -33,6 +33,12 @@ char serverinfo[MAX_INFO_STRING];
|
|||||||
char gpszVersionString[32];
|
char gpszVersionString[32];
|
||||||
char gpszProductString[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 */
|
/* <e875> ../engine/common.c:80 */
|
||||||
char *Info_Serverinfo(void)
|
char *Info_Serverinfo(void)
|
||||||
|
@ -170,6 +170,9 @@ NOBODY uint64 Q_strtoull(char *str);
|
|||||||
|
|
||||||
#endif // Q_functions
|
#endif // Q_functions
|
||||||
|
|
||||||
|
//strcpy that works correctly with overlapping src and dst buffers
|
||||||
|
char* strcpy_safe(char* dst, char* src);
|
||||||
|
|
||||||
int build_number(void);
|
int build_number(void);
|
||||||
char *Info_Serverinfo(void);
|
char *Info_Serverinfo(void);
|
||||||
|
|
||||||
|
@ -30,7 +30,6 @@
|
|||||||
|
|
||||||
// NOTE: This file contains a lot of fixes that are not covered by REHLDS_FIXES define.
|
// 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: 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
|
// Compare keys
|
||||||
if (!Q_strncmp(key, pkey, cmpsize))
|
if (!Q_strncmp(key, pkey, cmpsize))
|
||||||
{
|
{
|
||||||
Q_strcpy(start, s); // remove this part
|
strcpy_safe(start, s); // remove this part
|
||||||
s = start; // continue searching
|
s = start; // continue searching
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -245,7 +244,7 @@ void Info_RemovePrefixedKeys(char *s, const char prefix)
|
|||||||
|
|
||||||
if (pkey[0] == prefix)
|
if (pkey[0] == prefix)
|
||||||
{
|
{
|
||||||
Q_strcpy(start, s); // remove this part
|
strcpy_safe(start, s); // remove this part
|
||||||
s = start; // continue searching
|
s = start; // continue searching
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user