diff options
author | Alan Somers <asomers@FreeBSD.org> | 2017-04-05 17:17:18 +0000 |
---|---|---|
committer | Alan Somers <asomers@FreeBSD.org> | 2017-04-05 17:17:18 +0000 |
commit | fc9437c8860f738111eff4a87bd6c47ef076fa17 (patch) | |
tree | 7fd54a24bdf1eaafa38b4c34c8a615d093f4d25d /sbin/geom/misc | |
parent | 48fe9263620358256fdb34ddb0bb6e151b7e2664 (diff) | |
download | src-fc9437c8860f738111eff4a87bd6c47ef076fa17.tar.gz src-fc9437c8860f738111eff4a87bd6c47ef076fa17.zip |
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
Notes
Notes:
svn path=/head/; revision=316530
Diffstat (limited to 'sbin/geom/misc')
-rw-r--r-- | sbin/geom/misc/subr.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/sbin/geom/misc/subr.c b/sbin/geom/misc/subr.c index f7b2764a6f14..cf0d9b00cf85 100644 --- a/sbin/geom/misc/subr.c +++ b/sbin/geom/misc/subr.c @@ -336,7 +336,7 @@ g_metadata_clear(const char *name, const char *magic) 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 char *magic) } (void)g_flush(fd); out: - if (sector != NULL) - free(sector); + free(sector); g_close(fd); return (error); } |