libwbclient: Fix wbcListGroups against too small num_entries
authorVolker Lendecke <vl@samba.org>
Mon, 19 Apr 2010 13:50:11 +0000 (15:50 +0200)
committerVolker Lendecke <vl@samba.org>
Mon, 19 Apr 2010 14:31:02 +0000 (16:31 +0200)
Thanks for the s4 winbind sending 0 here and Tridge to point it out to me :-)

nsswitch/libwbclient/wbc_sid.c

index b3a683ddb5b34d4ce0354be30b10b8a7ea4a0412..63d566fa9f9aee3d499de28ebfac66b1c26cf0b5 100644 (file)
@@ -714,8 +714,17 @@ wbcErr wbcListGroups(const char *domain_name,
 
        next = (const char *)response.extra_data.data;
        while (next) {
-               const char *current = next;
-               char *k = strchr(next, ',');
+               const char *current;
+               char *k;
+
+               if (num_groups >= response.data.num_entries) {
+                       wbc_status = WBC_ERR_INVALID_RESPONSE;
+                       goto done;
+               }
+
+               current = next;
+               k = strchr(next, ',');
+
                if (k) {
                        k[0] = '\0';
                        next = k+1;
@@ -726,10 +735,6 @@ wbcErr wbcListGroups(const char *domain_name,
                groups[num_groups] = strdup(current);
                BAIL_ON_PTR_ERROR(groups[num_groups], wbc_status);
                num_groups += 1;
-               if (num_groups > response.data.num_entries) {
-                       wbc_status = WBC_ERR_INVALID_RESPONSE;
-                       goto done;
-               }
        }
        if (num_groups != response.data.num_entries) {
                wbc_status = WBC_ERR_INVALID_RESPONSE;