Skip to content

Commit dabe99f

Browse files
committed
correct route matching, dispatch, and purge logic
1 parent 2271ffa commit dabe99f

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/addr_families.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ WOLFSENTRY_LOCAL wolfsentry_errcode_t wolfsentry_addr_family_clone(
324324
if ((*new_bynumber = (struct wolfsentry_addr_family_bynumber *)WOLFSENTRY_MALLOC_1(dest_context->hpi.allocator, sizeof **new_bynumber)) == NULL)
325325
WOLFSENTRY_ERROR_RETURN(SYS_RESOURCE_FAILED);
326326
if ((*new_byname = (struct wolfsentry_addr_family_byname *)WOLFSENTRY_MALLOC_1(dest_context->hpi.allocator, byname_size)) == NULL) {
327-
(void)WOLFSENTRY_FREE_1(dest_context->hpi.allocator, (void *)new_byname);
327+
(void)WOLFSENTRY_FREE_1(dest_context->hpi.allocator, (void *)*new_bynumber);
328328
WOLFSENTRY_ERROR_RETURN(SYS_RESOURCE_FAILED);
329329
}
330330
memcpy(*new_bynumber, src_bynumber, sizeof **new_bynumber);

src/routes.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ static int compare_match_exactness(const struct wolfsentry_route *target, const
520520
} else
521521
#endif
522522
{
523-
right_match_score = addr_prefix_match_size(WOLFSENTRY_ROUTE_LOCAL_ADDR(target), WOLFSENTRY_ROUTE_LOCAL_ADDR_BITS(target), WOLFSENTRY_ROUTE_LOCAL_ADDR(right), WOLFSENTRY_ROUTE_LOCAL_ADDR_BITS(right));
523+
right_match_score = addr_prefix_match_size(WOLFSENTRY_ROUTE_REMOTE_ADDR(target), WOLFSENTRY_ROUTE_REMOTE_ADDR_BITS(target), WOLFSENTRY_ROUTE_REMOTE_ADDR(right), WOLFSENTRY_ROUTE_REMOTE_ADDR_BITS(right));
524524
}
525525
}
526526

@@ -2562,8 +2562,8 @@ static wolfsentry_errcode_t wolfsentry_route_event_dispatch_0(
25622562
(WOLFSENTRY_ATOMIC_LOAD(rule_route->meta.derogatory_count)
25632563
>= config->config.derogatory_threshold_for_penaltybox)
25642564
:
2565-
(WOLFSENTRY_ATOMIC_LOAD(rule_route->meta.derogatory_count)
2566-
- WOLFSENTRY_ATOMIC_LOAD(rule_route->meta.commendable_count)
2565+
((int)WOLFSENTRY_ATOMIC_LOAD(rule_route->meta.derogatory_count)
2566+
- (int)WOLFSENTRY_ATOMIC_LOAD(rule_route->meta.commendable_count)
25672567
>= (int)config->config.derogatory_threshold_for_penaltybox)))
25682568
{
25692569
wolfsentry_route_flags_t flags_before;
@@ -2961,6 +2961,10 @@ static wolfsentry_errcode_t wolfsentry_route_event_dispatch_by_route_1(
29612961
WOLFSENTRY_ERROR_UNLOCK_AND_RERETURN(ret);
29622962
}
29632963

2964+
if (route->header.parent_table == NULL) {
2965+
ret = WOLFSENTRY_ERROR_ENCODE(INTERNAL_CHECK_FATAL);
2966+
goto out;
2967+
}
29642968
if (route->header.parent_table->ent_type != WOLFSENTRY_OBJECT_TYPE_ROUTE) {
29652969
ret = WOLFSENTRY_ERROR_ENCODE(WRONG_OBJECT);
29662970
goto out;
@@ -3095,7 +3099,7 @@ static wolfsentry_errcode_t wolfsentry_route_stale_purge_1(
30953099
(! (route->flags & WOLFSENTRY_ROUTE_FLAG_PENDING_DELETE)) &&
30963100
((table->max_purgeable_idle_time == 0) || (now - route->meta.last_hit_time > table->max_purgeable_idle_time)))
30973101
{
3098-
continue;
3102+
break;
30993103
}
31003104
}
31013105
#ifdef WOLFSENTRY_THREADSAFE

0 commit comments

Comments
 (0)