You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by sc...@apache.org on 2019/02/27 02:24:38 UTC

[trafficserver] branch master updated: Assertion when cache_config_target_fragment_size is large than MAX_FRAG_SIZE

This is an automated email from the ASF dual-hosted git repository.

scw00 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 763cd6d  Assertion when cache_config_target_fragment_size is large than MAX_FRAG_SIZE
763cd6d is described below

commit 763cd6d0140f53eb149e944c0a9e7198fcc80624
Author: scw00 <sc...@apache.org>
AuthorDate: Sat Feb 23 09:53:27 2019 +0800

    Assertion when cache_config_target_fragment_size is large than MAX_FRAG_SIZE
---
 iocore/cache/Cache.cc      | 19 +++++++++++++++++--
 iocore/cache/CacheWrite.cc |  4 +++-
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/iocore/cache/Cache.cc b/iocore/cache/Cache.cc
index e1416fa..87b6f18 100644
--- a/iocore/cache/Cache.cc
+++ b/iocore/cache/Cache.cc
@@ -3154,6 +3154,18 @@ register_cache_stats(RecRawStatBlock *rsb, const char *prefix)
   REG_INT("span.online", cache_span_online_stat);
 }
 
+int
+FragmentSizeUpdateCb(const char * /* name ATS_UNUSED */, RecDataT /* data_type ATS_UNUSED */, RecData data, void *cookie)
+{
+  if (sizeof(Doc) >= static_cast<size_t>(data.rec_int) || static_cast<size_t>(data.rec_int) - sizeof(Doc) > MAX_FRAG_SIZE) {
+    Warning("The fragments size exceed the limitation, ignore: %" PRId64 ", %d", data.rec_int, cache_config_target_fragment_size);
+    return 0;
+  }
+
+  cache_config_target_fragment_size = data.rec_int;
+  return 0;
+}
+
 void
 ink_cache_init(ts::ModuleVersion v)
 {
@@ -3206,9 +3218,12 @@ ink_cache_init(ts::ModuleVersion v)
   Debug("cache_init", "proxy.config.cache.hit_evacuate_size_limit = %d", cache_config_hit_evacuate_size_limit);
 
   REC_EstablishStaticConfigInt32(cache_config_force_sector_size, "proxy.config.cache.force_sector_size");
-  REC_EstablishStaticConfigInt32(cache_config_target_fragment_size, "proxy.config.cache.target_fragment_size");
 
-  if (cache_config_target_fragment_size == 0) {
+  ink_assert(REC_RegisterConfigUpdateFunc("proxy.config.cache.target_fragment_size", FragmentSizeUpdateCb, nullptr) !=
+             REC_ERR_FAIL);
+  REC_ReadConfigInt32(cache_config_target_fragment_size, "proxy.config.cache.target_fragment_size");
+
+  if (cache_config_target_fragment_size == 0 || cache_config_target_fragment_size - sizeof(Doc) > MAX_FRAG_SIZE) {
     cache_config_target_fragment_size = DEFAULT_TARGET_FRAGMENT_SIZE;
   }
 
diff --git a/iocore/cache/CacheWrite.cc b/iocore/cache/CacheWrite.cc
index f81cf8d..178ec08 100644
--- a/iocore/cache/CacheWrite.cc
+++ b/iocore/cache/CacheWrite.cc
@@ -1369,7 +1369,9 @@ CacheVC::openWriteWriteDone(int event, Event *e)
 static inline int
 target_fragment_size()
 {
-  return cache_config_target_fragment_size - sizeof(Doc);
+  uint64_t value = cache_config_target_fragment_size - sizeof(Doc);
+  ink_release_assert(value <= MAX_FRAG_SIZE);
+  return value;
 }
 
 int