summaryrefslogtreecommitdiffstats
path: root/sys-utils/setpriv.c
diff options
context:
space:
mode:
authorSami Kerola2014-07-13 18:58:36 +0200
committerSami Kerola2014-07-13 19:35:38 +0200
commit7370501f60f1e7cc386c0f7d5b30eab1824cd613 (patch)
treec821cb3d97e55d147e74233c8a963a967bf8d732 /sys-utils/setpriv.c
parentdmesg: avoid unnecessary variable assignment (diff)
downloadkernel-qcow2-util-linux-7370501f60f1e7cc386c0f7d5b30eab1824cd613.tar.gz
kernel-qcow2-util-linux-7370501f60f1e7cc386c0f7d5b30eab1824cd613.tar.xz
kernel-qcow2-util-linux-7370501f60f1e7cc386c0f7d5b30eab1824cd613.zip
setpriv: avoid alloca() use xmalloc() instead
The getgroups() can return up to NGROUPS_MAX supplementary groups, that is (since kernel 2.6.3) 65536 in total. The git_t is 4 bytes, so maximum request is 256 kilobytes. When a system happen to have memory preasure alloca() may not be able to allocate enough memory, making debugging unnecessarily difficult. IMHO 64 pages is significant enough amount of memory to be properly error checked at a time of allocation. Reference: http://www.gnu.org/software/libc/manual/html_node/Disadvantages-of-Alloca.html Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'sys-utils/setpriv.c')
-rw-r--r--sys-utils/setpriv.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/sys-utils/setpriv.c b/sys-utils/setpriv.c
index 65921be18..ccfa99333 100644
--- a/sys-utils/setpriv.c
+++ b/sys-utils/setpriv.c
@@ -254,9 +254,10 @@ static void dump_groups(void)
return;
}
- groups = alloca(n * sizeof(gid_t));
+ groups = xmalloc(n * sizeof(gid_t));
n = getgroups(n, groups);
if (n < 0) {
+ free(groups);
warn("getgroups failed");
return;
}
@@ -273,6 +274,7 @@ static void dump_groups(void)
}
}
printf("\n");
+ free(groups);
}
static void dump(int dumplevel)