posix_mq RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: ruby.posix.mq@librelist.com
Subject: [PATCH] for_fd: delay assigning to mq->des until after mq_getattr
Date: Fri,  9 Jan 2015 07:35:18 +0000	[thread overview]
Message-ID: <1420788918-23775-1-git-send-email-normalperson@yhbt.net> (raw)
In-Reply-To: <1420788918-23775-1-git-send-email-normalperson@yhbt.net>

We do not want to assign to mq->des before verifying we
have a valid message queue, otherwise the GC may misclose
an invalid MQ descriptor (which may be a valid FD).
---
 ext/posix_mq/posix_mq.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/ext/posix_mq/posix_mq.c b/ext/posix_mq/posix_mq.c
index 5e8122e..93e3913 100644
--- a/ext/posix_mq/posix_mq.c
+++ b/ext/posix_mq/posix_mq.c
@@ -384,13 +384,15 @@ static VALUE for_fd(VALUE klass, VALUE socket)
 {
 	VALUE mqv = alloc(klass);
 	struct posix_mq *mq = get(mqv, 0);
+	mqd_t mqd;
 
 	mq->name = Qnil;
-	mq->des = FD_TO_MQD(NUM2INT(socket));
+	mqd = FD_TO_MQD(NUM2INT(socket));
 
-	if (mq_getattr(mq->des, &mq->attr) < 0)
+	if (mq_getattr(mqd, &mq->attr) < 0)
 		rb_sys_fail("provided file descriptor is not a POSIX MQ");
 
+	mq->des = mqd;
 	return mqv;
 }
 #endif /* FD_TO_MQD */
-- 
EW



           reply	other threads:[~2015-01-09  7:35 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <1420788918-23775-1-git-send-email-normalperson@yhbt.net>]

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

  List information: https://yhbt.net/ruby_posix_mq/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1420788918-23775-1-git-send-email-normalperson@yhbt.net \
    --to=normalperson@yhbt.net \
    --cc=ruby.posix.mq@librelist.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://yhbt.net/ruby_posix_mq.git/

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 read-only IMAP folder(s) and NNTP newsgroup(s).