FYI,
>From 0ee727e612ae202e5b47e39062f6604d65a76074 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[email protected]>
Date: Sat, 4 Aug 2012 11:02:40 +0200
Subject: [PATCH] truncate: don't leak a file descriptor with --ref=PIPE
* src/truncate.c (main): For a user who makes the mistake of
using a non-seekable file as a reference for the desired length,
truncate would open that file, attempt to seek to its end, but
upon seek failure would neglect to close the file descriptor.
Reverse conjuncts, so the close is unconditional.
Spotted by coverity.
---
src/truncate.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/truncate.c b/src/truncate.c
index c1e9666..6e1747d 100644
--- a/src/truncate.c
+++ b/src/truncate.c
@@ -370,7 +370,7 @@ main (int argc, char **argv)
if (0 <= ref_fd)
{
off_t file_end = lseek (ref_fd, 0, SEEK_END);
- if (0 <= file_end && close (ref_fd) == 0)
+ if (close (ref_fd) == 0 && 0 <= file_end)
file_size = file_end;
}
}
--
1.7.12.rc1.10.g97c7934