From a883368f8ce1e2b362be31382301b25dca367850 Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Tue, 11 Jul 2017 11:00:55 -0400 Subject: [PATCH] Fix loop termination condition in trps_filter_outbound_updates() --- include/tr_filter.h | 2 +- trp/trps.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/tr_filter.h b/include/tr_filter.h index 9e556f4..45b8fdc 100644 --- a/include/tr_filter.h +++ b/include/tr_filter.h @@ -46,7 +46,7 @@ #define TR_MAX_FILTERS 5 #define TR_MAX_FILTER_LINES 8 #define TR_MAX_FILTER_SPECS 8 -#define TR_MAX_FILTER_SPEC_MATCHES 8 +#define TR_MAX_FILTER_SPEC_MATCHES 64 /* Filter actions */ typedef enum { diff --git a/trp/trps.c b/trp/trps.c index 1dd1f6c..9d217f2 100644 --- a/trp/trps.c +++ b/trp/trps.c @@ -1707,13 +1707,14 @@ static void trps_filter_outbound_updates(TR_FILTER_SET *filters, GPtrArray *upda TRP_UPD *upd=NULL; guint ii=0; - /* walk backward through the array so we can remove elements */ - for (ii=updates->len-1; ii>=0; ii--) { - upd=g_ptr_array_index(updates, ii); + /* Walk backward through the array so we can remove elements. Careful about loop + * termination - remember that ii is unsigned. */ + for (ii=updates->len; ii>0; ii--) { + upd=g_ptr_array_index(updates, ii-1); trps_filter_one_outbound_update(tr_filter_set_get(filters, TR_FILTER_TYPE_TRP_OUTBOUND), upd); /* see if we removed all the records from this update */ if (trp_upd_num_inforecs(upd)==0) - g_ptr_array_remove_index_fast(updates, ii); /* does not preserve order at index ii or higher */ + g_ptr_array_remove_index_fast(updates, ii-1); /* does not preserve order at index ii or higher */ } } -- 2.1.4