Gitweb:
http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=7e3a8b6d...
Commit: 7e3a8b6da97574d086aaecb94a08596925b82d41
Parent: 7e83ff820e5d9068ac35e04d09d303fc2465afcb
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Fri Oct 3 16:51:26 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Wed Apr 1 16:51:34 2015 +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(a)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)) {