5 ms·
Interesting choice of code for a demo. I wonder if anyone hosed themselves running this. It seems gnu rm has "-preserve-root" as a default, but that's not gua
by tyingq 9y ago
Interesting choice of code for a demo. I wonder if anyone hosed themselves running this.
It seems gnu rm has "-preserve-root" as a default, but that's not guaranteed to be on every rm.
- csomar 9y agoOne of the advantages of using Docker! You can safely run this code multiple times and play with it without affecting your machine.
- tyingq 9y agoSure, but you could also replace "rm -rf /" with "id" or something else non destructive. Somebody is going to copy paste that snippet and have a bad day.
- dmix 9y agoI believe "rm -rf /" illustrates the point quite well, better than id. I'm more in the common sense is more common than people give credit and in the situations where that is not the case then rm has built-in protections. It literally says: > That is, the compiled program executes “rm -rf /” The next line following the code. It's not tricking anyone.
- tyingq 9y agoGnu rm has built in protections. Not sure that's the case on OSX, Linux distributions that use busybox, etc.
- jwilk 9y agoI usually use "cowsay" for demonstrating that arbitrary code execution is possible. Less destructive, and more entertaining when someone actually tries to run the code. :-)
- rcthompson 9y agoIf someone blindly copies, pastes, compiles, and runs a random snippet of code from the internet that is specifically described as producing weird and unexpected behavior, then they deserve the harsh lesson they're about to learn.
- andrewflnr 9y agoJust because it's a harsh, cruel world doesn't mean you should be cruel.
- nurettin 9y agoIt doesn't mean he should be cruel, it just means he is statistically more likely to be cruel.
- rcthompson 9y agoI normally have some measure of sympathy for people who blindly run code that is unexplained or under-explained (e.g. the many "curl | bash" installers). But blindly running code that is specifically called out as having weird and unexpected behavior is like driving your car right through the bright yellow "bridge out" sign that's blocking the bridge.
- nv-vn 9y agoDo you use Docker to run literally every piece of code though?
- ramshorns 9y agoIf it's run as an unprivileged user rather than root, it won't be able to delete the whole system. I'm pretty sure that means it won't do anything, but I don't feel like trying it.
- tyingq 9y ago>I'm pretty sure that means it won't do anything Assuming an rm without the "-preserve-root" default, it would remove everything that it had permission to. So, eventually, for example, it would wipe your home directory. I suspect this to be the case for OSX, Alpine Linux (or other distros that use busybox), probably some of the BSD distributions, etc.
- jwilk 9y ago$ uname -sr FreeBSD 11.1-RELEASE $ rm -rf / rm: "/" may not be removed No idea about other BSDs. Busybox's rm is indeed happy to nuke /.
- jwilk 9y agoAlso: $ uname -sr OpenBSD 6.1 $ rm -rf / rm: "/" may not be removed
- jwilk 9y agoThe latest POSIX standard actually requires this behavior: If […] an operand resolves to the root directory, rm shall write a diagnostic message to standard error and do nothing more with such operands. Source: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/rm.html http://pubs.opengroup.org/onlinepubs/9699919799/utilities/rm...
- deleted 9y ago[deleted]
- kazinator 9y agobut that's not guaranteed to be on every rm. Not even the GNU Coreutils one, if compiled with this compiler.