zsh-users
 help / color / mirror / code / Atom feed
* null bytes in file names?
@ 2003-04-07  8:32 Dominik Vogt
  2003-04-07  8:48 ` Erik Trulsson
  0 siblings, 1 reply; 3+ messages in thread
From: Dominik Vogt @ 2003-04-07  8:32 UTC (permalink / raw)
  To: Zsh Users

As far as I know, UNIX file systems allow null bytes in file
names.  Out of curiosity I tried generating such a file.  I edited
a file fn in a hex editor and put a single null byte into it.

Take I (with "touch"):

  $ touch $(< fn)
  touch: creating `': No such file or directory
  touch: creating `': No such file or directory
  $ touch $(< fn)
  touch: creating `': No such file or directory
  $ touch s$(< fn)t
  $ touch u"$(< fn)"v
  $ ls
  fn s t u

"u" might actually be named "u^@v" but displayed incorrectly by ls,
so let's try to access a file named "u".

  $ ls u
  u

Nope, the name got cut off.

  $ rm s t y

Take II (shell builtins only):

  $ echo foo > $(< fn)
  zsh: no such file or directory: 
  $ echo foo > "$(< fn)"
  zsh: no such file or directory: ^@
  $ echo foo > w$(< fn)x
  $ echo foo > y$(< fn)z
  $ ls
  fn w  x  y  z
  $ ls w y
  w  y

So, no luck.  I wonder where the problem comes from:

 - zsh? (4.0.4)
 - libc?
 - kernel? (linux-2.4.20)

Bye

Dominik ^_^  ^_^


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: null bytes in file names?
  2003-04-07  8:32 null bytes in file names? Dominik Vogt
@ 2003-04-07  8:48 ` Erik Trulsson
  2003-04-07  9:40   ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Erik Trulsson @ 2003-04-07  8:48 UTC (permalink / raw)
  To: Zsh Users

On Mon, Apr 07, 2003 at 10:32:21AM +0200, Dominik Vogt wrote:
> As far as I know, UNIX file systems allow null bytes in file
> names.  Out of curiosity I tried generating such a file.  I edited
> a file fn in a hex editor and put a single null byte into it.

Your knowledge is somewhat faulty.
There are exactly two characters that Unix does not allow in filenames.
Those are NUL (ASCII code 0) and / (ASCII code 47).
The former is used to indicate the end of a filename, while the latter
is used to separate directory paths.

So, you cant't have null bytes in a filename under Unix.

> 
> Take I (with "touch"):
> 
>   $ touch $(< fn)
>   touch: creating `': No such file or directory
>   touch: creating `': No such file or directory
>   $ touch $(< fn)
>   touch: creating `': No such file or directory
>   $ touch s$(< fn)t
>   $ touch u"$(< fn)"v
>   $ ls
>   fn s t u
> 
> "u" might actually be named "u^@v" but displayed incorrectly by ls,
> so let's try to access a file named "u".
> 
>   $ ls u
>   u
> 
> Nope, the name got cut off.
> 
>   $ rm s t y
> 
> Take II (shell builtins only):
> 
>   $ echo foo > $(< fn)
>   zsh: no such file or directory: 
>   $ echo foo > "$(< fn)"
>   zsh: no such file or directory: ^@
>   $ echo foo > w$(< fn)x
>   $ echo foo > y$(< fn)z
>   $ ls
>   fn w  x  y  z
>   $ ls w y
>   w  y
> 
> So, no luck.  I wonder where the problem comes from:
> 
>  - zsh? (4.0.4)
>  - libc?
>  - kernel? (linux-2.4.20)
> 
> Bye
> 
> Dominik ^_^  ^_^

-- 
<Insert your favourite quote here.>
Erik Trulsson
ertr1013@student.uu.se


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: null bytes in file names?
  2003-04-07  8:48 ` Erik Trulsson
@ 2003-04-07  9:40   ` Peter Stephenson
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2003-04-07  9:40 UTC (permalink / raw)
  To: Zsh Users

Erik Trulsson wrote:
> On Mon, Apr 07, 2003 at 10:32:21AM +0200, Dominik Vogt wrote:
> > As far as I know, UNIX file systems allow null bytes in file
> > names.  Out of curiosity I tried generating such a file.  I edited
> > a file fn in a hex editor and put a single null byte into it.
> 
> Your knowledge is somewhat faulty.
> There are exactly two characters that Unix does not allow in filenames.
> Those are NUL (ASCII code 0) and / (ASCII code 47).
> The former is used to indicate the end of a filename, while the latter
> is used to separate directory paths.

Just to be particular...

> > Take I (with "touch"):
> > 
> >   $ touch $(< fn)
> >   touch: creating `': No such file or directory
> >   touch: creating `': No such file or directory

...zsh actually handles the NUL internally, but there's no way to pass
it down as an argument to `touch'.  That gets passed a string `NUL
NUL'.  However, since as you no doubt know all the command receives is a
count of arguments and a series of null-terminated strings, touch simply
sees the first NUL.  The same would happen with an `open()' call from
within zsh.  That's where the rule Erik mentioned comes from.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-04-07  9:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-07  8:32 null bytes in file names? Dominik Vogt
2003-04-07  8:48 ` Erik Trulsson
2003-04-07  9:40   ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).