Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Feb 2019 14:31:44 +0000 (UTC)
From:      Andriy Voskoboinyk <avos@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r343909 - head/usr.bin/newkey
Message-ID:  <201902081431.x18EVirN025543@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: avos
Date: Fri Feb  8 14:31:44 2019
New Revision: 343909
URL: https://svnweb.freebsd.org/changeset/base/343909

Log:
  newkey(8): fix 'tmpname' memory leak (always) and input file descriptor leak
  when output file cannot be opened
  
  PR:		201732
  Reported by:	David Binderman <dcb314@hotmail.com>
  MFC after:	1 week

Modified:
  head/usr.bin/newkey/update.c

Modified: head/usr.bin/newkey/update.c
==============================================================================
--- head/usr.bin/newkey/update.c	Fri Feb  8 14:27:25 2019	(r343908)
+++ head/usr.bin/newkey/update.c	Fri Feb  8 14:31:44 2019	(r343909)
@@ -266,11 +266,14 @@ localupdate(char *name, char *filename, u_int op, u_in
 	sprintf(tmpname, "%s.tmp", filename);
 	rf = fopen(filename, "r");
 	if (rf == NULL) {
-		return (ERR_READ);
+		err = ERR_READ;
+		goto cleanup;
 	}
 	wf = fopen(tmpname, "w");
 	if (wf == NULL) {
-		return (ERR_WRITE);
+		fclose(rf);
+		err = ERR_WRITE;
+		goto cleanup;
 	}
 	err = -1;
 	while (fgets(line, sizeof (line), rf)) {
@@ -310,13 +313,18 @@ localupdate(char *name, char *filename, u_int op, u_in
 	fclose(rf);
 	if (err == 0) {
 		if (rename(tmpname, filename) < 0) {
-			return (ERR_DBASE);
+			err = ERR_DBASE;
+			goto cleanup;
 		}
 	} else {
 		if (unlink(tmpname) < 0) {
-			return (ERR_DBASE);
+			err = ERR_DBASE;
+			goto cleanup;
 		}
 	}
+
+cleanup:
+	free(tmpname);
 	return (err);
 }
 



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