diff options
| author | Qiuwen Lu <[email protected]> | 2020-06-16 16:50:27 +0800 |
|---|---|---|
| committer | Qiuwen Lu <[email protected]> | 2020-06-16 16:50:27 +0800 |
| commit | 5ef8dc166bcb20e6dee6d77362ee7e2e6665b34e (patch) | |
| tree | 1adb8845775fd27ae8653344b7fcc766fdd3eb7d | |
| parent | 26314ca06c238d85debf6d08d5a38acb93e5a017 (diff) | |
修正LinkInfo表插入过程中由于HashKey为0导致插入失败的问题v4.3.22-20200616
* 原实现没有检查HashKey的长度,当长度为0时向哈希表内将插入失败,导致程序崩溃;
* 现修正,在LookupLinkID时检查长度。
| -rw-r--r-- | tunnat/src/runtime.cc | 9 | ||||
| -rw-r--r-- | tunnat/src/session.cc | 11 |
2 files changed, 17 insertions, 3 deletions
diff --git a/tunnat/src/runtime.cc b/tunnat/src/runtime.cc index f17689e..9143cf1 100644 --- a/tunnat/src/runtime.cc +++ b/tunnat/src/runtime.cc @@ -101,13 +101,18 @@ static void __phy_to_virt_link_info_check(TunnatInstance * instance, TunnatThrea marsio_buff_t * mbuf, TunnelContainerArray &tun_array) { LinkInfoTable * link_info_table = th_instance->link_info_table; - tunnat_link_id_t link_id; + tunnat_link_id_t link_id = (tunnat_link_id_t)(-1); /* 未找到Link-ID */ - if(link_info_table->LookupLinkID(tun_array, link_id) < 0) + if(link_info_table->LookupLinkID(tun_array, link_id) == -ENOENT) { link_info_table->AddTunnel(tun_array, link_id); } + /* 失败,直接返回 */ + else + { + return; + } auto * ctrlzone = static_cast<mr_tunnat_ctrlzone *>(marsio_buff_ctrlzone(mbuf, g_ctrlzone_id)); ctrlzone->virtual_link_id = link_id; diff --git a/tunnat/src/session.cc b/tunnat/src/session.cc index bdf2108..3047735 100644 --- a/tunnat/src/session.cc +++ b/tunnat/src/session.cc @@ -235,10 +235,19 @@ int LinkInfoTable::LookupLinkID(const TunnelContainerArray &tun_array, tunnat_li char tun_array_hash_key[TUN_ARRAY_HASH_KEY_SIZE]; size_t sz_tun_array_hash_key = tun_array.LinkTunnelToHashKey(tun_array_hash_key, sizeof(tun_array_hash_key)); + if(sz_tun_array_hash_key <= 0) + { + return -EINVAL; + } + auto * result = (IndexTunnelTableEntry *)MESA_htable_search(tb_tunnel_index_by_tunnel, (const uchar *)tun_array_hash_key, (uint)sz_tun_array_hash_key); - if(!result) return -ENOENT; + if(!result) + { + return -ENOENT; + } + out_tunnat_link_id = result->link_id; /* 再次查询Store表,避免表项由于长时间仅在Index表查询而未在Store表查询引起Store的超时淘汰 */ |
