]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/deb/deblistparser.cc
Fix previous commit: Do not call memset() if realloc() returned NULL.
[apt.git] / apt-pkg / deb / deblistparser.cc
index bdb50f6bff809ba9b7ebf22e8660dc243b244ae0..4948c9be4939b8a6389427e5f815ad112e8e82d5 100644 (file)
@@ -215,15 +215,22 @@ string debListParser::DescriptionLanguage()
  */
 MD5SumValue debListParser::Description_md5()
 {
-   string value = Section.FindS("Description-md5");
-
-   if (value.empty()) 
+   string const value = Section.FindS("Description-md5");
+   if (value.empty() == true)
    {
       MD5Summation md5;
       md5.Add((Description() + "\n").c_str());
       return md5.Result();
-   } else
-      return MD5SumValue(value);
+   }
+   else if (likely(value.size() == 32))
+   {
+      if (likely(value.find_first_not_of("0123456789abcdefABCDEF") == string::npos))
+        return MD5SumValue(value);
+      _error->Error("Malformed Description-md5 line; includes invalid character '%s'", value.c_str());
+      return MD5SumValue();
+   }
+   _error->Error("Malformed Description-md5 line; doesn't have the required length (32 != %d) '%s'", (int)value.size(), value.c_str());
+   return MD5SumValue();
 }
                                                                         /*}}}*/
 // ListParser::UsePackage - Update a package structure                 /*{{{*/
@@ -236,21 +243,26 @@ bool debListParser::UsePackage(pkgCache::PkgIterator &Pkg,
    if (Pkg->Section == 0)
       Pkg->Section = UniqFindTagWrite("Section");
 
-   // Packages which are not from the "native" arch doesn't get the essential flag
-   // in the default "native" mode - it is also possible to mark "all" or "none".
-   // The "installed" mode is handled by ParseStatus(), See #544481 and friends.
    string const static myArch = _config->Find("APT::Architecture");
-   string const static essential = _config->Find("pkgCacheGen::Essential", "native");
-   if ((essential == "native" && Pkg->Arch != 0 && myArch == Pkg.Arch()) ||
-       essential == "all")
+   // Possible values are: "all", "native", "installed" and "none"
+   // The "installed" mode is handled by ParseStatus(), See #544481 and friends.
+   string const static essential = _config->Find("pkgCacheGen::Essential", "all");
+   if (essential == "all" ||
+       (essential == "native" && Pkg->Arch != 0 && myArch == Pkg.Arch()))
       if (Section.FindFlag("Essential",Pkg->Flags,pkgCache::Flag::Essential) == false)
         return false;
    if (Section.FindFlag("Important",Pkg->Flags,pkgCache::Flag::Important) == false)
       return false;
 
    if (strcmp(Pkg.Name(),"apt") == 0)
-      Pkg->Flags |= pkgCache::Flag::Important;
-   
+   {
+      if ((essential == "native" && Pkg->Arch != 0 && myArch == Pkg.Arch()) ||
+         essential == "all")
+        Pkg->Flags |= pkgCache::Flag::Essential | pkgCache::Flag::Important;
+      else
+        Pkg->Flags |= pkgCache::Flag::Important;
+   }
+
    if (ParseStatus(Pkg,Ver) == false)
       return false;
    return true;
@@ -625,16 +637,18 @@ bool debListParser::ParseDepends(pkgCache::VerIterator &Ver,
    if (Section.Find(Tag,Start,Stop) == false)
       return true;
 
-   string Package;
    string const pkgArch = Ver.Arch();
-   string Version;
-   unsigned int Op;
 
    while (1)
    {
+      string Package;
+      string Version;
+      unsigned int Op;
+
       Start = ParseDepends(Start,Stop,Package,Version,Op,false,!MultiArchEnabled);
       if (Start == 0)
         return _error->Error("Problem parsing dependency %s",Tag);
+      size_t const found = Package.rfind(':');
 
       if (MultiArchEnabled == true &&
          (Type == pkgCache::Dep::Conflicts ||
@@ -646,6 +660,18 @@ bool debListParser::ParseDepends(pkgCache::VerIterator &Ver,
            if (NewDepends(Ver,Package,*a,Version,Op,Type) == false)
               return false;
       }
+      else if (MultiArchEnabled == true && found != string::npos &&
+              strcmp(Package.c_str() + found, ":any") != 0)
+      {
+        string Arch = Package.substr(found+1, string::npos);
+        Package = Package.substr(0, found);
+        // Such dependencies are not supposed to be accepted …
+        // … but this is probably the best thing to do.
+        if (Arch == "native")
+           Arch = _config->Find("APT::Architecture");
+        if (NewDepends(Ver,Package,Arch,Version,Op,Type) == false)
+           return false;
+      }
       else if (NewDepends(Ver,Package,pkgArch,Version,Op,Type) == false)
         return false;
       if (Start == Stop)