Project

General

Profile

Bug #13994

Socket.getnameinfo が NUL終端文字列を期待している

Added by tommy (Masahiro Tomita) over 1 year ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.5.0dev (2017-10-10 trunk 60154) [x86_64-linux]
[ruby-dev:50286]

Description

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 --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;
    }

Associated revisions

Revision fb89004a
Added by nobu (Nobuyoshi Nakada) over 1 year ago

socket.c: null byte at Socket.getnameinfo

  • ext/socket/socket.c (sock_s_getnameinfo): check null byte. patched by tommy (Masahiro Tomita) in [ruby-dev:50286]. [Bug #13994]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60162 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 60162
Added by nobu (Nobuyoshi Nakada) over 1 year ago

socket.c: null byte at Socket.getnameinfo

  • ext/socket/socket.c (sock_s_getnameinfo): check null byte. patched by tommy (Masahiro Tomita) in [ruby-dev:50286]. [Bug #13994]

Revision 60162
Added by nobu (Nobuyoshi Nakada) over 1 year ago

socket.c: null byte at Socket.getnameinfo

  • ext/socket/socket.c (sock_s_getnameinfo): check null byte. patched by tommy (Masahiro Tomita) in [ruby-dev:50286]. [Bug #13994]

Revision 60162
Added by nobu (Nobuyoshi Nakada) over 1 year ago

socket.c: null byte at Socket.getnameinfo

  • ext/socket/socket.c (sock_s_getnameinfo): check null byte. patched by tommy (Masahiro Tomita) in [ruby-dev:50286]. [Bug #13994]

Revision 206a7980
Added by nagachika (Tomoyuki Chikanaga) over 1 year ago

merge revision(s) 60162: [Backport #13994]

    socket.c: null byte at Socket.getnameinfo

    * ext/socket/socket.c (sock_s_getnameinfo): check null byte.
      patched by tommy (Masahiro Tomita) in [ruby-dev:50286].
      [Bug #13994]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@62904 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 62904
Added by nagachika (Tomoyuki Chikanaga) over 1 year ago

merge revision(s) 60162: [Backport #13994]

socket.c: null byte at Socket.getnameinfo

* ext/socket/socket.c (sock_s_getnameinfo): check null byte.
  patched by tommy (Masahiro Tomita) in [ruby-dev:50286].
  [Bug #13994]

Revision b63b168c
Added by usa (Usaku NAKAMURA) about 1 year ago

merge revision(s) 60162: [Backport #13994]

    socket.c: null byte at Socket.getnameinfo

    * ext/socket/socket.c (sock_s_getnameinfo): check null byte.
      patched by tommy (Masahiro Tomita) in [ruby-dev:50286].
      [Bug #13994]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@62948 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 62948
Added by usa (Usaku NAKAMURA) about 1 year ago

merge revision(s) 60162: [Backport #13994]

socket.c: null byte at Socket.getnameinfo

* ext/socket/socket.c (sock_s_getnameinfo): check null byte.
  patched by tommy (Masahiro Tomita) in [ruby-dev:50286].
  [Bug #13994]

History

#1

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

  • Status changed from Open to Closed

Applied in changeset trunk|r60162.


socket.c: null byte at Socket.getnameinfo

  • ext/socket/socket.c (sock_s_getnameinfo): check null byte. patched by tommy (Masahiro Tomita) in [ruby-dev:50286]. [Bug #13994]
#2

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

  • Backport changed from 2.3: UNKNOWN, 2.4: UNKNOWN to 2.3: REQUIRED, 2.4: REQUIRED

Updated by nagachika (Tomoyuki Chikanaga) over 1 year ago

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

ruby_2_4 r62904 merged revision(s) 60162.

Updated by usa (Usaku NAKAMURA) about 1 year ago

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

ruby_2_3 r62948 merged revision(s) 60162.

Also available in: Atom PDF