]> git.lizzy.rs Git - rust.git/commitdiff
rustup: rewrite to protect against truncation
authorErick Tryzelaar <erick.tryzelaar@gmail.com>
Mon, 1 Dec 2014 07:34:19 +0000 (23:34 -0800)
committerErick Tryzelaar <erick.tryzelaar@gmail.com>
Wed, 3 Dec 2014 23:18:52 +0000 (15:18 -0800)
This closes #19168. It's possible that if the downloading of `rustup.sh`
is interrupted, bad things could happen, such as running a naked
"rm -rf /" instead of "rm -rf /path/to/tmpdir". This wraps rustup.sh's
functionality in a function that gets called at the last time that should
protect us from these truncation errors.

src/etc/rustup.sh

index 311c1c3f15ef7fdcd67bc9fde597621e2036e367..85fe829c25a6d3d457c884b894fa747dd818b051 100755 (executable)
@@ -455,27 +455,37 @@ install_package() {
     fi
 }
 
-rm -Rf "${CFG_TMP_DIR}"
-need_ok "failed to remove temporary installation directory"
+# It's possible that curl could be interrupted partway though downloading
+# `rustup.sh`, truncating the file. This could be especially bad if we were in
+# the middle of a line that would run "rm -rf ". To protect against this, we
+# wrap up the `rustup.sh` destructive functionality in this helper function,
+# which we call as the last thing we do. This means we will not do anything
+# unless we have the entire file downloaded.
+install_packages() {
+    rm -Rf "${CFG_TMP_DIR}"
+    need_ok "failed to remove temporary installation directory"
 
-mkdir -p "${CFG_TMP_DIR}"
-need_ok "failed to create create temporary installation directory"
-
-download_and_extract_package \
-    "${RUST_URL}" \
-    "${RUST_TARBALL_NAME}"
+    mkdir -p "${CFG_TMP_DIR}"
+    need_ok "failed to create create temporary installation directory"
 
-if [ -z "${CFG_DISABLE_CARGO}" ]; then
     download_and_extract_package \
-        "${CARGO_URL}" \
-        "${CARGO_TARBALL_NAME}"
-fi
+        "${RUST_URL}" \
+        "${RUST_TARBALL_NAME}"
 
-install_package "${RUST_LOCAL_INSTALL_SCRIPT}"
+    if [ -z "${CFG_DISABLE_CARGO}" ]; then
+        download_and_extract_package \
+            "${CARGO_URL}" \
+            "${CARGO_TARBALL_NAME}"
+    fi
 
-if [ -z "${CFG_DISABLE_CARGO}" ]; then
-    install_package "${CARGO_LOCAL_INSTALL_SCRIPT}"
-fi
+    install_package "${RUST_LOCAL_INSTALL_SCRIPT}"
+
+    if [ -z "${CFG_DISABLE_CARGO}" ]; then
+        install_package "${CARGO_LOCAL_INSTALL_SCRIPT}"
+    fi
+
+    rm -Rf "${CFG_TMP_DIR}"
+    need_ok "couldn't rm temporary installation directory"
+}
 
-rm -Rf "${CFG_TMP_DIR}"
-need_ok "couldn't rm temporary installation directory"
+install_packages