Skip to content

Commit

Permalink
rustup: rewrite to protect against truncation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
erickt committed Dec 3, 2014
1 parent 8ca8e6f commit bd8dac8
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions src/etc/rustup.sh
Expand Up @@ -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

0 comments on commit bd8dac8

Please sign in to comment.