The issue is best illustrated with a demo first: ---- # mkdir demo # cd demo # echo '/usr/local/' | pax -rw . (hangs forever, interrupt with Ctrl-C) # echo '/usr/local/' | pax -rw . (this time it completes successfully) ---- In other words, when `pax(1)` is operating under copy mode (the forth synopsis form): ---- pax -r -w [file ...] directory ---- If *all* the following conditions are met, it will hang forever: 1. the `file` operand is not specified; and 2. its has its standard input piped; and 3. the (piped) standard input contains a line that is directory (as the conceptual equivalence of `file` operand); and 4. the `file`(which is a directory) contains at least two components ('*/*/'); and 5. the destination directory does not contain all the parent components of `file`; and 6. the directory is specified with a slash (`/`) at the end.
Hello, I am facing the same bug too : $ mkdir -p /tmp/src/foo/bar $ rm -rf /tmp/dst ; mkdir -p /tmp/dst $ cd /tmp/src $ echo 'foo/bar/' | /bin/pax -r -w -d -pe "/tmp/dst" <looping infinitely> Here, pax(1) infinitely deletes and re-creates /tmp/dst/foo/bar/. The problem is that chk_path() (bin/pax/file_subs.c), called from node_creat() also creates the leaf directory when a trailing '/' appears in the directory name to create. When the execution goes back from chk_path() to node_creat(), the function still cannot create the leaf directory (it has been created by chk_path()), so it unlinks it and calls node_creat() again. The function re-creates it, and so on... A possible fix is to make node_creat() detect trailing slashes so it does NOT create a leaf directory but only intermediate ones. I've added a simple check in that way in the attached patch. Best regards, Ganael.
Created attachment 251272 [details] Proposed patch
Why + if ((spt == NULL) || (*(spt + 1) == '\0')) and not + if ((spt == NULL) || *spt == '/')) ???
(In reply to Warner Losh from comment #3) Oh, wait, that won't work so well. Never mind.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=681fd2bed8eaba88693867ba928a1c03a5b152cc commit 681fd2bed8eaba88693867ba928a1c03a5b152cc Author: Ganael Laplanche <ganael.laplanche@martymac.org> AuthorDate: 2024-06-21 16:39:09 +0000 Commit: Warner Losh <imp@FreeBSD.org> CommitDate: 2024-06-21 16:39:09 +0000 pax: Terminate loop for empty directory names Pax can sometimes loop forever. For example: $ mkdir -p /tmp/src/foo/bar $ rm -rf /tmp/dst ; mkdir -p /tmp/dst $ cd /tmp/src $ echo 'foo/bar/' | /bin/pax -r -w -d -pe "/tmp/dst" <looping infinitely> Here, pax(1) infinitely deletes and re-creates /tmp/dst/foo/bar/. The problem is that chk_path() (bin/pax/file_subs.c), called from node_creat() also creates the leaf directory when a trailing '/' appears in the directory name to create. When the execution goes back from chk_path() to node_creat(), the function still cannot create the leaf directory (it has been created by chk_path()), so it unlinks it and calls node_creat() again. The function re-creates it, and so on... In node_creat() detect trailing slashes and not create a leaf directory, but only intermediate ones. PR: 277060 Reviewed by: imp bin/pax/file_subs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
Hi Warner, Thanks a lot for having taken care of this! Cheers, Ganael.
^Triage: assign to committer.
Hello c433li, Thanks for your report. The issue has been patched. Don't hesitate to re-open that PR if you think something is missing. Best regards, Ganael.
Hi Warner, Would it be possible to MFC commit 681fd2bed8eaba88693867ba928a1c03a5b152cc to 13-STABLE and 14-STABLE please ? Thanks in advance, Ganael.