Преглед изворни кода

add a check for symlinks in .git to outside the source package

This is run both at pack time and at unpack. At pack time, it would probably
be accidentially building a package with a symlinkey .git that wouldn't
unpack properly. At unpack time, such symlinks are generally not to be
trusted

(Although dpkg-source allows symlinks in packages' source, which are
potentially also untrustworthy.. would make an interesting exploit.)
Joey Hess пре 19 година
родитељ
комит
2131acc69d
1 измењених фајлова са 15 додато и 0 уклоњено
  1. 15 0
      scripts/Dpkg/Source/VCS/git.pm

+ 15 - 0
scripts/Dpkg/Source/VCS/git.pm

@@ -22,6 +22,7 @@ package Dpkg::Source::VCS::git;
 use strict;
 use warnings;
 use Cwd;
+use File::Find;
 use Dpkg;
 use Dpkg::Gettext;
 
@@ -46,6 +47,20 @@ sub sanity_check {
 		main::error(sprintf(_g("git repository %s uses submodules. This is not yet supported."), $srcdir));
 	}
 
+	# Symlinks from .git to outside could cause unpack failures, or
+	# point to files they shouldn't, so check for and don't allow.
+	if (-l "$srcdir/.git") {
+		main::error(sprintf(_g("%s is a symlink"), "$srcdir/.git"));
+	}
+	my $abs_srcdir=Cwd::abs_path($srcdir);
+	find(sub {
+		if (-l $_) {
+			if (Cwd::abs_path(readlink($_)) !~ /^\Q$abs_srcdir\E(\/|$)/) {
+				main::error(sprintf(_g("%s is a symlink to outside %s"), $File::Find::name, $srcdir));
+			}
+		}
+	}, "$srcdir/.git");
+
 }
 
 # Called before a tarball is created, to prepare the tar directory.