From 9ffe86dc7019615b1d6c6a2ebdeb8dd51f03130a Mon Sep 17 00:00:00 2001 From: Sumit Bose Date: Wed, 1 Oct 2014 16:19:18 +0200 Subject: [PATCH] add_v1_group_data: fix for empty members list --- src/providers/ipa/ipa_s2n_exop.c | 41 ++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/src/providers/ipa/ipa_s2n_exop.c b/src/providers/ipa/ipa_s2n_exop.c index 76494a0..e3fc882 100644 --- a/src/providers/ipa/ipa_s2n_exop.c +++ b/src/providers/ipa/ipa_s2n_exop.c @@ -621,28 +621,37 @@ static errno_t add_v1_group_data(BerElement *ber, struct resp_attrs *attrs) goto done; } - for (attrs->ngroups = 0; list[attrs->ngroups] != NULL; - attrs->ngroups++); + if (list != NULL) { + for (attrs->ngroups = 0; list[attrs->ngroups] != NULL; + attrs->ngroups++); + + if (attrs->ngroups > 0) { + attrs->a.group.gr_mem = talloc_zero_array(attrs, char *, + attrs->ngroups + 1); + if (attrs->a.group.gr_mem == NULL) { + DEBUG(SSSDBG_OP_FAILURE, "talloc_array failed.\n"); + ret = ENOMEM; + goto done; + } - if (attrs->ngroups > 0) { - attrs->a.group.gr_mem = talloc_zero_array(attrs, char *, - attrs->ngroups + 1); + for (c = 0; c < attrs->ngroups; c++) { + attrs->a.group.gr_mem[c] = + talloc_strdup(attrs->a.group.gr_mem, + list[c]); + if (attrs->a.group.gr_mem[c] == NULL) { + DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n"); + ret = ENOMEM; + goto done; + } + } + } + } else { + attrs->a.group.gr_mem = talloc_zero_array(attrs, char *, 1); if (attrs->a.group.gr_mem == NULL) { DEBUG(SSSDBG_OP_FAILURE, "talloc_array failed.\n"); ret = ENOMEM; goto done; } - - for (c = 0; c < attrs->ngroups; c++) { - attrs->a.group.gr_mem[c] = - talloc_strdup(attrs->a.group.gr_mem, - list[c]); - if (attrs->a.group.gr_mem[c] == NULL) { - DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n"); - ret = ENOMEM; - goto done; - } - } } tag = ber_peek_tag(ber, &ber_len); -- 1.8.3.1