shithub: ext4srv

Download patch

ref: 3669b3e2e684a40b20c5a22bf4f6ee898e616447
parent: efbec63da9c094e0908047352d1d5480dfbc4b97
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Thu Nov 12 07:52:23 EST 2020

group: fix outright broken ingroup

--- a/group.c
+++ b/group.c
@@ -25,19 +25,19 @@
 				goto error;
 			}
 
-			if((g = realloc(gs->g, (gs->ng+1)*sizeof(*g))) == nil)
+			if((g = realloc(gs->g, (gs->ng+1)*sizeof(Group))) == nil)
 				goto error;
 			gs->g = g;
 			g += gs->ng++;
+			memset(g, 0, sizeof(*g));
 			g->id = id;
 			g->name = a[0];
-			g->memb = nil;
-			g->nmemb = 0;
 			for(m = a[3]; n > 3 && *m; *m++ = 0){
-				if((memb = realloc(g->memb, (g->nmemb+1)*sizeof(*g->memb))) == nil)
+				if((memb = realloc(g->memb, (g->nmemb+1)*sizeof(Group))) == nil)
 					goto error;
 				g->memb = memb;
 				memb += g->nmemb++;
+				memset(memb, 0, sizeof(*memb));
 				memb->name = m;
 				if((m = strchr(m, ',')) == nil)
 					break;
@@ -53,8 +53,8 @@
 
 	g = gs->g;
 	for(n = 0; n < gs->ng; n++, g++){
-		for(k = 0; k < g->nmemb; k++)
-			findgroup(gs, g->memb[k].name, &g->memb[k].id);
+		for(k = 0, memb = g->memb; k < g->nmemb; k++, memb++)
+			findgroup(gs, memb->name, &memb->id);
 	}
 
 	return 0;
@@ -120,7 +120,7 @@
 	if(g->id == id)
 		return 1;
 
-	for(i = 0, g = g->memb; i < g->nmemb; i++, g++){
+	for(i = g->nmemb, g = g->memb; i > 0; i--, g++){
 		if(g->id == id)
 			return 1;
 	}