bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 18/41] proc: Fix use-after-realloc


From: Sergey Bugaev
Subject: [PATCH 18/41] proc: Fix use-after-realloc
Date: Tue, 9 May 2023 00:31:13 +0300

---
 proc/info.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/proc/info.c b/proc/info.c
index 12743465..d84fdd45 100644
--- a/proc/info.c
+++ b/proc/info.c
@@ -941,6 +941,8 @@ S_proc_getloginpids (struct proc *callerp,
            if (new - parray > parraysize)
              {
                struct proc **newparray;
+               ptrdiff_t tail_offset = tail - parray;
+               ptrdiff_t new_offset = new - parray;
                newparray = realloc (parray, ((parraysize *= 2)
                                              * sizeof (struct proc *)));
                if (! newparray)
@@ -949,8 +951,8 @@ S_proc_getloginpids (struct proc *callerp,
                    return ENOMEM;
                  }
 
-               tail = newparray + (tail - parray);
-               new = newparray + (new - parray);
+               tail = newparray + tail_offset;
+               new = newparray + new_offset;
                parray = newparray;
              }
            *new++ = p;
-- 
2.40.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]