Skip to content

Commit 4a37ca5

Browse files
committed
Fix crash on AS (add inc/dec uses when retrieving AS, country, Obs Points, VLAN)
1 parent bf02a4d commit 4a37ca5

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/NetworkInterface.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6074,6 +6074,7 @@ static bool mac_search_walker(GenericHashEntry *he, void *user_data,
60746074
static bool as_search_walker(GenericHashEntry *he, void *user_data,
60756075
bool *matched) {
60766076
struct flowHostRetriever *r = (struct flowHostRetriever *)user_data;
6077+
u_int32_t prev_actNumEntries = r->actNumEntries;
60776078
AutonomousSystem *as = (AutonomousSystem *)he;
60786079

60796080
if (r->actNumEntries >= r->maxNumEntries) return (true); /* Limit reached */
@@ -6124,6 +6125,11 @@ static bool as_search_walker(GenericHashEntry *he, void *user_data,
61246125
break;
61256126
}
61266127

6128+
if (prev_actNumEntries != r->actNumEntries) {
6129+
/* AS added to entries, inc uses to avoid concurrency issues while walking and processing */
6130+
as->incUses();
6131+
}
6132+
61276133
*matched = true;
61286134
return (false); /* false = keep on walking */
61296135
}
@@ -6133,6 +6139,7 @@ static bool as_search_walker(GenericHashEntry *he, void *user_data,
61336139
static bool obs_point_search_walker(GenericHashEntry *he, void *user_data,
61346140
bool *matched) {
61356141
struct flowHostRetriever *r = (struct flowHostRetriever *)user_data;
6142+
u_int32_t prev_actNumEntries = r->actNumEntries;
61366143
ObservationPoint *obs_point = (ObservationPoint *)he;
61376144

61386145
if (r->actNumEntries >= r->maxNumEntries) return (true); /* Limit reached */
@@ -6173,6 +6180,11 @@ static bool obs_point_search_walker(GenericHashEntry *he, void *user_data,
61736180
break;
61746181
}
61756182

6183+
if (prev_actNumEntries != r->actNumEntries) {
6184+
/* ObsPoint added to entries, inc uses to avoid concurrency issues while walking and processing */
6185+
obs_point->incUses();
6186+
}
6187+
61766188
*matched = true;
61776189
return (false); /* false = keep on walking */
61786190
}
@@ -6182,6 +6194,7 @@ static bool obs_point_search_walker(GenericHashEntry *he, void *user_data,
61826194
static bool country_search_walker(GenericHashEntry *he, void *user_data,
61836195
bool *matched) {
61846196
struct flowHostRetriever *r = (struct flowHostRetriever *)user_data;
6197+
u_int32_t prev_actNumEntries = r->actNumEntries;
61856198
Country *country = (Country *)he;
61866199

61876200
if (r->actNumEntries >= r->maxNumEntries) return (true); /* Limit reached */
@@ -6222,6 +6235,11 @@ static bool country_search_walker(GenericHashEntry *he, void *user_data,
62226235
break;
62236236
}
62246237

6238+
if (prev_actNumEntries != r->actNumEntries) {
6239+
/* Country added to entries, inc uses to avoid concurrency issues while walking and processing */
6240+
country->incUses();
6241+
}
6242+
62256243
*matched = true;
62266244
return (false); /* false = keep on walking */
62276245
}
@@ -6231,6 +6249,7 @@ static bool country_search_walker(GenericHashEntry *he, void *user_data,
62316249
static bool vlan_search_walker(GenericHashEntry *he, void *user_data,
62326250
bool *matched) {
62336251
struct flowHostRetriever *r = (struct flowHostRetriever *)user_data;
6252+
u_int32_t prev_actNumEntries = r->actNumEntries;
62346253
VLAN *vl = (VLAN *)he;
62356254

62366255
if (r->actNumEntries >= r->maxNumEntries) return (true); /* Limit reached */
@@ -6270,6 +6289,11 @@ static bool vlan_search_walker(GenericHashEntry *he, void *user_data,
62706289
break;
62716290
}
62726291

6292+
if (prev_actNumEntries != r->actNumEntries) {
6293+
/* VLAN added to entries, inc uses to avoid concurrency issues while walking and processing */
6294+
vl->incUses();
6295+
}
6296+
62736297
*matched = true;
62746298
return (false); /* false = keep on walking */
62756299
}
@@ -9287,6 +9311,12 @@ int NetworkInterface::getActiveASList(lua_State *vm, const Paginator *p,
92879311
lua_insert(vm, -2);
92889312
lua_settable(vm, -3);
92899313

9314+
// Decrease reference counter for all AS entries (see incUses in as_search_walker)
9315+
for (u_int i = 0; i < retriever.actNumEntries; i++) {
9316+
if (retriever.elems[i].asValue)
9317+
retriever.elems[i].asValue->decUses();
9318+
}
9319+
92909320
// finally free the elements regardless of the sorted kind
92919321
if (retriever.elems) free(retriever.elems);
92929322

@@ -9337,6 +9367,12 @@ int NetworkInterface::getActiveObsPointsList(lua_State *vm,
93379367
lua_insert(vm, -2);
93389368
lua_settable(vm, -3);
93399369

9370+
// Decrease reference counter for all ObsPoint entries (see incUses in obs_point_search_walker)
9371+
for (u_int i = 0; i < retriever.actNumEntries; i++) {
9372+
if (retriever.elems[i].obsPointValue)
9373+
retriever.elems[i].obsPointValue->decUses();
9374+
}
9375+
93409376
// finally free the elements regardless of the sorted kind
93419377
if (retriever.elems) free(retriever.elems);
93429378

@@ -9387,6 +9423,12 @@ int NetworkInterface::getActiveCountriesList(lua_State *vm,
93879423
lua_insert(vm, -2);
93889424
lua_settable(vm, -3);
93899425

9426+
// Decrease reference counter for all Country entries (see incUses in country_search_walker)
9427+
for (u_int i = 0; i < retriever.actNumEntries; i++) {
9428+
if (retriever.elems[i].countryVal)
9429+
retriever.elems[i].countryVal->decUses();
9430+
}
9431+
93909432
// finally free the elements regardless of the sorted kind
93919433
if (retriever.elems) free(retriever.elems);
93929434

@@ -9440,6 +9482,12 @@ int NetworkInterface::getActiveVLANList(lua_State *vm, char *sortColumn,
94409482
lua_insert(vm, -2);
94419483
lua_settable(vm, -3);
94429484

9485+
// Decrease reference counter for all VLAN entries (see incUses in vlan_search_walker)
9486+
for (u_int i = 0; i < retriever.actNumEntries; i++) {
9487+
if (retriever.elems[i].vlanValue)
9488+
retriever.elems[i].vlanValue->decUses();
9489+
}
9490+
94439491
// finally free the elements regardless of the sorted kind
94449492
if (retriever.elems) free(retriever.elems);
94459493

0 commit comments

Comments
 (0)