xfsprogs: fix potential memory free issues in quota_group_type()
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
@@ -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
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 thefree()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<[email protected]>---
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