mirror of
https://github.com/rehlds/rehlds.git
synced 2025-01-19 10:08:04 +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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -248,76 +248,76 @@ NOXREF int IsToken(const char *pText, const char *pTokenName)
|
|||||||
/* <c55e5> ../engine/tmessage.c:245 */
|
/* <c55e5> ../engine/tmessage.c:245 */
|
||||||
NOXREF int ParseDirective(const char *pText)
|
NOXREF int ParseDirective(const char *pText)
|
||||||
{
|
{
|
||||||
if (pText && pText[0] == '$')
|
if (pText && pText[0] == '$')
|
||||||
{
|
{
|
||||||
float tempFloat[8];
|
float tempFloat[8];
|
||||||
if (IsToken(pText, "position"))
|
if (IsToken(pText, "position"))
|
||||||
{
|
{
|
||||||
if (ParseFloats(pText, tempFloat, 2))
|
if (ParseFloats(pText, tempFloat, 2))
|
||||||
{
|
{
|
||||||
gMessageParms.x = tempFloat[0];
|
gMessageParms.x = tempFloat[0];
|
||||||
gMessageParms.y = tempFloat[1];
|
gMessageParms.y = tempFloat[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (IsToken(pText, "effect"))
|
else if (IsToken(pText, "effect"))
|
||||||
{
|
{
|
||||||
if (ParseFloats(pText, tempFloat, 1))
|
if (ParseFloats(pText, tempFloat, 1))
|
||||||
{
|
{
|
||||||
gMessageParms.effect = (int)tempFloat[0];
|
gMessageParms.effect = (int)tempFloat[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (IsToken(pText, "fxtime"))
|
else if (IsToken(pText, "fxtime"))
|
||||||
{
|
{
|
||||||
if (ParseFloats(pText, tempFloat, 1))
|
if (ParseFloats(pText, tempFloat, 1))
|
||||||
{
|
{
|
||||||
gMessageParms.fxtime = tempFloat[0];
|
gMessageParms.fxtime = tempFloat[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (IsToken(pText, "color2"))
|
else if (IsToken(pText, "color2"))
|
||||||
{
|
{
|
||||||
if (ParseFloats(pText, tempFloat, 3))
|
if (ParseFloats(pText, tempFloat, 3))
|
||||||
{
|
{
|
||||||
gMessageParms.r2 = (int)tempFloat[0];
|
gMessageParms.r2 = (int)tempFloat[0];
|
||||||
gMessageParms.g2 = (int)tempFloat[1];
|
gMessageParms.g2 = (int)tempFloat[1];
|
||||||
gMessageParms.b2 = (int)tempFloat[2];
|
gMessageParms.b2 = (int)tempFloat[2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (IsToken(pText, "color"))
|
else if (IsToken(pText, "color"))
|
||||||
{
|
{
|
||||||
if (ParseFloats(pText, tempFloat, 3))
|
if (ParseFloats(pText, tempFloat, 3))
|
||||||
{
|
{
|
||||||
gMessageParms.r1 = (int)tempFloat[0];
|
gMessageParms.r1 = (int)tempFloat[0];
|
||||||
gMessageParms.g1 = (int)tempFloat[1];
|
gMessageParms.g1 = (int)tempFloat[1];
|
||||||
gMessageParms.b1 = (int)tempFloat[2];
|
gMessageParms.b1 = (int)tempFloat[2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (IsToken(pText, "fadein"))
|
else if (IsToken(pText, "fadein"))
|
||||||
{
|
{
|
||||||
if (ParseFloats(pText, tempFloat, 1))
|
if (ParseFloats(pText, tempFloat, 1))
|
||||||
{
|
{
|
||||||
gMessageParms.fadein = tempFloat[0];
|
gMessageParms.fadein = tempFloat[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (IsToken(pText, "fadeout"))
|
else if (IsToken(pText, "fadeout"))
|
||||||
{
|
{
|
||||||
if (ParseFloats(pText, tempFloat, 3))
|
if (ParseFloats(pText, tempFloat, 3))
|
||||||
{
|
{
|
||||||
gMessageParms.fadeout = tempFloat[0];
|
gMessageParms.fadeout = tempFloat[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (IsToken(pText, "holdtime"))
|
else if (IsToken(pText, "holdtime"))
|
||||||
{
|
{
|
||||||
if (ParseFloats(pText, tempFloat, 3))
|
if (ParseFloats(pText, tempFloat, 3))
|
||||||
{
|
{
|
||||||
gMessageParms.holdtime = tempFloat[0];
|
gMessageParms.holdtime = tempFloat[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Con_DPrintf("Unknown token: %s\n", pText);
|
Con_DPrintf("Unknown token: %s\n", pText);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user