in reply to Read a list of NUL-delimited names from STDIN to be processed

When I read nul-delimited lines from find or xargs, I usually do that with the -0 switch (which is equivalent to $/ = "\0";), and I don't chomp the data as the extra nul byte doesn't hurt after filenames.

Replies are listed 'Best First'.
Re^2: Read a list of NUL-delimited names from STDIN to be processed
by Ultra (Hermit) on Nov 24, 2005 at 11:46 UTC

    and I don't chomp the data as the extra nul byte doesn't hurt after filenames.

    Well I think it could hurt in case of a Null Byte Poisoning

    Let's say you would have a null terminated file name, and would like to append the name with another string (like an index or whatever)
    Consider the following piece of code:

    #!/usr/bin/perl -w use strict; my $fname = "aaa.txt\0bla"; print "NAME: $fname\n"; if ( $fname =~ /\0/ ) { open( F, ">$fname" ) || die "could not open $fname, reason: $!"; close(F); } else { print "No NULL BYTE in $fname\n"; }
    It doesn't do what you would expect it to do, right?

    Of course, I may be dead wrong ....

    Dodge This!