From e2660960e76c656d842908141e386b2197fbea10 Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Thu, 5 Sep 2013 23:11:39 +0200 Subject: [PATCH] Reject bundle index cache if version is not the current --- Frameworks/plist/src/fs_cache.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Frameworks/plist/src/fs_cache.cc b/Frameworks/plist/src/fs_cache.cc index 73683977..12930f30 100644 --- a/Frameworks/plist/src/fs_cache.cc +++ b/Frameworks/plist/src/fs_cache.cc @@ -29,6 +29,7 @@ static std::string read_link (std::string const& path) namespace plist { int32_t const cache_t::kPropertyCacheFormatVersion = 2; + uint32_t const kCapnpCacheFormatVersion = 1; void cache_t::load (std::string const& path) { @@ -93,7 +94,14 @@ namespace plist if(fd != -1) { capnp::PackedFdMessageReader message(kj::AutoCloseFd{fd}); - for(auto src : message.getRoot().getEntries()) + auto cache = message.getRoot(); + if(cache.getVersion() != kCapnpCacheFormatVersion) + { + fprintf(stderr, "skip ā€˜%s’ version %u (expected %u)\n", path.c_str(), cache.getVersion(), kCapnpCacheFormatVersion); + return; + } + + for(auto src : cache.getEntries()) { entry_t entry(src.getPath().cStr()); switch(src.getType().which()) @@ -195,6 +203,7 @@ namespace plist capnp::MallocMessageBuilder message; auto cache = message.initRoot(); + cache.setVersion(kCapnpCacheFormatVersion); auto entries = cache.initEntries(_cache.size()); size_t i = 0;