From: Richard Russon Date: Sat, 27 Apr 2019 20:26:38 +0000 (+0100) Subject: libaddress: fix group code for degenerate cases X-Git-Tag: 2019-10-25~238^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3ebf184473f44e7c95efd6d92fa0fc10bf66ea66;p=neomutt libaddress: fix group code for degenerate cases --- diff --git a/address/group.c b/address/group.c index 9603eaa9c..edcbac9e6 100644 --- a/address/group.c +++ b/address/group.c @@ -102,6 +102,9 @@ static void group_remove(struct Group *g) */ void mutt_grouplist_clear(struct GroupList *head) { + if (!head) + return; + struct GroupNode *np = STAILQ_FIRST(head), *next = NULL; while (np) { @@ -132,6 +135,9 @@ static bool empty_group(struct Group *g) */ void mutt_grouplist_add(struct GroupList *head, struct Group *group) { + if (!head || !group) + return; + struct GroupNode *np = NULL; STAILQ_FOREACH(np, head, entries) { @@ -149,6 +155,9 @@ void mutt_grouplist_add(struct GroupList *head, struct Group *group) */ void mutt_grouplist_destroy(struct GroupList *head) { + if (!head) + return; + struct GroupNode *np = STAILQ_FIRST(head), *next = NULL; while (np) { @@ -166,13 +175,11 @@ void mutt_grouplist_destroy(struct GroupList *head) */ static void group_add_addrlist(struct Group *g, struct Address *a) { - struct Address **p = NULL, *q = NULL; - - if (!g) - return; - if (!a) + if (!g || !a) return; + struct Address **p = NULL, *q = NULL; + for (p = &g->as; *p; p = &((*p)->next)) ; @@ -236,6 +243,9 @@ static int group_remove_regex(struct Group *g, const char *s) */ void mutt_grouplist_add_addrlist(struct GroupList *head, struct Address *a) { + if (!head || !a) + return; + struct GroupNode *np = NULL; STAILQ_FOREACH(np, head, entries) { @@ -252,6 +262,9 @@ void mutt_grouplist_add_addrlist(struct GroupList *head, struct Address *a) */ int mutt_grouplist_remove_addrlist(struct GroupList *head, struct Address *a) { + if (!head || !a) + return -1; + int rc = 0; struct GroupNode *np = NULL; @@ -278,6 +291,9 @@ int mutt_grouplist_remove_addrlist(struct GroupList *head, struct Address *a) int mutt_grouplist_add_regex(struct GroupList *head, const char *s, int flags, struct Buffer *err) { + if (!head || !s) + return -1; + int rc = 0; struct GroupNode *np = NULL; @@ -299,6 +315,9 @@ int mutt_grouplist_add_regex(struct GroupList *head, const char *s, int flags, */ int mutt_grouplist_remove_regex(struct GroupList *head, const char *s) { + if (!head || !s) + return -1; + int rc = 0; struct GroupNode *np = NULL; STAILQ_FOREACH(np, head, entries)