Hello,

On Thu, 1 Oct 2026 00:56:12 Samuel Thibault wrote:

> > diff --git a/proc/mgt.c b/proc/mgt.c
> > index 05af823f..9ac7fa3e 100644
> > --- a/proc/mgt.c
> > +++ b/proc/mgt.c
> > @@ -221,6 +221,14 @@ S_proc_child (struct proc *parentp,
> >    if (childp->p_parentset)
> >      return EBUSY;
> >
> > +  char *exe_path = NULL;
> > +  if (parentp->exe)
> > +    {
> > +      exe_path = strdup (parentp->exe);
>
> Better only strdup if !childp->exe

It seemed to me that the childp->exe field might change somewhere else in
the code before the if (!childp->exe && parentp->exe) check.  If that is
not the case, then perhaps it would be best to simply move the
if (! childp->exe && parentp->exe) check and the
childp->exe = strdup (parentp->exe) assignment to a point before
mach_port_deallocate.

Thanks,

--
Mikhail Karpov
From dc9fe77ede2a15d2eaef6fbe0c3b40fb9d61fc41 Mon Sep 17 00:00:00 2001
From: Mikhail Karpov <[email protected]>
Date: Thu, 1 Oct 2026 06:30:07 +0700
Subject: [PATCH] Fixing strdup in proc/mgt.c patch

---
 proc/mgt.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/proc/mgt.c b/proc/mgt.c
index 05af823f..73790c8b 100644
--- a/proc/mgt.c
+++ b/proc/mgt.c
@@ -221,6 +221,13 @@ S_proc_child (struct proc *parentp,
   if (childp->p_parentset)
     return EBUSY;
 
+  if (!childp->exe && parentp->exe)
+    {
+      childp->exe = strdup (parentp->exe);
+      if (!childp->exe)
+        return errno;
+    }
+
   mach_port_deallocate (mach_task_self (), childt);
 
   /* Process identification.
@@ -273,8 +280,6 @@ S_proc_child (struct proc *parentp,
       childp->start_code = parentp->start_code;
       childp->end_code = parentp->end_code;
     }
-  if (! childp->exe && parentp->exe)
-    childp->exe = strdup (parentp->exe);
 
   if (MACH_PORT_VALID (parentp->p_task_namespace))
     {
-- 
2.43.0

Reply via email to