]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
prlimit: don't share pointer for old and new in prlimit(2)
authorKarel Zak <kzak@redhat.com>
Wed, 16 Nov 2011 12:30:05 +0000 (13:30 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 16 Nov 2011 12:30:05 +0000 (13:30 +0100)
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>
sys-utils/prlimit.c

index a99cc1e314010ac4a7f2af4676cb28c3c13f2676..bcbfb5a8f7ea2f054cdc56f958e9c4b3e1dfd38b 100644 (file)
@@ -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"),