gfs2-utils: master - libgfs2: Fail fd comparison if the fds are negative

Andrew Price andyp at fedoraproject.org
Mon Oct 6 18:54:03 UTC 2014


Gitweb:        http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=7dcfbae20b74aa10fc597441a0538f654a13891b
Commit:        7dcfbae20b74aa10fc597441a0538f654a13891b
Parent:        d3743efabda1118a54beb84e43655809f64a103d
Author:        Andrew Price <anprice at redhat.com>
AuthorDate:    Fri Oct 3 16:51:26 2014 +0100
Committer:     Andrew Price <anprice at redhat.com>
CommitterDate: Fri Oct 3 16:56:42 2014 +0100

libgfs2: Fail fd comparison if the fds are negative

Spotted by coverity: "*devfd" is passed to a parameter that cannot be
negative.

This refers to the fstat calls in fdcmp. Guard them with a check for
negative fds.

Signed-off-by: Andrew Price <anprice at redhat.com>
---
 gfs2/libgfs2/misc.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
index 9eca24c..a66ca4f 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -105,6 +105,9 @@ int compute_constants(struct gfs2_sbd *sdp)
 static int fdcmp(int fd1, int fd2)
 {
 	struct stat st1, st2;
+
+	if (fd1 < 0 || fd2 < 0)
+		return -1;
 	if ((fstat(fd1, &st1) != 0) || (fstat(fd2, &st2) != 0))
 		return -1;
 	if (S_ISBLK(st1.st_mode) && S_ISBLK(st2.st_mode)) {


More information about the cluster-commits mailing list