Live data from Hacker News

Bug 1202858 – Restarting squid results in deleting all files in hard-drive

bugzilla.redhat.com

41–50 of 179 posts

Re: Bug 1202858 – Restarting squid results in deleting all files in hard-drive

#41
post #4

We had one of these kinda bugs. If you uninstalled our software it deleted a major chunk of your Windows registry, crippling your computer. It was a one character error in our script. The first ticket read "Uninstalling [Product] destroys your computer". I was responsible for customer support. Good times! Was a rough week. We managed to not get sued.

Pretty terrible that such a thing is even allowed by Windows. This is why as a user I like Apple's OS X sandbox.

Re: Bug 1202858 – Restarting squid results in deleting all files in hard-drive

#42

Earlier quoted context omitted.

I believe that "--preserve-root" applies only to / itself. That means `rm -rf /*` will expand to `rm -rf /bin /dev /etc /lib ...` and delete all anyway.

That's accurate. `rm -rf /* ` will still work to delete everything. But that said, `rm -rf "$STREAMROOT/"` can't ever expand to that, and more-over since the expansions in double-quotes it won't be subject to path expansion by bash. So even "/* /", which would normally expand into "/bin/ /dev/ /etc/ ..." won't. You can see what I mean yourself, just use echo: `echo /* `: /bin /dev /etc /lib ... `echo /*/`: /bin/ /dev…

The original example was `rm -rf "$STREAMROOT/"*`, though (the asterisk being out of the double quotes.) Now that glob will expand.

Re: Bug 1202858 – Restarting squid results in deleting all files in hard-drive

#43
post #41
post #4

We had one of these kinda bugs. If you uninstalled our software it deleted a major chunk of your Windows registry, crippling your computer. It was a one character error in our script. The first ticket read "Uninstalling [Product] destroys your computer". I was responsible for customer support. Good times! Was a rough week. We managed to not get sued.

Pretty terrible that such a thing is even allowed by Windows. This is why as a user I like Apple's OS X sandbox.

If a software needs/has root rights, then all bets are off. This is true on any OS.

Re: Bug 1202858 – Restarting squid results in deleting all files in hard-drive

#44

Scary. Even more scary is the fact that the bug has been open for a week, one person has confirmed 100% reproducibility, and no one seems to care at Red Hat. Isn't deleting peoples hard drives a big no no ?

Ahh Redhat, the distro which chose to symlink a bunch of binary lib files from Apache into the etc directory. "Why is grepping /etc taking so long? Binary files in /etc?!? WTF?!?" Coming from Debian, Redhat seems to make a lot of irk-worthy choices.

[deleted]

Re: Bug 1202858 – Restarting squid results in deleting all files in hard-drive

#45

Hmm, there are two possible candidates in the init.d script for the RHEL 6 package of an older version of squid (doesn't look like bug submitter is using a current version). In stop(): rm -rf $SQUID_PIDFILE_DIR/* and in restart(): rm -rf $SQUID_PIDFILE_DIR/* SQUID_PIDFILE_DIR is hardcoded to "/var/run/squid" at the top of my copy of the init script. But, neither of those rm commands check first to make sure that SQUI…

squid-3.1.10-29.el6.src.rpm (from ftp.redhat.com, buried where they keep SRPMs) has squid.init within, and that file has no mention of SQUID_PIDFILE_DIR. A few other spot-checked versions are the same way. https://github.com/mozilla-services/squid-rpm/blob/master/SO... ... however ... whatever that is, does. Did they take this upstream init script somehow?

This looks like it:

https://bugzilla.redhat.com/show_bug.cgi?id=1102343

I guess they applied that change which was obviously written against a very different init script where the variable is actually defined, got QA to test it and immediately backed it out.

Re: Bug 1202858 – Restarting squid results in deleting all files in hard-drive

#46
post #32

Earlier quoted context omitted.

And this is why it is important to write something like set -eu on top of your bash scripts -- execution will stop on errors (non-zero retvals) and on undefined variables.

or check the variable before using it, like any other programming language: [[ "$VAR" ]] && rm -rf "$VAR/*" I think most of these issues stem from the fact that most developers that write shell scripts don't actually understand what they're doing, treating the script as a necessary annoyance rather than a component of the software.

If anyone understands shell scripts, it would be people writing init scripts at Red Hat :)

Anyways, that is not anything like other programming languages. Checking in that way is error prone and not really an improvement (nor equivalent to set -o).

  [[ "$DAEMON_PATH" ]] && rm -rf "$DEAMON_PATH/*"
See what I did there? It's an rm -rf /* bug because "checking variables" is not the answer.

In other programming languages, if an identifier is mis-typed things will blow up. E.g., in ruby if I write:

  daemon_path=1; if daemon_path; puts deamon_path; end
I get "NameError: undefined local variable or method `deamon_path`"

These issues do not always stem from bad developers. Bash's defaults are not safe in many ways and saying "people should just check the variable" isn't helpful here.

Re: Bug 1202858 – Restarting squid results in deleting all files in hard-drive

#47
My good old trick to mitigate that is:

    touch /-@
I also always do it in my home directory:

    touch ~/-@
That's the first thing I do on a new host.

When accidentally running rm -f *, the command expands to -@ first, which is not a valid option and makes the command fail before doing any harm

    rm: illegal option -- @
    usage: rm [-f | -i] [-dPRrvW] file ...

Re: Bug 1202858 – Restarting squid results in deleting all files in hard-drive

#48

Hmm, there are two possible candidates in the init.d script for the RHEL 6 package of an older version of squid (doesn't look like bug submitter is using a current version). In stop(): rm -rf $SQUID_PIDFILE_DIR/* and in restart(): rm -rf $SQUID_PIDFILE_DIR/* SQUID_PIDFILE_DIR is hardcoded to "/var/run/squid" at the top of my copy of the init script. But, neither of those rm commands check first to make sure that SQUI…

squid-3.1.10-29.el6.src.rpm (from ftp.redhat.com, buried where they keep SRPMs) has squid.init within, and that file has no mention of SQUID_PIDFILE_DIR. A few other spot-checked versions are the same way. https://github.com/mozilla-services/squid-rpm/blob/master/SO... ... however ... whatever that is, does. Did they take this upstream init script somehow?

That would be my guess too, although the package maintainer confirmed it on (presumably) a fresh install. I can't find a candidate rm command anywhere in the SRPM, so maybe an upstream file got merged into distrib somehow? I don't have access to an RHEL system to try it out, and can't find the distrib RPM yet to check.

Re: Bug 1202858 – Restarting squid results in deleting all files in hard-drive

#49
post #32

Earlier quoted context omitted.

And this is why it is important to write something like set -eu on top of your bash scripts -- execution will stop on errors (non-zero retvals) and on undefined variables.

or check the variable before using it, like any other programming language: [[ "$VAR" ]] && rm -rf "$VAR/*" I think most of these issues stem from the fact that most developers that write shell scripts don't actually understand what they're doing, treating the script as a necessary annoyance rather than a component of the software.

> like any other programming language

some real-world programming languages don't have undefined variables :)

Re: Bug 1202858 – Restarting squid results in deleting all files in hard-drive

#50
post #42

Earlier quoted context omitted.

That's accurate. `rm -rf /* ` will still work to delete everything. But that said, `rm -rf "$STREAMROOT/"` can't ever expand to that, and more-over since the expansions in double-quotes it won't be subject to path expansion by bash. So even "/* /", which would normally expand into "/bin/ /dev/ /etc/ ..." won't. You can see what I mean yourself, just use echo: `echo /* `: /bin /dev /etc /lib ... `echo /*/`: /bin/ /dev…

The original example was `rm -rf "$STREAMROOT/"*`, though (the asterisk being out of the double quotes.) Now that glob will expand.

Ah, my apologies, I think that was HackerNew's markup at work. The '* ' wasn't there when I looked before.
Post reply on HN