It's correct, origfd >=0 indicates that origfd points to a file not stdin. 
refer to 
          int origfd = (f.fd == BADFD ? -1
                        : openat (f.fd, f.base, open_searchdir_how.flags));
------------------ ???????? ------------------
??????:                                                                         
                                               "Marius Spix"                    
                                                                
<[email protected]&gt;;
????????:&nbsp;2026??3??10??(??????) ????6:20
??????:&nbsp;"CuiWeixie"<[email protected]&gt;;"bug-tar"<[email protected]&gt;;
????:&nbsp;"cuiweixie"<[email protected]&gt;;
????:&nbsp;Aw: [PATCH] Fix wrong fd in restore_parent_fd fallback path



Is
 &nbsp;
 if (0 <= origfd)
 ...
 close (origfd);
 &nbsp;
 correct in this context?
 &nbsp;
 This can close the standard fd 0 (stdin).
 &nbsp;
 The GNU manual states:
 &nbsp;
 When a new file descriptor is allocated, the operating system chooses the 
smallest non-negative integer that does not yet correspond to an open file 
descriptor. So, when a given fd (0, 1, or 2) is closed, opening a new file 
descriptor may assign the new file descriptor to this fd. This can have 
unintended effects, because now standard input/output/error of your process is 
referring to a file that was not meant to be used in that role.
 &nbsp;
 Best regards,
 &nbsp;
 Marius
 &nbsp;
   Gesendet: Montag, 9. M?0?1rz 2026 um 12:37
 Von: "Weixie Cui" <[email protected]&gt;
 An: [email protected]
 CC: "Weixie Cui" <[email protected]&gt;
 Betreff: [PATCH] Fix wrong fd in restore_parent_fd fallback path
 
 From: Weixie Cui <[email protected]&gt;

Use fstat(origfd) instead of fstat(parentfd) when verifying the
alternatively-opened directory; parentfd is invalid in this branch.
---
src/create.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/create.c b/src/create.c
index a962ed75..71f183a5 100644
--- a/src/create.c
+++ b/src/create.c
@@ -1588,7 +1588,7 @@ restore_parent_fd (struct tar_stat_info const *st)
: openat (f.fd, f.base, open_searchdir_how.flags));
if (0 <= origfd)
{
- if (fstat (parentfd, &amp;parentstat) < 0
+ if (fstat (origfd, &amp;parentstat) < 0
|| !psame_inode (&amp;parent-&gt;stat, &amp;parentstat))
close (origfd);
else
-- 
2.39.5 (Apple Git-154)

Reply via email to