Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 5 Apr 2017 17:17:18 +0000 (UTC)
From:      Alan Somers <asomers@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r316530 - head/sbin/geom/misc
Message-ID:  <201704051717.v35HHIni073068@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: asomers
Date: Wed Apr  5 17:17:18 2017
New Revision: 316530
URL: https://svnweb.freebsd.org/changeset/base/316530

Log:
  Fix clearing geom metadata if DIOCGSECTORSIZE fails
  
  An unhandled error case would result in passing SIZE_MAX to malloc.
  While I'm here, remove an unnecessary NULL check before free
  
  Reported by:	Coverity
  CID:		1017793
  MFC after:	3 weeks
  Sponsored by:	Spectra Logic Corp

Modified:
  head/sbin/geom/misc/subr.c

Modified: head/sbin/geom/misc/subr.c
==============================================================================
--- head/sbin/geom/misc/subr.c	Wed Apr  5 17:11:39 2017	(r316529)
+++ head/sbin/geom/misc/subr.c	Wed Apr  5 17:17:18 2017	(r316530)
@@ -336,7 +336,7 @@ g_metadata_clear(const char *name, const
 		goto out;
 	}
 	sectorsize = g_sectorsize(fd);
-	if (sectorsize == 0) {
+	if (sectorsize <= 0) {
 		error = errno;
 		goto out;
 	}
@@ -365,8 +365,7 @@ g_metadata_clear(const char *name, const
 	}
 	(void)g_flush(fd);
 out:
-	if (sector != NULL)
-		free(sector);
+	free(sector);
 	g_close(fd);
 	return (error);
 }



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