Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 May 2014 17:34:51 +0000 (UTC)
From:      Marcel Moolenaar <marcel@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r266509 - head/usr.bin/mkimg
Message-ID:  <201405211734.s4LHYpoi020747@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marcel
Date: Wed May 21 17:34:50 2014
New Revision: 266509
URL: http://svnweb.freebsd.org/changeset/base/266509

Log:
  Fix CID 1215129: move the call to lseek(2) before the call to malloc(3)
  so that the error path (taken due to lseek(2) failing) isn't leaking
  memory.

Modified:
  head/usr.bin/mkimg/image.c

Modified: head/usr.bin/mkimg/image.c
==============================================================================
--- head/usr.bin/mkimg/image.c	Wed May 21 17:22:41 2014	(r266508)
+++ head/usr.bin/mkimg/image.c	Wed May 21 17:34:50 2014	(r266509)
@@ -98,11 +98,11 @@ image_copyout(int fd)
 
 	ofs = lseek(fd, 0L, SEEK_CUR);
 
+	if (lseek(image_fd, 0, SEEK_SET) != 0)
+		return (errno);
 	buffer = malloc(BUFFER_SIZE);
 	if (buffer == NULL)
 		return (errno);
-	if (lseek(image_fd, 0, SEEK_SET) != 0)
-		return (errno);
 	error = 0;
 	while (1) {
 		rdsz = read(image_fd, buffer, BUFFER_SIZE);



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