trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpe...@apache.org
Subject [6/7] trafficserver git commit: Fix hook ID bounds checking
Date Fri, 02 Jan 2015 21:09:00 GMT
Fix hook ID bounds checking

Coverity CID #1242006


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/eba452d5
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/eba452d5
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/eba452d5

Branch: refs/heads/master
Commit: eba452d5f876858d97984976a9245f98f1f915d4
Parents: 15ae8f0
Author: James Peach <jpeach@apache.org>
Authored: Mon Dec 29 22:04:04 2014 -0800
Committer: James Peach <jpeach@apache.org>
Committed: Fri Jan 2 12:45:52 2015 -0800

----------------------------------------------------------------------
 proxy/InkAPI.cc        |  8 ++------
 proxy/InkAPIInternal.h | 18 ++++++++++++------
 2 files changed, 14 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/eba452d5/proxy/InkAPI.cc
----------------------------------------------------------------------
diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc
index 62f0870..fdb5bde 100644
--- a/proxy/InkAPI.cc
+++ b/proxy/InkAPI.cc
@@ -631,17 +631,13 @@ sdk_sanity_check_alt_info(TSHttpAltInfo info)
 TSReturnCode
 sdk_sanity_check_hook_id(TSHttpHookID id)
 {
-  if (id<TS_HTTP_READ_REQUEST_HDR_HOOK || id> TS_HTTP_LAST_HOOK)
-    return TS_ERROR;
-  return TS_SUCCESS;
+  return HttpAPIHooks::is_valid(id) ? TS_SUCCESS : TS_ERROR;
 }
 
 TSReturnCode
 sdk_sanity_check_lifecycle_hook_id(TSLifecycleHookID id)
 {
-  if (id<TS_LIFECYCLE_PORTS_INITIALIZED_HOOK || id> TS_LIFECYCLE_LAST_HOOK)
-    return TS_ERROR;
-  return TS_SUCCESS;
+  return LifecycleAPIHooks::is_valid(id) ? TS_SUCCESS : TS_ERROR;
 }
 
 TSReturnCode

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/eba452d5/proxy/InkAPIInternal.h
----------------------------------------------------------------------
diff --git a/proxy/InkAPIInternal.h b/proxy/InkAPIInternal.h
index 79a948b..49dc0bf 100644
--- a/proxy/InkAPIInternal.h
+++ b/proxy/InkAPIInternal.h
@@ -246,30 +246,36 @@ template < typename ID, ID N >
 void
 FeatureAPIHooks<ID,N>::prepend(ID id, INKContInternal *cont)
 {
-  hooks_p = true;
-  m_hooks[id].prepend(cont);
+  if (likely(is_valid(id))) {
+    hooks_p = true;
+    m_hooks[id].prepend(cont);
+  }
 }
 
 template < typename ID, ID N >
 void
 FeatureAPIHooks<ID,N>::append(ID id, INKContInternal *cont)
 {
-  hooks_p = true;
-  m_hooks[id].append(cont);
+  if (likely(is_valid(id))) {
+    hooks_p = true;
+    m_hooks[id].append(cont);
+  }
 }
 
 template < typename ID, ID N >
 APIHook *
 FeatureAPIHooks<ID,N>::get(ID id) const
 {
-  return m_hooks[id].get();
+  return likely(is_valid(id)) ? m_hooks[id].get() : NULL;
 }
 
 template < typename ID, ID N >
 void
 FeatureAPIHooks<ID,N>::invoke(ID id, int event, void* data)
 {
-  m_hooks[id].invoke(event, data);
+  if (likely(is_valid(id))) {
+    m_hooks[id].invoke(event, data);
+  }
 }
 
 template < typename ID, ID N >


Mime
View raw message