From 47cc2cc72684600e434a8ee2e7f4685d54d9fa39 Mon Sep 17 00:00:00 2001
From: Rudolf Polzer <divverent@xonotic.org>
Date: Sat, 13 Jul 2013 11:30:40 +0200
Subject: [PATCH] kill some more evil

---
 cl_parse.c | 12 ++++++++++++
 console.c  | 12 +++++++++++-
 host.c     |  8 ++++++--
 3 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/cl_parse.c b/cl_parse.c
index 4b8da407..a465f910 100644
--- a/cl_parse.c
+++ b/cl_parse.c
@@ -2992,6 +2992,12 @@ static void CL_IPLog_Add(const char *address, const char *name, qboolean checkex
 	if (addtofile)
 	{
 		// add it to the iplog.txt file
+		{
+			char name[MAX_OSPATH];
+			strlcpy(name, cl_iplog_name.string, sizeof(name));
+			FS_SetExtension(name, ".log", sizeof (name), IS_HARDENED);
+			Cvar_SetQuick(cl_iplog_name, name);
+		}
 		// TODO: this ought to open the one in the userpath version of the base
 		// gamedir, not the current gamedir
 		Log_Printf(cl_iplog_name.string, "%s %s\n", address, name);
@@ -3009,6 +3015,12 @@ static void CL_IPLog_Load(void)
 	char line[MAX_INPUTLINE];
 	char address[MAX_INPUTLINE];
 	cl_iplog_loaded = true;
+	{
+		char name[MAX_OSPATH];
+		strlcpy(name, cl_iplog_name.string, sizeof(name));
+		FS_SetExtension(name, ".log", sizeof (name), IS_HARDENED);
+		Cvar_SetQuick(cl_iplog_name, name);
+	}
 	// TODO: this ought to open the one in the userpath version of the base
 	// gamedir, not the current gamedir
 	filedata = FS_LoadFile(cl_iplog_name.string, tempmempool, true, &filesize);
diff --git a/console.c b/console.c
index e21f2cbf..be14fca1 100644
--- a/console.c
+++ b/console.c
@@ -410,6 +410,13 @@ static void Log_Open (void)
 	if (logfile != NULL || log_file.string[0] == '\0')
 		return;
 
+	{
+		char name[MAX_OSPATH];
+		strlcpy(name, log_file.string, sizeof(name));
+		FS_SetExtension(name, ".log", sizeof (name), IS_HARDENED);
+		Cvar_SetQuick(log_file, name);
+	}
+
 	logfile = FS_OpenRealFile(log_file.string, "a", false);
 	if (logfile != NULL)
 	{
@@ -692,12 +699,15 @@ static void Con_ConDump_f (void)
 {
 	int i;
 	qfile_t *file;
+	char name[MAX_OSPATH];
 	if (Cmd_Argc() != 2)
 	{
 		Con_Printf("usage: condump <filename>\n");
 		return;
 	}
-	file = FS_OpenRealFile(Cmd_Argv(1), "w", false);
+	strlcpy(name, Cmd_Argv(1), sizeof(name));
+	FS_SetExtension(name, ".txt", sizeof (name), IS_HARDENED);
+	file = FS_OpenRealFile(name, "w", false);
 	if (!file)
 	{
 		Con_Printf("condump: unable to write file \"%s\"\n", Cmd_Argv(1));
diff --git a/host.c b/host.c
index 7bc799dd..ce6abbd1 100644
--- a/host.c
+++ b/host.c
@@ -276,16 +276,20 @@ Writes key bindings and archived cvars to config.cfg
 static void Host_SaveConfig_to(const char *file)
 {
 	qfile_t *f;
+	char name[MAX_OSPATH];
+
+	strlcpy(name, file, sizeof(name));
+	FS_SetExtension(name, ".cfg", sizeof (name), IS_HARDENED);
 
 // dedicated servers initialize the host but don't parse and set the
 // config.cfg cvars
 	// LordHavoc: don't save a config if it crashed in startup
 	if (host_framecount >= 3 && cls.state != ca_dedicated && !COM_CheckParm("-benchmark") && !COM_CheckParm("-capturedemo"))
 	{
-		f = FS_OpenRealFile(file, "wb", false);
+		f = FS_OpenRealFile(name, "wb", false);
 		if (!f)
 		{
-			Con_Printf("Couldn't write %s.\n", file);
+			Con_Printf("Couldn't write %s.\n", name);
 			return;
 		}
 
-- 
2.39.5