Subject: Re: bug#36279: 26.2.90; (process-attributes nonexistent-pid) segmentation fault

From: Robert Pluim <[email-masked]>
Date: Tue, 18 Jun 2019 19:53:06 +0200

>>>>> On Tue, 18 Jun 2019 20:44:41 +0300, Eli Zaretskii <[email-masked]> said:

    >> Date: Wed, 19 Jun 2019 00:23:20 +0800
    >> From: xuchunyang <[email-masked]>
    >> Cc: [email-masked], Noam Postavsky <[email-masked]>
    >> 
    >> It fixes the issue for me too. (process-attributes 123456) returns nil instead of crashing Emacs.
    >> 
    >> > 
    >> > diff --git a/src/sysdep.c b/src/sysdep.c
    >> > index 1e35e06b63..518ecebcf6 100644
    >> > --- a/src/sysdep.c
    >> > +++ b/src/sysdep.c
    >> > @@ -3798,7 +3798,7 @@ system_process_attributes (Lisp_Object pid)
    >> >    CONS_TO_INTEGER (pid, int, proc_id);
    >> >    mib[3] = proc_id;
    >> >  
    >> > -  if (sysctl (mib, 4, &proc, &proclen, NULL, 0) != 0)
    >> > +  if (sysctl (mib, 4, &proc, &proclen, NULL, 0) != 0 || proclen == 0)
    >> >      return attrs;
    >> >  
    >> >    uid = proc.kp_eproc.e_ucred.cr_uid;
    >> >

    Eli> Thanks.  Robert, please push to the emacs-26 branch.

Will do.

    Eli> (I understand this problem is quite old, is that right?)

commit ef4ed84e72a323b3d29dc34df92d3f89ad4fc322
Date:   Sun Apr 24 14:33:05 2016 +0200

introduced the macOS version of system_process_attributes.

list_system_processes (on macOS and FreeBSD) and
system_process_attributes(on FreeBSD) potentially have similar issues
with sysctl. Would you like a defensive patch for those? (I donʼt have
a FreeBSD system to test on)

Robert