ruby-dev (Japanese) list archive (unofficial mirror)
 help / color / mirror / Atom feed
From: nagachika00@gmail•com
To: ruby-dev@ruby-lang.org
Subject: [ruby-dev:50513] [Ruby trunk Bug#13994] Socket.getnameinfo が NUL終端文字列を期待している
Date: Fri, 23 Mar 2018 12:43:04 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-71174.20180323124303.226490b4b93e7c56@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-13994.20171010150622@ruby-lang.org

Issue #13994 has been updated by nagachika (Tomoyuki Chikanaga).

Backport changed from 2.3: REQUIRED, 2.4: REQUIRED to 2.3: REQUIRED, 2.4: DONE

ruby_2_4 r62904 merged revision(s) 60162.

----------------------------------------
Bug #13994: Socket.getnameinfo が NUL終端文字列を期待している
https://bugs.ruby-lang.org/issues/13994#change-71174

* Author: tommy (Masahiro Tomita)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.5.0dev (2017-10-10 trunk 60154) [x86_64-linux]
* Backport: 2.3: REQUIRED, 2.4: DONE
----------------------------------------
Socket.getnameinfo が NUL終端文字列を期待していて、SHARABLE_MIDDLE_SUBSTRING=1 時におかしくなります。

```
% grep abcdefg /etc/hosts /etc/services 
/etc/hosts:192.168.0.99	abcdefghijklmnopqrstuvwxyz.test
/etc/services:abcdefghijklmnopqrstuvwxyz	9999/tcp

% ruby -rsocket -e 'p Socket.getnameinfo(["AF_INET", "abcdefghijklmnopqrstuvwxyz!".chop, "abcdefghijklmnopqrstuvwxyz.test!".chop])'
Traceback (most recent call last):
	1: from -e:1:in `<main>'
-e:1:in `getnameinfo': getaddrinfo: Servname not supported for ai_socktype (SocketError)
```

パッチ適用後は次のようになります。

```
% ruby -rsocket -e 'p Socket.getnameinfo(["AF_INET", "abcdefghijklmnopqrstuvwxyz!".chop, "abcdefghijklmnopqrstuvwxyz.test!".chop])'
["abcdefghijklmnopqrstuvwxyz.test", "abcdefghijklmnopqrstuvwxyz"]
```

パッチ:

```diff
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 14e069bb8d..9eb36def14 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -1287,7 +1287,7 @@ sock_s_getnameinfo(int argc, VALUE *argv)
 	    hptr = NULL;
 	}
 	else {
-	    strncpy(hbuf, StringValuePtr(host), sizeof(hbuf));
+	    strncpy(hbuf, StringValueCStr(host), sizeof(hbuf));
 	    hbuf[sizeof(hbuf) - 1] = '\0';
 	    hptr = hbuf;
 	}
@@ -1301,7 +1301,7 @@ sock_s_getnameinfo(int argc, VALUE *argv)
 	    pptr = pbuf;
 	}
 	else {
-	    strncpy(pbuf, StringValuePtr(port), sizeof(pbuf));
+	    strncpy(pbuf, StringValueCStr(port), sizeof(pbuf));
 	    pbuf[sizeof(pbuf) - 1] = '\0';
 	    pptr = pbuf;
 	}
```




-- 
https://bugs.ruby-lang.org/

  parent reply	other threads:[~2018-03-23 12:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-13994.20171010150622@ruby-lang.org>
2017-10-10 15:06 ` [ruby-dev:50286] [Ruby trunk Bug#13994] Socket.getnameinfo が NUL終端文字列を期待している tommy
2018-03-23 12:43 ` nagachika00 [this message]
2018-03-28  5:59 ` [ruby-dev:50516] " usa

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-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

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

  git send-email \
    --in-reply-to=redmine.journal-71174.20180323124303.226490b4b93e7c56@ruby-lang.org \
    --to=ruby-dev@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).