Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

mkdir builtin and $'\0'



$ zsh --version
zsh 5.0.8 (x86_64-pc-linux-gnu)
$ strace -e mkdir zsh -c "zmodload zsh/files; mkdir $'a\0b'"
mkdir("a\203 b", 0755)                  = -1 EEXIST (File exists)
zsh:mkdir:1: cannot make directory `a^@b': file exists
+++ exited with 1 +++

See how that $'\0' became "\203 " except in the error message.

Not a big problem in that nothing good will ever come out of
mkdir $'\0' anyway since one can't pass a NUL character to the
mkdir() system call.

A bit worse:

$ strace -e chdir zsh -c "cd $'a\0b'; print -r -- \$PWD; pwd"
chdir("/export/home/stephane/a")        = -1 ENOENT (No such file or directory)
chdir("a\203 b")                        = 0
chdir("..")                             = 0
chdir("..")                             = 0
chdir("..")                             = 0
chdir("/home/stephane/a\203 b")         = 0
/export/home/stephane/a
/home/stephane/a� b
+++ exited with 0 +++

I suppose the chdir("..")s come after the realisation that $PWD
probably doesn't represent the current directory anymore (since
chdir("$PWD/dir") doesn't work while chdir("dir") does).

"mv" at least doesn't have the problem. A note though:

$ strace -e rename zsh -c "zmodload zsh/files; mv $'a\0b' x"
rename("a", "x/a")                      = -1 ENOENT (No such file or directory)
zsh:mv:1: a^@b: no such file or directory
+++ exited with 1 +++

The error message mentions a^@b not existing while it did
attempt to rename "a" instead.

Maybe those builtins should fail with an error if one attempts
to call them with an argument containing NUL.

-- 
Stephane



Messages sorted by: Reverse Date, Date, Thread, Author