Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 14 Jul 2015 18:24:06 +0000 (UTC)
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r285548 - head/sys/kern
Message-ID:  <201507141824.t6EIO6At056210@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: markj
Date: Tue Jul 14 18:24:05 2015
New Revision: 285548
URL: https://svnweb.freebsd.org/changeset/base/285548

Log:
  Fix some error-handling bugs when core dump compression is enabled:
  - Ensure that core dump parameters are initialized in the error path.
  - Don't call gzio_fini() on a NULL stream.
  
  Reported by:	rpaulo

Modified:
  head/sys/kern/imgact_elf.c

Modified: head/sys/kern/imgact_elf.c
==============================================================================
--- head/sys/kern/imgact_elf.c	Tue Jul 14 17:01:55 2015	(r285547)
+++ head/sys/kern/imgact_elf.c	Tue Jul 14 18:24:05 2015	(r285548)
@@ -1241,6 +1241,7 @@ __elfN(coredump)(struct thread *td, stru
 
 	compress = (flags & IMGACT_CORE_COMPRESS) != 0;
 	hdr = NULL;
+	tmpbuf = NULL;
 	TAILQ_INIT(&notelst);
 
 	/* Size the program segments. */
@@ -1255,6 +1256,14 @@ __elfN(coredump)(struct thread *td, stru
 	__elfN(prepare_notes)(td, &notelst, &notesz);
 	coresize = round_page(hdrsize + notesz) + seginfo.size;
 
+	/* Set up core dump parameters. */
+	params.offset = 0;
+	params.active_cred = cred;
+	params.file_cred = NOCRED;
+	params.td = td;
+	params.vp = vp;
+	params.gzs = NULL;
+
 #ifdef RACCT
 	if (racct_enable) {
 		PROC_LOCK(td->td_proc);
@@ -1271,15 +1280,6 @@ __elfN(coredump)(struct thread *td, stru
 		goto done;
 	}
 
-	/* Set up core dump parameters. */
-	params.offset = 0;
-	params.active_cred = cred;
-	params.file_cred = NOCRED;
-	params.td = td;
-	params.vp = vp;
-	params.gzs = NULL;
-
-	tmpbuf = NULL;
 #ifdef GZIO
 	/* Create a compression stream if necessary. */
 	if (compress) {
@@ -1336,7 +1336,8 @@ done:
 #ifdef GZIO
 	if (compress) {
 		free(tmpbuf, M_TEMP);
-		gzio_fini(params.gzs);
+		if (params.gzs != NULL)
+			gzio_fini(params.gzs);
 	}
 #endif
 	while ((ninfo = TAILQ_FIRST(&notelst)) != NULL) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201507141824.t6EIO6At056210>