svn commit: r344193 - in stable: 10/usr.bin/newkey 11/usr.bin/newkey 12/usr.bin/newkey

Andriy Voskoboinyk avos at FreeBSD.org
Sat Feb 16 00:37:09 UTC 2019


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 at 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);
 }
 


More information about the svn-src-all mailing list