[前][次][番号順一覧][スレッド一覧]

ruby-changes:70106

From: Kazuhiro <ko1@a...>
Date: Wed, 8 Dec 2021 13:31:52 +0900 (JST)
Subject: [ruby-changes:70106] af6e088357 (master): Skip bind port 1 when ip_unprivileged_port_start<=1

https://git.ruby-lang.org/ruby.git/commit/?id=af6e088357

From af6e0883570e8c61cef6234040d8689d88db7300 Mon Sep 17 00:00:00 2001
From: Kazuhiro NISHIYAMA <zn@m...>
Date: Wed, 8 Dec 2021 13:26:53 +0900
Subject: Skip bind port 1 when ip_unprivileged_port_start<=1

Linux can allow to bind port 1 to user.
And `ip_unprivileged_port_start` is 0 on [lima](https://github.com/lima-vm/lima) default vm.

```
1)
Socket#bind on SOCK_DGRAM socket raises Errno::EACCES when the current user does not have permission to bind FAILED
Expected Errno::EACCES but no exception was raised (0 was returned)
.../ruby/spec/ruby/library/socket/socket/bind_spec.rb:38:in `block (4 levels) in <top (required)>'
.../ruby/spec/ruby/library/socket/socket/bind_spec.rb:4:in `<top (required)>'

2)
Socket#bind on SOCK_STREAM socket raises Errno::EACCES when the current user does not have permission to bind FAILED
Expected Errno::EACCES but no exception was raised (0 was returned)
.../ruby/spec/ruby/library/socket/socket/bind_spec.rb:79:in `block (4 levels) in <top (required)>'
.../ruby/spec/ruby/library/socket/socket/bind_spec.rb:44:in `<top (required)>'

3)
Socket#bind using IPv4 using a packed socket address raises Errno::EACCES when the user is not allowed to bind to the port FAILED
Expected Errno::EACCES but no exception was raised (0 was returned)
.../ruby/spec/ruby/library/socket/socket/bind_spec.rb:119:in `block (6 levels) in <top (required)>'
.../ruby/spec/ruby/library/socket/socket/bind_spec.rb:85:in `<top (required)>'

4)
Socket#bind using IPv6 using a packed socket address raises Errno::EACCES when the user is not allowed to bind to the port FAILED
Expected Errno::EACCES but no exception was raised (0 was returned)
.../ruby/spec/ruby/library/socket/socket/bind_spec.rb:119:in `block (6 levels) in <top (required)>'
.../ruby/spec/ruby/library/socket/socket/bind_spec.rb:85:in `<top (required)>'
```
---
 spec/ruby/library/socket/socket/bind_spec.rb | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/spec/ruby/library/socket/socket/bind_spec.rb b/spec/ruby/library/socket/socket/bind_spec.rb
index 0349df84a66..4465a3dafac 100644
--- a/spec/ruby/library/socket/socket/bind_spec.rb
+++ b/spec/ruby/library/socket/socket/bind_spec.rb
@@ -33,6 +33,7 @@ describe "Socket#bind on SOCK_DGRAM socket" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/socket/socket/bind_spec.rb#L33
 
   platform_is_not :windows, :cygwin do
     as_user do
+      break if File.read('/proc/sys/net/ipv4/ip_unprivileged_port_start').to_i <= 1 rescue nil
       it "raises Errno::EACCES when the current user does not have permission to bind" do
         sockaddr1 = Socket.pack_sockaddr_in(1, "127.0.0.1")
         -> { @sock.bind(sockaddr1) }.should raise_error(Errno::EACCES)
@@ -74,6 +75,7 @@ describe "Socket#bind on SOCK_STREAM socket" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/socket/socket/bind_spec.rb#L75
 
   platform_is_not :windows, :cygwin do
     as_user do
+      break if File.read('/proc/sys/net/ipv4/ip_unprivileged_port_start').to_i <= 1 rescue nil
       it "raises Errno::EACCES when the current user does not have permission to bind" do
         sockaddr1 = Socket.pack_sockaddr_in(1, "127.0.0.1")
         -> { @sock.bind(sockaddr1) }.should raise_error(Errno::EACCES)
@@ -113,6 +115,8 @@ describe 'Socket#bind' do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/socket/socket/bind_spec.rb#L115
 
       platform_is_not :windows do
         as_user do
+          break if File.read('/proc/sys/net/ipv4/ip_unprivileged_port_start').to_i <= 1 rescue nil
+
           it 'raises Errno::EACCES when the user is not allowed to bind to the port' do
             sockaddr1 = Socket.pack_sockaddr_in(1, ip_address)
 
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]