From: Karel Zak Date: Wed, 16 Nov 2011 12:30:05 +0000 (+0100) Subject: prlimit: don't share pointer for old and new in prlimit(2) X-Git-Tag: v2.21-rc1~174 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8b6e4503882a3ffe8c7b2b47c58f41d364b09ef4;p=thirdparty%2Futil-linux.git 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 Signed-off-by: Karel Zak --- diff --git a/sys-utils/prlimit.c b/sys-utils/prlimit.c index a99cc1e314..bcbfb5a8f7 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"),