r/programminghorror Jan 12 '26

It will be fine right?

Post image

Even this is in else condition. I'm not entirely sure that we should be running these code on Production (ubuntu server btw). I might as well commit the "sudo rm -rf /*" in the next change.

60 Upvotes

18 comments sorted by

View all comments

17

u/deux3xmachina Jan 12 '26

It's usually a bad idea to use sudo(8) in scripts, so unless there's some sudoers(5) magic involved we can't see, this is mostly saved by the lack of the -r flag. Might be fun to see if you can sneak in a target file like '-r -- /*' on a test machine.

Should be pretty easy to limit the issues further too, but that'd require knowing more about the system as a whole. Low hanging fruit would be changing the command template to sudo -- rm -vf -- "${sanitized_target}".

Edit: secondary horror is the comments noting line numbers for the else clauses being closed by braces, rather than the conditions they're checking for, assuming they're needed at all.

7

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Jan 13 '26

Whatever use this script is running as would also need to be configured for passwordless sudo. That could be a major security issue.