Skip to content

Commit c0515f7

Browse files
committed
ab: cure nullptr derefs in ab_tree_get_{company,mlist}_info
Fixes: gromox-0~666
1 parent 68e0dc3 commit c0515f7

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

exch/nsp/ab_tree.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -940,8 +940,10 @@ void ab_tree_get_mlist_info(const SIMPLE_TREE_NODE *pnode,
940940
auto pabnode = containerof(pnode, AB_NODE, stree);
941941
if (pabnode->node_type != abnode_type::mlist &&
942942
pabnode->node_type != abnode_type::remote) {
943-
mail_address[0] = '\0';
944-
*plist_privilege = 0;
943+
if (mail_address != nullptr)
944+
mail_address[0] = '\0';
945+
if (plist_privilege != nullptr)
946+
*plist_privilege = 0;
945947
return;
946948
}
947949
auto obj = static_cast<sql_user *>(pabnode->d_info);
@@ -973,14 +975,18 @@ void ab_tree_get_company_info(const SIMPLE_TREE_NODE *pnode,
973975
if (pabnode->node_type == abnode_type::remote) {
974976
pbase = ab_tree_get_base(-pabnode->id);
975977
if (pbase == nullptr) {
976-
str_name[0] = '\0';
977-
str_address[0] = '\0';
978+
if (str_name != nullptr)
979+
str_name[0] = '\0';
980+
if (str_address != nullptr)
981+
str_address[0] = '\0';
978982
return;
979983
}
980984
auto iter = pbase->phash.find(pabnode->minid);
981985
if (iter == pbase->phash.end()) {
982-
str_name[0] = '\0';
983-
str_address[0] = '\0';
986+
if (str_name != nullptr)
987+
str_name[0] = '\0';
988+
if (str_address != nullptr)
989+
str_address[0] = '\0';
984990
return;
985991
}
986992
pabnode = iter->second;

exch/zcore/ab_tree.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,8 @@ static void ab_tree_get_mlist_info(const SIMPLE_TREE_NODE *pnode,
869869
auto pabnode = containerof(pnode, AB_NODE, stree);
870870
if (pabnode->node_type != abnode_type::mlist &&
871871
pabnode->node_type != abnode_type::remote) {
872-
mail_address[0] = '\0';
872+
if (mail_address != nullptr)
873+
mail_address[0] = '\0';
873874
*plist_privilege = 0;
874875
return;
875876
}
@@ -891,14 +892,18 @@ static void ab_tree_get_company_info(const SIMPLE_TREE_NODE *pnode,
891892
if (pabnode->node_type == abnode_type::remote) {
892893
pbase = ab_tree_get_base(-pabnode->id);
893894
if (pbase == nullptr) {
894-
str_name[0] = '\0';
895-
str_address[0] = '\0';
895+
if (str_name != nullptr)
896+
str_name[0] = '\0';
897+
if (str_address != nullptr)
898+
str_address[0] = '\0';
896899
return;
897900
}
898901
auto iter = pbase->phash.find(pabnode->minid);
899902
if (iter == pbase->phash.end()) {
900-
str_name[0] = '\0';
901-
str_address[0] = '\0';
903+
if (str_name != nullptr)
904+
str_name[0] = '\0';
905+
if (str_address != nullptr)
906+
str_address[0] = '\0';
902907
return;
903908
}
904909
pabnode = iter->second;

0 commit comments

Comments
 (0)