Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'why using -0 and -print0 matters' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
why using -0 and -print0 matters
Authored by: merlyn on Jan 30, '03 01:17:57PM
By default, xargs takes any whitespace in its input to delimit between entries. This is fine for traditional typical Unix filenames, but has always been a problem for security-minded folks who know that filenames can contain arbitrary whitespace (spaces, tabs, newlines).


In fairly modern versions of xargs (including the version shipped with OSX), the -0 switch can be added, which overrides the delimiter to be strictly and only the ASCII NUL byte (which cannot ever appear within a filename, because all Unix system calls are NUL-terminated strings). Now, this won't work with traditional find ... -print, but most modern find commands have also been updated to include -print0, which puts a NUL byte between entries -- not a newline!


So, when you use them together, you get a nice handoff solution for what was formerly a security nightmare. As the good folks at Apple found out for the iTunes update... whitespace matters!

[ Reply to This | # ]