From 8db6b70ab6a64ea9b0ac313f2816131a046fbd76 Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Wed, 26 May 2021 17:42:07 +0300 Subject: libports: Treat no-senders notifications as a hint No-senders notifications are directed to the port that no longer has any senders left. Since any client can easily spoof such a notification, we have to treat the notification as just a hint and verify whether there are, in fact, any senders, and only call ports_no_senders () if there actually are none left. --- libports/notify-no-senders.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'libports') diff --git a/libports/notify-no-senders.c b/libports/notify-no-senders.c index 55aa853f..cf0b386a 100644 --- a/libports/notify-no-senders.c +++ b/libports/notify-no-senders.c @@ -1,8 +1,9 @@ /* No sender notification - Copyright (C) 1995 Free Software Foundation, Inc. + Copyright (C) 1995, 2021 Free Software Foundation, Inc. - Written by Miles Bader + Written by Miles Bader , + and Sergey Bugaev . This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -23,10 +24,24 @@ error_t ports_do_mach_notify_no_senders (struct port_info *pi, - mach_port_mscount_t count) + mach_port_mscount_t count) { + error_t err; + mach_port_status_t stat; + if (!pi) return EOPNOTSUPP; - ports_no_senders (pi, count); + + /* Treat the notification as a hint, since it might not be coming from the + kernel. We now check if there are indeed no more senders left. */ + err = mach_port_get_receive_status (mach_task_self (), + pi->port_right, &stat); + if (err) + return err; + + if (stat.mps_srights) + return EAGAIN; + + ports_no_senders (pi, stat.mps_mscount); return 0; } -- cgit v1.2.3