Skip to content
Permalink
Browse files

Guard against recursive installs.

git-svn-id: https://svn.macosforge.org/repository/darwinbuild/branches/PR-8488185@896 10a61168-4876-4dac-953b-31e694342555
  • Loading branch information
wsiegrist@apple.com
wsiegrist@apple.com committed Oct 26, 2010
1 parent 300b3f7 commit 57fe641f2c36de35a83acce1db94f3882e02134f
Showing with 40 additions and 1 deletion.
  1. +6 −0 darwinup/Depot.cpp
  2. +17 −1 darwinup/main.cpp
  3. +17 −0 testing/darwinup/run-tests.sh
@@ -426,6 +426,12 @@ int Depot::analyze_stage(const char* path, Archive* archive, Archive* rollback,

IF_DEBUG("[analyze] %s\n", file->path());

if (strcasestr(file->path(), ".DarwinDepot")) {
fprintf(stderr, "Error: Root contains a .DarwinDepot, "
"aborting to avoid damaging darwinup metadata.\n");
return DEPOT_ERROR;
}

// Perform a three-way-diff between the file to be installed (file),
// the file we last installed in this location (preceding),
// and the file that actually exists in this location (actual).
@@ -211,7 +211,23 @@ int main(int argc, char* argv[]) {
for (int i = 1; i < argc && res == 0; i++) {
if (strcmp(argv[0], "install") == 0) {
if (i==1 && depot->initialize(true)) exit(13);
res = depot->install(argv[i]);
// gaurd against installing paths ontop of themselves
if (strncmp(path, argv[i], strlen(argv[i])) == 0
&& (strlen(path) == strlen(argv[i])
|| strlen(path) - 1 == strlen(argv[i]))) {
if (strncmp(path, "/", 1) == 0 && strlen(path) == 1) {
fprintf(stderr, "Error: You provided '/' as a path to a root. "
"If you meant to specify a destination of '/', then you "
"just need to remove the '/' argument as the destination "
"defaults to '/'. Use the -p option to specify another "
"destination.\n");
} else {
fprintf(stderr, "Error: You cannot install the root at '%s' onto"
" itself.\n", path);
}
res = DEPOT_ERROR;
}
if (res == 0) res = depot->install(argv[i]);
} else if (strcmp(argv[0], "upgrade") == 0) {
if (i==1 && depot->initialize(true)) exit(14);
// find most recent matching archive by name
@@ -63,6 +63,7 @@ do
done;

cp corrupt.tgz $PREFIX/
cp depotroot.tar.gz $PREFIX/

mkdir -p $ORIG
cp -R $DEST/* $ORIG/
@@ -438,6 +439,22 @@ echo "DIFF: diffing original test files to dest (should be no diffs) ..."
$DIFF $ORIG $DEST 2>&1
if [ $? -ne 0 ]; then exit 1; fi

echo "========== TEST: testing recursive install guards ==========";
$DARWINUP install $PREFIX/depotroot.tar.gz
if [ $? -ne 255 ]; then exit 1; fi
echo "DIFF: diffing original test files to dest (should be no diffs) ..."
$DIFF $ORIG $DEST 2>&1
if [ $? -ne 0 ]; then exit 1; fi
$DARWINUP install $DEST
if [ $? -ne 255 ]; then exit 1; fi
echo "DIFF: diffing original test files to dest (should be no diffs) ..."
$DIFF $ORIG $DEST 2>&1
if [ $? -ne 0 ]; then exit 1; fi
darwinup $1 install /
if [ $? -ne 255 ]; then exit 1; fi
echo "DIFF: diffing original test files to dest (should be no diffs) ..."
$DIFF $ORIG $DEST 2>&1
if [ $? -ne 0 ]; then exit 1; fi

echo "========== TEST: Try replacing File with Directory =========="
$DARWINUP install $PREFIX/rep_file_dir

0 comments on commit 57fe641

Please sign in to comment.
You can’t perform that action at this time.