]> git.saurik.com Git - ldid.git/blobdiff - ldid.cpp
Add guarantee that allocations shouldn't overflow.
[ldid.git] / ldid.cpp
index 6b0c95a2713bc3ea832a0a6db7bded00bb4a4c2a..a4dc725b73714ea99a7f0d94e9059001b235c884 100644 (file)
--- a/ldid.cpp
+++ b/ldid.cpp
@@ -1171,6 +1171,8 @@ static void Allocate(const void *idata, size_t isize, std::streambuf &output, co
         size_t saved(save(mach_header, output, allocation.limit_, overlap, top));
         if (allocation.alloc_ > saved)
             pad(output, allocation.alloc_ - saved);
+        else
+            _assert(allocation.alloc_ == saved);
         position += allocation.alloc_;
     }
 }
@@ -1505,7 +1507,7 @@ std::vector<char> Sign(const void *idata, size_t isize, std::streambuf &output,
 
         special = std::max(special, CSSLOT_REQUIREMENTS);
         alloc += sizeof(struct BlobIndex);
-        if (!requirement.empty())
+        if (requirement.empty())
             alloc += 0xc;
         else
             alloc += requirement.size();
@@ -2096,7 +2098,7 @@ Bundle Sign(const std::string &root, Folder &folder, const std::string &key, std
     }), fun([&](const std::string &name, const Functor<std::string ()> &read) {
     }));
 
-    std::map<std::string, std::string> links;
+    std::set<std::string> excludes;
 
     auto exclude([&](const std::string &name) {
         // BundleDiskRep::adjustResources -> builder.addExclusion
@@ -2104,12 +2106,16 @@ Bundle Sign(const std::string &root, Folder &folder, const std::string &key, std
             return true;
 
         for (const auto &bundle : bundles)
-            if (Starts(name, bundle.first + "/"))
+            if (Starts(name, bundle.first + "/")) {
+                excludes.insert(name);
                 return true;
+            }
 
         return false;
     });
 
+    std::map<std::string, std::string> links;
+
     folder.Find("", fun([&](const std::string &name, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &code) {
         if (exclude(name))
             return;
@@ -2170,8 +2176,8 @@ Bundle Sign(const std::string &root, Folder &folder, const std::string &key, std
         for (const auto &hash : local)
             for (const auto &rule : version.second)
                 if (rule(hash.first)) {
-                    if (rule.mode_ == NestedMode);
-                    else if (rule.mode_ == NoMode && old)
+                    if (!old && mac && excludes.find(hash.first) != excludes.end());
+                    else if (old && rule.mode_ == NoMode)
                         plist_dict_set_item(files, hash.first.c_str(), plist_new_data(hash.second.sha1_, sizeof(hash.second.sha1_)));
                     else if (rule.mode_ != OmitMode) {
                         auto entry(plist_new_dict());