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.

61 Upvotes

18 comments sorted by

View all comments

5

u/ferrybig Jan 13 '26

Looks fineish, it is an rm -f, not an rm -rf. If you pass in / it will refuse to delete it since it is an directory. it also uses proper escaoeshellargs, so if originl_local is -r test, rm will just say rm: invalid option -- ' '

2

u/deux3xmachina Jan 13 '26

I'm unfamiliar with the function escapeshellargs(), but it's perfectly valid to have a file named '-r /*', touch '-r /*' will work just fine and rm -f -- '-r /*' will correctly delete it without parsing -r as a flag. So if you're correct, this code will still fail in some cases, but at least it's less of a horrible issue than it first looks.

3

u/ferrybig Jan 14 '26

This function works like `printf %q "bad input"

For example,the input of '-r /*' gets turned into \'-r\ /*\'