]> git.ipfire.org Git - thirdparty/util-linux.git/commit - sys-utils/setpriv.c
setpriv: avoid alloca() use xmalloc() instead
authorSami Kerola <kerolasa@iki.fi>
Sun, 13 Jul 2014 16:58:36 +0000 (17:58 +0100)
committerSami Kerola <kerolasa@iki.fi>
Sun, 13 Jul 2014 17:35:38 +0000 (18:35 +0100)
commit7370501f60f1e7cc386c0f7d5b30eab1824cd613
treec821cb3d97e55d147e74233c8a963a967bf8d732
parentd9bdd89db1ae0e35d31adf0a21ed9c8e5badf0cf
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>
sys-utils/setpriv.c