diff options
| author | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2014-11-30 23:34:19 -0800 |
|---|---|---|
| committer | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2014-12-03 15:18:52 -0800 |
| commit | bd8dac8f758fc76ff3c4553e187eba627728cf71 (patch) | |
| tree | 091853a5a8c55006bcf680239a4f317c09e299af /src | |
| parent | 8ca8e6fa4d3a7dc1a40e958cfa4ca62096bfa509 (diff) | |
| download | rust-bd8dac8f758fc76ff3c4553e187eba627728cf71.tar.gz rust-bd8dac8f758fc76ff3c4553e187eba627728cf71.zip | |
rustup: rewrite to protect against truncation
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.
Diffstat (limited to 'src')
| -rwxr-xr-x | src/etc/rustup.sh | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/src/etc/rustup.sh b/src/etc/rustup.sh index 311c1c3f15e..85fe829c25a 100755 --- a/src/etc/rustup.sh +++ b/src/etc/rustup.sh @@ -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 |
