Skip to contentSkip to conversation

xfsprogs: fix potential memory free issues in quota_group_type()

PATCH In review Li Zhong 2 participants 2 messages Sep 22, 2013 – Sep 24, 2013

lore
Share & tools
lore

Li Zhong

author
#0 lore raw

PATCH 1/1 xfsprogs: fix potential memory free issues in quota_group_type()

This patch tries to fix CID 997009 reported by Coverity scan, as suggested by sekharan

If getgroups() fails, gids might be malloced, and overwritten with &gid. So the free() at the end of the function is trying to free a variable on the stack, while the pointer to the allocated memory is lost.

---
 quota/quota.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
quota/quota.c +2 -1
index 7e52ad2..ae9b156 100644
@@ -292,7 +292,8 @@ quota_group_type(
 	} else if ( ((ngroups = sysconf(_SC_NGROUPS_MAX)) < 0) ||
 		    ((gids = malloc(ngroups * sizeof(gid_t))) == NULL) ||
 		    ((ngroups = getgroups(ngroups, gids)) < 0)) {
-		dofree = (gids != NULL);
+		if (gids)
+			free(gids);
 		gid = getgid();
 		gids = &gid;
 		ngroups = 1;
Signature · 8 lines
1.8.1.4



_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Li Zhong

This patch tries to fix CID 997009 reported by Coverity scan, as suggested by sekharan

If getgroups() fails, gids might be malloced, and overwritten with &gid. So the free() at the end of the function is trying to free a variable on the stack, while the pointer to the allocated memory is lost.

---

Looks good to me.

And it seems that dofree would always be true in the following else statement.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs