Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 16 Feb 2019 00:37:09 +0000 (UTC)
From:      Andriy Voskoboinyk <avos@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r344193 - in stable: 10/usr.bin/newkey 11/usr.bin/newkey 12/usr.bin/newkey
Message-ID:  <201902160037.x1G0b9h9071420@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: avos
Date: Sat Feb 16 00:37:08 2019
New Revision: 344193
URL: https://svnweb.freebsd.org/changeset/base/344193

Log:
  MFC r343909:
  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>

Modified:
  stable/11/usr.bin/newkey/update.c
Directory Properties:
  stable/11/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/10/usr.bin/newkey/update.c
  stable/12/usr.bin/newkey/update.c
Directory Properties:
  stable/10/   (props changed)
  stable/12/   (props changed)

Modified: stable/11/usr.bin/newkey/update.c
==============================================================================
--- stable/11/usr.bin/newkey/update.c	Sat Feb 16 00:15:54 2019	(r344192)
+++ stable/11/usr.bin/newkey/update.c	Sat Feb 16 00:37:08 2019	(r344193)
@@ -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?201902160037.x1G0b9h9071420>