https://news.ycombinator.com/item?id=29747034
Parsing the output of ls is an antipattern (wooledge.org) 2 points by goranmoomin on Sept 6, 2021 | past
https://news.ycombinator.com/item?id=28435532
Why you shouldn't parse the output of ls(1) (wooledge.org) 2 points by O1111OOO on Dec 24, 2018 | past | 2 comments
https://news.ycombinator.com/item?id=18753980
Parsing ls (wooledge.org) 3 points by tambourine_man on Jan 31, 2016 | past
https://news.ycombinator.com/item?id=11007601
Why you shouldn't parse the output of ls(1) (wooledge.org) 2 points by rosser on Jan 20, 2015 | past
https://news.ycombinator.com/item?id=8914841
Why you shouldn't parse the output of ls (wooledge.org) 31 points by dgellow on July 6, 2014 | past | 18 comments
Has anyone actually found a good use for filenames containing newlines?
I was handling security incidents on a large scale with tools that attackers would purposely circumvent with special filenames/inputs. Instead of fighting against the grain, I decided to build a platform with a heavy focus on correctness. Any deviation from the data specification would stick out as a sore thumb and immediately detect anti-forensics and other tricks.
Today, I have a vast compendium of anti-forensics tricks, such as commands not getting written to history, files that cannot be deleted or copied, and much more.
Suffice to say that if you are parsing the output of any tool, you are vulnerable to a whole slew of adversarial techniques.
ls -D
and the application for which it was specifically earmarked. I am consistently amazed at how hard it is to mess dired up.
All these file name issues all come from one source, Microsoft. POSIX should be updated to forbid file names with any of these characters:
* space
* NULL
* New Line (as others said, I never ran across a file with a \n in it)
In my case, these were files created by some other program that contained a bug, where the filename was accidentally set to something like the file contents, say. These other programs were often written by researchers, rather than engineers, who (reasonably so) cared more about their research, than functional correctness. They were also not incentivised to clean-up the dodgy files, if they fix the bug — a big if! — or may not have even be equipped to do so.
You could argue that this is an edge case, but shit happens. Often.