Skip to content

Commit c060e2e

Browse files
committed
install: Don't allow installation over the install files
1 parent 92d0ec2 commit c060e2e

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

mk/dist.mk

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,9 @@ dist-install-dir-$(1): PREPARE_LIB_CMD=$(DEFAULT_PREPARE_LIB_CMD)
199199
dist-install-dir-$(1): PREPARE_MAN_CMD=$(DEFAULT_PREPARE_MAN_CMD)
200200
dist-install-dir-$(1): PREPARE_CLEAN=true
201201
dist-install-dir-$(1): prepare-base-dir-$(1)
202-
# Write the install manifest, making sure the manifest contains itself
203-
$$(Q)touch $$(PREPARE_DEST_DIR)/$$(CFG_LIBDIR_RELATIVE)/rustlib/manifest-$(1).in
204202
$$(Q)(cd $$(PREPARE_DEST_DIR)/ && find -type f | sed 's/^\.\///') \
205-
> $$(PREPARE_DEST_DIR)/$$(CFG_LIBDIR_RELATIVE)/rustlib/manifest-$(1).in
203+
> tmp/dist/manifest-$(1).in
204+
$$(Q)mv tmp/dist/manifest-$(1).in $$(PREPARE_DEST_DIR)/$$(CFG_LIBDIR_RELATIVE)/rustlib/manifest.in
206205
# Add remaining non-installed files
207206
$$(Q)$$(PREPARE_MAN_CMD) $$(S)COPYRIGHT $$(PREPARE_DEST_DIR)
208207
$$(Q)$$(PREPARE_MAN_CMD) $$(S)LICENSE-APACHE $$(PREPARE_DEST_DIR)

src/etc/install.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,17 +227,29 @@ fi
227227
step_msg "validating $CFG_SELF args"
228228
validate_opt
229229

230+
231+
# OK, let's get installing ...
232+
230233
# Sanity check: can we can write to the destination?
231234
umask 022 && mkdir -p "${CFG_LIBDIR}"
232-
need_ok "can't write to destination. consider `sudo`."
235+
need_ok "can't write to destination. consider 'sudo'."
233236
touch "${CFG_LIBDIR}/rust-install-probe" 2> /dev/null
234237
if [ $? -ne 0 ]
235238
then
236-
err "can't write to destination. consider `sudo`."
239+
err "can't write to destination. consider 'sudo'."
237240
fi
238241
rm "${CFG_LIBDIR}/rust-install-probe"
239242
need_ok "failed to remove install probe"
240243

244+
# Sanity check: don't install to the directory containing the installer.
245+
# That would surely cause chaos.
246+
INSTALLER_DIR="$(cd $(dirname $0) && pwd)"
247+
PREFIX_DIR="$(cd ${CFG_PREFIX} && pwd)"
248+
if [ "${INSTALLER_DIR}" = "${PREFIX_DIR}" ]
249+
then
250+
err "can't install to same directory as installer"
251+
fi
252+
241253
# The file name of the manifest we're going to create during install
242254
INSTALLED_MANIFEST="${CFG_LIBDIR}/rustlib/manifest"
243255

0 commit comments

Comments
 (0)