Tomas Hozza 4a918b
From 18df9e628ea10c7d607f43fcfd935e7924731f24 Mon Sep 17 00:00:00 2001
Tomas Hozza 4a918b
From: Evan Hunt <each@isc.org>
Tomas Hozza 4a918b
Date: Mon, 9 Sep 2013 22:12:47 -0700
Tomas Hozza 4a918b
Subject: [PATCH] [master] strdup journal filename
Tomas Hozza 4a918b
Tomas Hozza 4a918b
3646.	[bug]		Journal filename string could be set incorrectly,
Tomas Hozza 4a918b
                        causing garbage in log messages.  [RT #34738]
Tomas Hozza 4a918b
---
Tomas Hozza 4a918b
 lib/dns/journal.c | 12 +++++++++---
Tomas Hozza 4a918b
 1 file changed, 9 insertions(+), 3 deletions(-)
Tomas Hozza 4a918b
Tomas Hozza 4a918b
diff --git a/lib/dns/journal.c b/lib/dns/journal.c
Tomas Hozza 4a918b
index 08aabd5..46a52e1 100644
Tomas Hozza 4a918b
--- a/lib/dns/journal.c
Tomas Hozza 4a918b
+++ b/lib/dns/journal.c
Tomas Hozza 4a918b
@@ -307,7 +307,7 @@ struct dns_journal {
Tomas Hozza 4a918b
 	unsigned int		magic;		/*%< JOUR */
Tomas Hozza 4a918b
 	isc_mem_t		*mctx;		/*%< Memory context */
Tomas Hozza 4a918b
 	journal_state_t		state;
Tomas Hozza 4a918b
-	const char 		*filename;	/*%< Journal file name */
Tomas Hozza 4a918b
+	char 			*filename;	/*%< Journal file name */
Tomas Hozza 4a918b
 	FILE *			fp;		/*%< File handle */
Tomas Hozza 4a918b
 	isc_offset_t		offset;		/*%< Current file offset */
Tomas Hozza 4a918b
 	journal_header_t 	header;		/*%< In-core journal header */
Tomas Hozza 4a918b
@@ -573,10 +573,13 @@ journal_open(isc_mem_t *mctx, const char *filename, isc_boolean_t write,
Tomas Hozza 4a918b
 	isc_mem_attach(mctx, &j->mctx);
Tomas Hozza 4a918b
 	j->state = JOURNAL_STATE_INVALID;
Tomas Hozza 4a918b
 	j->fp = NULL;
Tomas Hozza 4a918b
-	j->filename = filename;
Tomas Hozza 4a918b
+	j->filename = isc_mem_strdup(mctx, filename);
Tomas Hozza 4a918b
 	j->index = NULL;
Tomas Hozza 4a918b
 	j->rawindex = NULL;
Tomas Hozza 4a918b
 
Tomas Hozza 4a918b
+	if (j->filename == NULL)
Tomas Hozza 4a918b
+		FAIL(ISC_R_NOMEMORY);
Tomas Hozza 4a918b
+
Tomas Hozza 4a918b
 	result = isc_stdio_open(j->filename, write ? "rb+" : "rb", &fp);
Tomas Hozza 4a918b
 
Tomas Hozza 4a918b
 	if (result == ISC_R_FILENOTFOUND) {
Tomas Hozza 4a918b
@@ -679,6 +682,8 @@ journal_open(isc_mem_t *mctx, const char *filename, isc_boolean_t write,
Tomas Hozza 4a918b
 			    sizeof(journal_rawpos_t));
Tomas Hozza 4a918b
 		j->index = NULL;
Tomas Hozza 4a918b
 	}
Tomas Hozza 4a918b
+	if (j->filename != NULL)
Tomas Hozza 4a918b
+		isc_mem_free(j->mctx, j->filename);
Tomas Hozza 4a918b
 	if (j->fp != NULL)
Tomas Hozza 4a918b
 		(void)isc_stdio_close(j->fp);
Tomas Hozza 4a918b
 	isc_mem_putanddetach(&j->mctx, j, sizeof(*j));
Tomas Hozza 4a918b
@@ -1242,7 +1247,8 @@ dns_journal_destroy(dns_journal_t **journalp) {
Tomas Hozza 4a918b
 		isc_mem_put(j->mctx, j->it.target.base, j->it.target.length);
Tomas Hozza 4a918b
 	if (j->it.source.base != NULL)
Tomas Hozza 4a918b
 		isc_mem_put(j->mctx, j->it.source.base, j->it.source.length);
Tomas Hozza 4a918b
-
Tomas Hozza 4a918b
+	if (j->filename != NULL)
Tomas Hozza 4a918b
+		isc_mem_free(j->mctx, j->filename);
Tomas Hozza 4a918b
 	if (j->fp != NULL)
Tomas Hozza 4a918b
 		(void)isc_stdio_close(j->fp);
Tomas Hozza 4a918b
 	j->magic = 0;
Tomas Hozza 4a918b
-- 
Tomas Hozza 4a918b
1.8.3.1
Tomas Hozza 4a918b