From 8b6e4503882a3ffe8c7b2b47c58f41d364b09ef4 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 16 Nov 2011 13:30:05 +0100 Subject: [PATCH] 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 --- sys-utils/prlimit.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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"), -- 2.47.3