@@ -756,6 +756,8 @@ ec_error_t nsp_interface_query_rows(NSPI_HANDLE handle, uint32_t flags,
756756 *pprows = nullptr ;
757757 if (g_nsp_trace > 0 )
758758 fprintf (stderr, " nsp_query_rows: table_count=%u count=%u\n " , table_count, count);
759+ if (handle.handle_type != HANDLE_EXCHANGE_NSP)
760+ return ecError;
759761 nsp_trace (__func__, 0 , pstat);
760762
761763 if (pstat == nullptr || pstat->codepage == CP_WINUNICODE)
@@ -787,7 +789,7 @@ ec_error_t nsp_interface_query_rows(NSPI_HANDLE handle, uint32_t flags,
787789 return ecTableTooBig;
788790 }
789791 auto pbase = ab_tree::AB.get (handle.guid );
790- if (handle. handle_type != HANDLE_EXCHANGE_NSP || !pbase || (g_session_check && pbase->guid () != handle.guid ))
792+ if (pbase == nullptr || (g_session_check && pbase->guid () != handle.guid ))
791793 return ecError;
792794 auto rowset = common_util_proprowset_init ();
793795 if (rowset == nullptr )
@@ -902,6 +904,8 @@ ec_error_t nsp_interface_seek_entries(NSPI_HANDLE handle, uint32_t reserved,
902904{
903905 *pprows = nullptr ;
904906 nsp_trace (__func__, 0 , pstat);
907+ if (handle.handle_type != HANDLE_EXCHANGE_NSP)
908+ return ecError;
905909 if (pstat == nullptr || pstat->codepage == CP_WINUNICODE ||
906910 reserved != 0 )
907911 return ecNotSupported;
@@ -936,7 +940,7 @@ ec_error_t nsp_interface_seek_entries(NSPI_HANDLE handle, uint32_t reserved,
936940 return ecTableTooBig;
937941 }
938942 auto pbase = ab_tree::AB.get (handle.guid );
939- if (! pbase || handle. handle_type != HANDLE_EXCHANGE_NSP || (g_session_check && pbase->guid () != handle.guid ))
943+ if (pbase == nullptr || (g_session_check && pbase->guid () != handle.guid ))
940944 return ecError;
941945 auto rowset = common_util_proprowset_init ();
942946 if (rowset == nullptr )
@@ -1175,6 +1179,8 @@ ec_error_t nsp_interface_get_matches(NSPI_HANDLE handle, uint32_t reserved1,
11751179 *ppoutmids = nullptr ;
11761180 *pprows = nullptr ;
11771181 nsp_trace (__func__, 0 , pstat);
1182+ if (handle.handle_type != HANDLE_EXCHANGE_NSP)
1183+ return ecError;
11781184 PROPERTY_VALUE prop_val;
11791185
11801186 if (pstat == nullptr || pstat->codepage == CP_WINUNICODE)
@@ -1187,12 +1193,11 @@ ec_error_t nsp_interface_get_matches(NSPI_HANDLE handle, uint32_t reserved1,
11871193 if (reserved1 != 0 || ppropname != nullptr )
11881194 return ecNotSupported;
11891195 auto base = ab_tree::AB.get (handle.guid );
1190- if (! base || handle. handle_type != HANDLE_EXCHANGE_NSP || (g_session_check && base->guid () != handle.guid ))
1196+ if (base == nullptr || (g_session_check && base->guid () != handle.guid ))
11911197 return ecError;
11921198 auto outmids = common_util_proptagarray_init ();
1193- if (outmids == nullptr ) {
1199+ if (outmids == nullptr )
11941200 return ecServerOOM;
1195- }
11961201 NSP_ROWSET *rowset = nullptr ;
11971202 if (pproptags != nullptr ) {
11981203 if (pproptags->cvalues > 100 )
@@ -1343,7 +1348,8 @@ ec_error_t nsp_interface_resort_restriction(NSPI_HANDLE handle, uint32_t reserve
13431348{
13441349 *ppoutmids = nullptr ;
13451350 nsp_trace (__func__, 0 , pstat);
1346-
1351+ if (handle.handle_type != HANDLE_EXCHANGE_NSP)
1352+ return ecError;
13471353 if (pstat == nullptr || pstat->codepage == CP_WINUNICODE)
13481354 return ecNotSupported;
13491355 auto parray = ndr_stack_anew<nsp_sort_item>(NDR_STACK_IN, pinmids->cvalues );
@@ -1356,7 +1362,7 @@ ec_error_t nsp_interface_resort_restriction(NSPI_HANDLE handle, uint32_t reserve
13561362 if (outmids->pproptag == nullptr )
13571363 return ecServerOOM;
13581364 auto base = ab_tree::AB.get (handle.guid );
1359- if (! base || handle. handle_type != HANDLE_EXCHANGE_NSP || (g_session_check && base->guid () != handle.guid ))
1365+ if (base == nullptr || (g_session_check && base->guid () != handle.guid ))
13601366 return ecError;
13611367
13621368 size_t count = 0 ;
@@ -1396,10 +1402,12 @@ ec_error_t nsp_interface_dntomid(NSPI_HANDLE handle, uint32_t reserved,
13961402 if (g_nsp_trace > 0 )
13971403 fprintf (stderr, " Entering %s\n " , __func__);
13981404 *ppoutmids = nullptr ;
1405+ if (handle.handle_type != HANDLE_EXCHANGE_NSP)
1406+ return ecError;
13991407 if (pnames == nullptr )
14001408 return ecSuccess;
14011409 auto base = ab_tree::AB.get (handle.guid );
1402- if (! base || handle. handle_type != HANDLE_EXCHANGE_NSP || (g_session_check && base->guid () != handle.guid ))
1410+ if (base == nullptr || (g_session_check && base->guid () != handle.guid ))
14031411 return ecError;
14041412 auto outmids = ndr_stack_anew<LPROPTAG_ARRAY>(NDR_STACK_OUT);
14051413 if (outmids == nullptr )
@@ -1529,16 +1537,14 @@ ec_error_t nsp_interface_get_proplist(NSPI_HANDLE handle, uint32_t flags,
15291537{
15301538 if (g_nsp_trace > 0 )
15311539 fprintf (stderr, " Entering %s\n " , __func__);
1532-
1533- auto base = ab_tree::AB.get (handle.guid );
1534- if (!base || HANDLE_EXCHANGE_NSP != handle.handle_type || (g_session_check && base->guid () != handle.guid )) {
1535- *tags = nullptr ;
1540+ *tags = nullptr ;
1541+ if (handle.handle_type != HANDLE_EXCHANGE_NSP)
15361542 return ecError;
1537- }
1538- if (mid == 0 ) {
1539- *tags = nullptr ;
1543+ if (mid == 0 )
15401544 return ecInvalidObject;
1541- }
1545+ auto base = ab_tree::AB.get (handle.guid );
1546+ if (base == nullptr || (g_session_check && base->guid () != handle.guid ))
1547+ return ecError;
15421548 *tags = ndr_stack_anew<LPROPTAG_ARRAY>(NDR_STACK_OUT);
15431549 if (*tags == nullptr )
15441550 return ecServerOOM;
@@ -1578,12 +1584,13 @@ ec_error_t nsp_interface_get_props(NSPI_HANDLE handle, uint32_t flags,
15781584{
15791585 *pprows = nullptr ;
15801586 nsp_trace (__func__, 0 , pstat);
1581-
1587+ if (handle.handle_type != HANDLE_EXCHANGE_NSP)
1588+ return ecError;
15821589 if (pstat == nullptr )
15831590 return ecNotSupported;
15841591 bool b_ephid = flags & fEphID ;
15851592 auto base = ab_tree::AB.get (handle.guid );
1586- if (! base || handle. handle_type != HANDLE_EXCHANGE_NSP || (g_session_check && base->guid () != handle.guid ))
1593+ if (base == nullptr || (g_session_check && base->guid () != handle.guid ))
15871594 return ecError;
15881595 if (g_nsp_trace >= 2 ) {
15891596 if (pproptags == nullptr ) {
@@ -1697,11 +1704,12 @@ ec_error_t nsp_interface_compare_mids(NSPI_HANDLE handle, uint32_t reserved,
16971704 const STAT *pstat, uint32_t mid1, uint32_t mid2, int32_t *cmp)
16981705{
16991706 nsp_trace (__func__, 0 , pstat);
1700-
1707+ if (handle.handle_type != HANDLE_EXCHANGE_NSP)
1708+ return ecError;
17011709 if (pstat != nullptr && pstat->codepage == CP_WINUNICODE)
17021710 return ecNotSupported;
17031711 auto base = ab_tree::AB.get (handle.guid );
1704- if (! base || handle. handle_type != HANDLE_EXCHANGE_NSP || (g_session_check && base->guid () != handle.guid ))
1712+ if (base == nullptr || (g_session_check && base->guid () != handle.guid ))
17051713 return ecError;
17061714
17071715 if (NULL == pstat || 0 == pstat->container_id ) {
@@ -1846,7 +1854,8 @@ ec_error_t nsp_interface_get_specialtable(NSPI_HANDLE handle, uint32_t flags,
18461854{
18471855 *pprows = nullptr ;
18481856 nsp_trace (__func__, 0 , pstat);
1849-
1857+ if (handle.handle_type != HANDLE_EXCHANGE_NSP)
1858+ return ecError;
18501859 if (flags & NspiAddressCreationTemplates)
18511860 /* creation of templates table */
18521861 return ecSuccess;
@@ -1856,7 +1865,7 @@ ec_error_t nsp_interface_get_specialtable(NSPI_HANDLE handle, uint32_t flags,
18561865 if (!b_unicode && codepage == CP_WINUNICODE)
18571866 return ecNotSupported;
18581867 auto base = ab_tree::AB.get (handle.guid );
1859- if (! base || handle. handle_type != HANDLE_EXCHANGE_NSP || (g_session_check && base->guid () != handle.guid ))
1868+ if (base == nullptr || (g_session_check && base->guid () != handle.guid ))
18601869 return ecError;
18611870 (*pversion) ++;
18621871 auto rowset = common_util_proprowset_init ();
@@ -1891,13 +1900,15 @@ ec_error_t nsp_interface_mod_linkatt(NSPI_HANDLE handle, uint32_t flags,
18911900 if (g_nsp_trace > 0 )
18921901 fprintf (stderr, " Entering %s {flags=%xh,proptag=%xh,mid=%xh}\n " ,
18931902 __func__, flags, proptag, mid);
1903+ if (handle.handle_type != HANDLE_EXCHANGE_NSP)
1904+ return ecError;
18941905 if (mid == 0 )
18951906 return ecInvalidObject;
18961907 if (proptag != PR_EMS_AB_PUBLIC_DELEGATES)
18971908 return ecNotSupported;
18981909 auto rpc_info = get_rpc_info ();
18991910 auto base = ab_tree::AB.get (handle.guid );
1900- if (! base || handle. handle_type != HANDLE_EXCHANGE_NSP || (g_session_check && base->guid () != handle.guid ))
1911+ if (base == nullptr || (g_session_check && base->guid () != handle.guid ))
19011912 return ecError;
19021913 ab_tree::ab_node tnode (base, mid);
19031914 if (!tnode.exists ())
@@ -2097,6 +2108,8 @@ ec_error_t nsp_interface_resolve_namesw(NSPI_HANDLE handle, uint32_t reserved,
20972108 *ppmids = nullptr ;
20982109 *pprows = nullptr ;
20992110 nsp_trace (__func__, 0 , pstat);
2111+ if (handle.handle_type != HANDLE_EXCHANGE_NSP)
2112+ return ecError;
21002113 if (pstat->codepage == CP_WINUNICODE)
21012114 return ecNotSupported;
21022115 /*
@@ -2106,8 +2119,7 @@ ec_error_t nsp_interface_resolve_namesw(NSPI_HANDLE handle, uint32_t reserved,
21062119 non-zero so we skip it.
21072120 */
21082121 auto base = ab_tree::AB.get (handle.guid );
2109-
2110- if (!base || handle.handle_type != HANDLE_EXCHANGE_NSP || (g_session_check && base->guid () != handle.guid ))
2122+ if (base == nullptr || (g_session_check && base->guid () != handle.guid ))
21112123 return ecError;
21122124 if (NULL == pproptags) {
21132125 auto nt = ndr_stack_anew<LPROPTAG_ARRAY>(NDR_STACK_IN);
0 commit comments