From: Karel Zak Date: Mon, 6 Dec 2021 09:39:00 +0000 (+0100) Subject: hardlink: make reflink detection more robust [coverity scan] X-Git-Tag: v2.38-rc1~106 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2a596d704fc730091a803784c0634d7eeefca87a;p=thirdparty%2Futil-linux.git hardlink: make reflink detection more robust [coverity scan] Signed-off-by: Karel Zak --- diff --git a/misc-utils/hardlink.c b/misc-utils/hardlink.c index b935308616..d4f3ee3a35 100644 --- a/misc-utils/hardlink.c +++ b/misc-utils/hardlink.c @@ -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 */