]> git.saurik.com Git - apt.git/commitdiff
Only allow "apt-get build-dep path" when path starts with ./ or /
authorMichael Vogt <mvo@ubuntu.com>
Tue, 8 Jul 2014 13:11:14 +0000 (15:11 +0200)
committerMichael Vogt <mvo@ubuntu.com>
Tue, 8 Jul 2014 13:11:14 +0000 (15:11 +0200)
This avoid the subtle problem that someone might have a directory
with the same package name as the build-depends he/she is trying
to fetch. Also print a note that the specific file/dir is used.

apt-pkg/contrib/strutl.cc
apt-pkg/contrib/strutl.h
cmdline/apt-get.cc
test/integration/test-apt-get-build-dep
test/libapt/strutil_test.cc

index 0f48860b1864a0ee706c289b9d016ee326f92dda..7948673dc193c899fac467360aa35486137610a2 100644 (file)
@@ -62,6 +62,13 @@ bool Endswith(const std::string &s, const std::string &end)
    return (s.substr(s.size() - end.size(), s.size()) == end);
 }
 
    return (s.substr(s.size() - end.size(), s.size()) == end);
 }
 
+bool Startswith(const std::string &s, const std::string &start)
+{
+   if (start.size() > s.size())
+      return false;
+   return (s.substr(0, start.size()) == start);
+}
+
 }
 }
                                                                        /*}}}*/
 }
 }
                                                                        /*}}}*/
index 5733fd6e2d4c8012dd7887e06d2516b33e91f861..da8bebdb513d520a188b024d852f84fb06493377 100644 (file)
@@ -40,6 +40,7 @@ namespace APT {
    namespace String {
       std::string Strip(const std::string &s);
       bool Endswith(const std::string &s, const std::string &ending);
    namespace String {
       std::string Strip(const std::string &s);
       bool Endswith(const std::string &s, const std::string &ending);
+      bool Startswith(const std::string &s, const std::string &starting);
    }
 }
 
    }
 }
 
index bd866bc8c66ee3e510d456b7593558ded17ae2cb..cdbfa4708af8115d039d8b124c2604b9b3388b8f 100644 (file)
@@ -1065,9 +1065,12 @@ static bool DoBuildDep(CommandLine &CmdL)
       string Src;
       pkgSrcRecords::Parser *Last = 0;
 
       string Src;
       pkgSrcRecords::Parser *Last = 0;
 
-      // a unpacked debian source tree
-      if (DirectoryExists(*I))
+      // an unpacked debian source tree
+      using APT::String::Startswith;
+      if ((Startswith(*I, "./") || Startswith(*I, "/")) &&
+          DirectoryExists(*I))
       {
       {
+         ioprintf(c1out, _("Note, using directory '%s' to get the build dependencies\n"), *I);
          // FIXME: how can we make this more elegant?
          std::string TypeName = "debian/control File Source Index";
          pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
          // FIXME: how can we make this more elegant?
          std::string TypeName = "debian/control File Source Index";
          pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
@@ -1077,6 +1080,8 @@ static bool DoBuildDep(CommandLine &CmdL)
       // if its a local file (e.g. .dsc) use this
       else if (FileExists(*I))
       {
       // if its a local file (e.g. .dsc) use this
       else if (FileExists(*I))
       {
+         ioprintf(c1out, _("Note, using file '%s' to get the build dependencies\n"), *I);
+
          // see if we can get a parser for this pkgIndexFile type
          string TypeName = flExtension(*I) + " File Source Index";
          pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
          // see if we can get a parser for this pkgIndexFile type
          string TypeName = flExtension(*I) + " File Source Index";
          pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
index f71beae9c41560a476d07f0b697818d141b3ab83..87ec6e54dc66eb809b88fa4301ce49fda35931c7 100755 (executable)
@@ -34,6 +34,7 @@ EOF
 
 testequal "Reading package lists...
 Building dependency tree...
 
 testequal "Reading package lists...
 Building dependency tree...
+Note, using file '2vcard_0.5-3.dsc' to get the build dependencies
 The following NEW packages will be installed:
   build-essential debhelper
 0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
 The following NEW packages will be installed:
   build-essential debhelper
 0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
@@ -76,6 +77,7 @@ EOF
 
 testequal "Reading package lists...
 Building dependency tree...
 
 testequal "Reading package lists...
 Building dependency tree...
+Note, using file '2vcard_0.5-3.dsc' to get the build dependencies
 The following NEW packages will be installed:
   build-essential debhelper
 0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
 The following NEW packages will be installed:
   build-essential debhelper
 0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
@@ -117,6 +119,7 @@ EOF
 
 testequal "Reading package lists...
 Building dependency tree...
 
 testequal "Reading package lists...
 Building dependency tree...
+Note, using directory './foo-1.0' to get the build dependencies
 The following NEW packages will be installed:
   build-essential debhelper
 0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
 The following NEW packages will be installed:
   build-essential debhelper
 0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
index e9b778c6b858e3127a4d4df18d1e03171e2c5336..1c2f0abac84053589806d0054e30f8cc35983def 100644 (file)
@@ -70,6 +70,15 @@ TEST(StrUtilTest,EndsWith)
    EXPECT_FALSE(Endswith("abcd", "x"));
    EXPECT_FALSE(Endswith("abcd", "abcndefg"));
 }
    EXPECT_FALSE(Endswith("abcd", "x"));
    EXPECT_FALSE(Endswith("abcd", "abcndefg"));
 }
+TEST(StrUtilTest,StartWith)
+{
+   using APT::String::Startswith;
+   EXPECT_TRUE(Startswith("abcd", "a"));
+   EXPECT_TRUE(Startswith("abcd", "ab"));
+   EXPECT_TRUE(Startswith("abcd", "abcd"));
+   EXPECT_FALSE(Startswith("abcd", "x"));
+   EXPECT_FALSE(Startswith("abcd", "abcndefg"));
+}
 TEST(StrUtilTest,SubstVar)
 {
    EXPECT_EQ("", SubstVar("", "fails", "passes"));
 TEST(StrUtilTest,SubstVar)
 {
    EXPECT_EQ("", SubstVar("", "fails", "passes"));