fix vector index range checks

Change-Id: I63c36644c9d93f2c3ec6606ca0205b407499de4e
Signed-off-by: Eyal Bari <ebari@cisco.com>
diff --git a/src/vnet/gre/interface.c b/src/vnet/gre/interface.c
index 0822cd7..70c6c4d 100644
--- a/src/vnet/gre/interface.c
+++ b/src/vnet/gre/interface.c
@@ -135,7 +135,7 @@
   adj = adj_get (ai);
   sw_if_index = adj->rewrite_header.sw_if_index;
 
-  if ((vec_len (gm->tunnel_index_by_sw_if_index) < sw_if_index) ||
+  if ((vec_len (gm->tunnel_index_by_sw_if_index) <= sw_if_index) ||
       (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index]))
     return;
 
diff --git a/src/vnet/ip/ip6_neighbor.c b/src/vnet/ip/ip6_neighbor.c
index 7c7a706..6227ed6 100644
--- a/src/vnet/ip/ip6_neighbor.c
+++ b/src/vnet/ip/ip6_neighbor.c
@@ -4247,7 +4247,7 @@
   ip6_radv_t *radv_info;
   u32 ri;
 
-  if (vec_len (nm->if_radv_pool_index_by_sw_if_index) < sw_if_index)
+  if (vec_len (nm->if_radv_pool_index_by_sw_if_index) <= sw_if_index)
     return 0;
 
   ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
diff --git a/src/vnet/ipip/ipip.c b/src/vnet/ipip/ipip.c
index a47704a..c49be09 100644
--- a/src/vnet/ipip/ipip.c
+++ b/src/vnet/ipip/ipip.c
@@ -355,7 +355,7 @@
 ipip_tunnel_db_find_by_sw_if_index (u32 sw_if_index)
 {
   ipip_main_t *gm = &ipip_main;
-  if (vec_len (gm->tunnel_index_by_sw_if_index) < sw_if_index)
+  if (vec_len (gm->tunnel_index_by_sw_if_index) <= sw_if_index)
     return NULL;
   u32 ti = gm->tunnel_index_by_sw_if_index[sw_if_index];
   if (ti == ~0)
diff --git a/src/vnet/mpls/interface.c b/src/vnet/mpls/interface.c
index c792d56..ec541f7 100644
--- a/src/vnet/mpls/interface.c
+++ b/src/vnet/mpls/interface.c
@@ -29,7 +29,7 @@
 {
     mpls_main_t * mm = &mpls_main;
 
-    if (vec_len(mm->mpls_enabled_by_sw_if_index) < sw_if_index)
+    if (vec_len(mm->mpls_enabled_by_sw_if_index) <= sw_if_index)
         return (0);
 
     return (mm->mpls_enabled_by_sw_if_index[sw_if_index]);
diff --git a/src/vnet/mpls/mpls_tunnel.c b/src/vnet/mpls/mpls_tunnel.c
index d3faeac..1d2614ca 100644
--- a/src/vnet/mpls/mpls_tunnel.c
+++ b/src/vnet/mpls/mpls_tunnel.c
@@ -52,7 +52,7 @@
 static mpls_tunnel_t*
 mpls_tunnel_get_from_sw_if_index (u32 sw_if_index)
 {
-    if ((vec_len(mpls_tunnel_db) < sw_if_index) ||
+    if ((vec_len(mpls_tunnel_db) <= sw_if_index) ||
         (~0 == mpls_tunnel_db[sw_if_index]))
         return (NULL);
 
diff --git a/src/vnet/unix/gdb_funcs.c b/src/vnet/unix/gdb_funcs.c
index 41ae3bd..d78773e 100644
--- a/src/vnet/unix/gdb_funcs.c
+++ b/src/vnet/unix/gdb_funcs.c
@@ -131,7 +131,7 @@
   vlib_main_t *vm = vlib_get_main ();
   vlib_node_main_t *nm = &vm->node_main;
 
-  if (index > vec_len (nm->nodes))
+  if (index >= vec_len (nm->nodes))
     {
       fformat (stderr, "%d out of range, max %d\n", vec_len (nm->nodes));
       return;
diff --git a/src/vnet/util/trajectory.c b/src/vnet/util/trajectory.c
index 91812dc..2538c7e 100644
--- a/src/vnet/util/trajectory.c
+++ b/src/vnet/util/trajectory.c
@@ -44,7 +44,7 @@
 
       node_index = trace[i];
 
-      if (node_index > vec_len (vnm->nodes))
+      if (node_index >= vec_len (vnm->nodes))
 	{
 	  fformat (stderr, "Skip bogus node index %d\n", node_index);
 	  continue;
diff --git a/src/vnet/vxlan/vxlan.c b/src/vnet/vxlan/vxlan.c
index e1ee348..f0312be 100644
--- a/src/vnet/vxlan/vxlan.c
+++ b/src/vnet/vxlan/vxlan.c
@@ -1124,7 +1124,7 @@
 {
   vxlan_main_t *vxm = &vxlan_main;
 
-  if (sw_if_index > vec_len (vxm->tunnel_index_by_sw_if_index))
+  if (sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index))
     return ~0;
   return vxm->tunnel_index_by_sw_if_index[sw_if_index];
 }