aboutsummaryrefslogtreecommitdiff
path: root/proc
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@gmail.com>2023-05-09 00:31:13 +0300
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2023-05-10 02:32:51 +0200
commit11892f0282aa3431051b1d8996f68d9f7895f818 (patch)
treec01ae635956a5e18ad55cd8277764ce88b8238b7 /proc
parent1932ab1888ff445092d124217f68948e2866d3d7 (diff)
downloadhurd-11892f0282aa3431051b1d8996f68d9f7895f818.tar.gz
hurd-11892f0282aa3431051b1d8996f68d9f7895f818.tar.bz2
hurd-11892f0282aa3431051b1d8996f68d9f7895f818.zip
proc: Fix use-after-realloc
Message-Id: <20230508213136.608575-19-bugaevc@gmail.com>
Diffstat (limited to 'proc')
-rw-r--r--proc/info.c6
1 files 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;