2
0
mirror of https://github.com/rehlds/rehlds.git synced 2024-12-29 08:05:50 +03:00

Merge pull request #254 from theAsmodai/master

Fixed crash when motd_write called without arguments (#253)
This commit is contained in:
theAsmodai 2016-10-25 14:40:36 +03:00 committed by GitHub
commit e819b1370a

View File

@ -276,7 +276,7 @@ void Host_Motd_f(void)
/* <3d5d4> ../engine/host_cmd.c:335 */ /* <3d5d4> ../engine/host_cmd.c:335 */
void Host_Motd_Write_f(void) void Host_Motd_Write_f(void)
{ {
char newFile[2048]; char newFile[2048] = "";
unsigned int i; unsigned int i;
FileHandle_t pFile; FileHandle_t pFile;
@ -295,18 +295,22 @@ void Host_Motd_Write_f(void)
return; return;
} }
Q_strncpy(newFile, Cmd_Args(), ARRAYSIZE(newFile));
#ifdef REHLDS_FIXES #ifdef REHLDS_FIXES
newFile[ARRAYSIZE(newFile) - 1] = 0; if (Cmd_Args()) {
Q_strncpy(newFile, Cmd_Args(), ARRAYSIZE(newFile) - 1);
newFile[ARRAYSIZE(newFile) - 1] = '\0';
}
#else // REHLDS_FIXES
Q_strncpy(newFile, Cmd_Args(), ARRAYSIZE(newFile));
#endif // REHLDS_FIXES #endif // REHLDS_FIXES
for (i = 0; i < Q_strlen(newFile); i++) auto len = Q_strlen(newFile);
for (i = 0; i < len; i++)
{ {
if (newFile[i] == '\\' && newFile[i + 1] == 'n') if (newFile[i] == '\\' && newFile[i + 1] == 'n')
{ {
newFile[i] = '\n'; newFile[i] = '\n';
Q_strncpy(&newFile[i + 1], &newFile[i + 2], min(sizeof(newFile) - 1, Q_strlen(newFile) + 1)); Q_memmove(&newFile[i + 1], &newFile[i + 2], Q_strlen(&newFile[i + 2]) + 1);
newFile[sizeof(newFile) - 1] = 0;
} }
} }
FS_Write(newFile, Q_strlen(newFile), 1, pFile); FS_Write(newFile, Q_strlen(newFile), 1, pFile);