]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hardlink: make reflink detection more robust [coverity scan]
authorKarel Zak <kzak@redhat.com>
Mon, 6 Dec 2021 09:39:00 +0000 (10:39 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 6 Dec 2021 09:39:00 +0000 (10:39 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/hardlink.c

index b93530861658b9c7c2f2b692cce628755a8f7b3f..d4f3ee3a35eb66cc19fd2a3542ddf34517931203 100644 (file)
@@ -907,6 +907,9 @@ static int is_reflink(struct file *xa, struct file *xb)
        int af = open(xa->links->path, O_RDONLY),
            bf = open(xb->links->path, O_RDONLY);
 
+       if (af < 0 || bf < 0)
+               goto done;
+
        do {
                size_t i;
 
@@ -948,9 +951,10 @@ static int is_reflink(struct file *xa, struct file *xb)
 
        rc = 1;
 done:
-       close(af);
-       close(bf);
-
+       if (af >= 0)
+               close(af);
+       if (bf >= 0)
+               close(bf);
        return rc;
 }
 #endif /* USE_REFLINK */