Skip to content

Commit

Permalink
Fix clearing geom metadata if DIOCGSECTORSIZE fails
Browse files Browse the repository at this point in the history
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
  • Loading branch information
asomers committed Apr 5, 2017
1 parent 48fe926 commit fc9437c
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions sbin/geom/misc/subr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit fc9437c

Please sign in to comment.