* [PATCH] xfsprogs: fix potential memory free issues in quota_group_type()
@ 2013-09-22 6:45 Li Zhong
2013-09-24 18:33 ` Mark Tinguely
0 siblings, 1 reply; 2+ messages in thread
From: Li Zhong @ 2013-09-22 6:45 UTC (permalink / raw)
To: xfsprogs; +Cc: Chandra Seetharaman
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.
Signed-off-by: Li Zhong <zhong@linux.vnet.ibm.com>
---
quota/quota.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/quota/quota.c b/quota/quota.c
index 7e52ad2..ae9b156 100644
--- a/quota/quota.c
+++ b/quota/quota.c
@@ -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;
--
1.8.1.4
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] xfsprogs: fix potential memory free issues in quota_group_type()
2013-09-22 6:45 [PATCH] xfsprogs: fix potential memory free issues in quota_group_type() Li Zhong
@ 2013-09-24 18:33 ` Mark Tinguely
0 siblings, 0 replies; 2+ messages in thread
From: Mark Tinguely @ 2013-09-24 18:33 UTC (permalink / raw)
To: Li Zhong; +Cc: Chandra Seetharaman, xfsprogs
On 09/22/13 01:45, Li Zhong wrote:
> 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.
>
> Signed-off-by: Li Zhong<zhong@linux.vnet.ibm.com>
> ---
Looks good to me.
And it seems that dofree would always be true in the following else
statement.
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-09-24 18:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-22 6:45 [PATCH] xfsprogs: fix potential memory free issues in quota_group_type() Li Zhong
2013-09-24 18:33 ` Mark Tinguely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox