From: Alexey Izbyshev <izbyshev@ispras.ru>
To: musl@lists.openwall.com
Subject: Re: [musl] [PATCH] mq_notify: fix close/recv race on failure path
Date: Sun, 12 Feb 2023 21:23:21 +0300 [thread overview]
Message-ID: <0ca8c83af81250f74b609513409669b4@ispras.ru> (raw)
In-Reply-To: <20230212003158.GO4163@brightrain.aerifal.cx>
On 2023-02-12 03:32, Rich Felker wrote:
diff --git a/src/mq/mq_notify.c b/src/mq/mq_notify.c
index a42888d2..8eac71ed 100644
--- a/src/mq/mq_notify.c
+++ b/src/mq/mq_notify.c
@@ -10,6 +10,8 @@
struct args {
sem_t sem;
int sock;
+ mqd_t mqd;
+ int err;
const struct sigevent *sev;
};
@@ -21,8 +23,21 @@ static void *start(void *p)
int s = args->sock;
void (*func)(union sigval) = args->sev->sigev_notify_function;
union sigval val = args->sev->sigev_value;
+ struct sigevent sev2;
+ static const char zeros[32];
+ int err = 0;
+ sev2.sigev_notify = SIGEV_THREAD;
+ sev2.sigev_signo = s;
+ sev2.sigev_value.sival_ptr = (void *)&zeros;
+
+ err = 0;
This assignment is redundant.
Maybe this hunk could be simplified by getting rid of err and simply
doing "args->err = -__syscall(SYS_mq_notify, args->mqd, &sev2)".
Except for this nit, the patches look good to me, thanks!
Alexey
+ if (syscall(SYS_mq_notify, args->mqd, &sev2) < 0)
+ err = errno;
+ args->err = err;
sem_post(&args->sem);
+ if (err) return 0;
+
n = recv(s, buf, sizeof(buf), MSG_NOSIGNAL|MSG_WAITALL);
close(s);
if (n==sizeof buf && buf[sizeof buf - 1] == 1)
next prev parent reply other threads:[~2023-02-12 18:23 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-09 10:46 Alexey Izbyshev
2022-12-14 2:26 ` Rich Felker
2022-12-14 6:49 ` Alexey Izbyshev
2023-02-10 16:29 ` Rich Felker
2023-02-11 14:45 ` Alexey Izbyshev
2023-02-11 14:52 ` Rich Felker
2023-02-11 15:13 ` Alexey Izbyshev
2023-02-11 15:06 ` Rich Felker
2023-02-11 17:13 ` Markus Wichmann
2023-02-11 17:46 ` Rich Felker
2023-02-11 17:50 ` Alexey Izbyshev
2023-02-11 17:59 ` Rich Felker
2023-02-11 18:08 ` Alexey Izbyshev
2023-02-11 18:35 ` Rich Felker
2023-02-11 19:28 ` Alexey Izbyshev
2023-02-11 19:49 ` Rich Felker
2023-02-11 20:14 ` Alexey Izbyshev
2023-02-12 0:32 ` Rich Felker
2023-02-12 18:23 ` Alexey Izbyshev [this message]
2023-02-12 19:35 ` Alexey Izbyshev
2023-02-12 20:04 ` Rich Felker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0ca8c83af81250f74b609513409669b4@ispras.ru \
--to=izbyshev@ispras.ru \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).