aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRobert Pluim2019-06-19 08:52:50 +0200
committerRobert Pluim2019-06-20 10:42:21 +0200
commit04477adedcee0d023dabc46a652f1673a2e9bd95 (patch)
treec9b6e47ff3b16ac1f2076fd1d0d41ebe5e594198 /src
parent81535eeadb5b9b964dd195b2720de2b1fc432c6e (diff)
downloademacs-04477adedcee0d023dabc46a652f1673a2e9bd95.tar.gz
emacs-04477adedcee0d023dabc46a652f1673a2e9bd95.zip
Check that length of data returned by sysctl is non-zero
The length of the data returned by sysctl can be zero, which was not checked for. This could cause crashes, e.g. when querying non-existent processes. (Bug#36279) * src/sysdep.c (list_system_processes) [DARWIN_OS || __FreeBSD__]: (system_process_attributes) [__FreeBSD__]: (system_process_attributes) [DARWIN_OS]: * src/filelock.c (get_boot_time) [CTL_KERN && KERN_BOOTTIME]: Check for zero length data returned by sysctl.
Diffstat (limited to 'src')
-rw-r--r--src/filelock.c2
-rw-r--r--src/sysdep.c10
2 files changed, 6 insertions, 6 deletions
diff --git a/src/filelock.c b/src/filelock.c
index 81d98f36fa4..bcd5bff563d 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -152,7 +152,7 @@ get_boot_time (void)
152 mib[1] = KERN_BOOTTIME; 152 mib[1] = KERN_BOOTTIME;
153 size = sizeof (boottime_val); 153 size = sizeof (boottime_val);
154 154
155 if (sysctl (mib, 2, &boottime_val, &size, NULL, 0) >= 0) 155 if (sysctl (mib, 2, &boottime_val, &size, NULL, 0) >= 0 && size != 0)
156 { 156 {
157 boot_time = boottime_val.tv_sec; 157 boot_time = boottime_val.tv_sec;
158 return boot_time; 158 return boot_time;
diff --git a/src/sysdep.c b/src/sysdep.c
index 1e35e06b633..b2aecc0ddac 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -3014,11 +3014,11 @@ list_system_processes (void)
3014 3014
3015 Lisp_Object proclist = Qnil; 3015 Lisp_Object proclist = Qnil;
3016 3016
3017 if (sysctl (mib, 3, NULL, &len, NULL, 0) != 0) 3017 if (sysctl (mib, 3, NULL, &len, NULL, 0) != 0 || len == 0)
3018 return proclist; 3018 return proclist;
3019 3019
3020 procs = xmalloc (len); 3020 procs = xmalloc (len);
3021 if (sysctl (mib, 3, procs, &len, NULL, 0) != 0) 3021 if (sysctl (mib, 3, procs, &len, NULL, 0) != 0 || len == 0)
3022 { 3022 {
3023 xfree (procs); 3023 xfree (procs);
3024 return proclist; 3024 return proclist;
@@ -3618,7 +3618,7 @@ system_process_attributes (Lisp_Object pid)
3618 CONS_TO_INTEGER (pid, int, proc_id); 3618 CONS_TO_INTEGER (pid, int, proc_id);
3619 mib[3] = proc_id; 3619 mib[3] = proc_id;
3620 3620
3621 if (sysctl (mib, 4, &proc, &proclen, NULL, 0) != 0) 3621 if (sysctl (mib, 4, &proc, &proclen, NULL, 0) != 0 || proclen == 0)
3622 return attrs; 3622 return attrs;
3623 3623
3624 attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (proc.ki_uid)), attrs); 3624 attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (proc.ki_uid)), attrs);
@@ -3740,7 +3740,7 @@ system_process_attributes (Lisp_Object pid)
3740 3740
3741 mib[2] = KERN_PROC_ARGS; 3741 mib[2] = KERN_PROC_ARGS;
3742 len = MAXPATHLEN; 3742 len = MAXPATHLEN;
3743 if (sysctl (mib, 4, args, &len, NULL, 0) == 0) 3743 if (sysctl (mib, 4, args, &len, NULL, 0) == 0 && len != 0)
3744 { 3744 {
3745 int i; 3745 int i;
3746 for (i = 0; i < len; i++) 3746 for (i = 0; i < len; i++)
@@ -3798,7 +3798,7 @@ system_process_attributes (Lisp_Object pid)
3798 CONS_TO_INTEGER (pid, int, proc_id); 3798 CONS_TO_INTEGER (pid, int, proc_id);
3799 mib[3] = proc_id; 3799 mib[3] = proc_id;
3800 3800
3801 if (sysctl (mib, 4, &proc, &proclen, NULL, 0) != 0) 3801 if (sysctl (mib, 4, &proc, &proclen, NULL, 0) != 0 || proclen == 0)
3802 return attrs; 3802 return attrs;
3803 3803
3804 uid = proc.kp_eproc.e_ucred.cr_uid; 3804 uid = proc.kp_eproc.e_ucred.cr_uid;