diff options
author | Karel Zak | 2011-11-16 13:30:05 +0100 |
---|---|---|
committer | Karel Zak | 2011-11-16 13:30:05 +0100 |
commit | 8b6e4503882a3ffe8c7b2b47c58f41d364b09ef4 (patch) | |
tree | 8f4b1c4550216775183ad33ce35e137c539a6458 /sys-utils/prlimit.c | |
parent | prlimit: avoid segfault due to array-out-of-bounds error (diff) | |
download | kernel-qcow2-util-linux-8b6e4503882a3ffe8c7b2b47c58f41d364b09ef4.tar.gz kernel-qcow2-util-linux-8b6e4503882a3ffe8c7b2b47c58f41d364b09ef4.tar.xz kernel-qcow2-util-linux-8b6e4503882a3ffe8c7b2b47c58f41d364b09ef4.zip |
prlimit: don't share pointer for old and new in prlimit(2)
This patch makes the code more robust. We should not share the same
pointer for old and new arguments for prlimit(2) syscall.
Reported-by: Bernhard Voelker <mail@bernhard-voelker.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/prlimit.c')
-rw-r--r-- | sys-utils/prlimit.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/sys-utils/prlimit.c b/sys-utils/prlimit.c index a99cc1e31..bcbfb5a8f 100644 --- a/sys-utils/prlimit.c +++ b/sys-utils/prlimit.c @@ -328,7 +328,7 @@ static void do_prlimit(struct list_head *lims) struct list_head *p, *pnext; list_for_each_safe(p, pnext, lims) { - struct rlimit *new = NULL; + struct rlimit *new = NULL, *old = NULL; struct prlimit *lim = list_entry(p, struct prlimit, lims); if (lim->modify) { @@ -341,7 +341,8 @@ static void do_prlimit(struct list_head *lims) errx(EXIT_FAILURE, _("the soft limit %s cannot exceed the hard limit"), lim->desc->name); new = &lim->rlim; - } + } else + old = &lim->rlim; if (verbose && new) { printf(_("New %s limit: "), lim->desc->name); @@ -356,7 +357,7 @@ static void do_prlimit(struct list_head *lims) printf(":%ju>\n", new->rlim_max); } - if (prlimit(pid, lim->desc->resource, new, &lim->rlim) == -1) + if (prlimit(pid, lim->desc->resource, new, old) == -1) err(EXIT_FAILURE, lim->modify ? _("failed to set the %s resource limit") : _("failed to get the %s resource limit"), |