Skip to content
Browse files

bin/*: enforce -p/--port argument to be a valid integer

Users may confuse '-p' with the (to-be-deprecated) '-P/--pid'
option, leading to surprising behavior if a pathname is passed as a
port, because String#to_i would convert it to zero, causing:

    TCPServer.new(host, port = 0)

to bind to a random, unused port.
  • Loading branch information...
1 parent 7e9e4c7 commit d5870ccc714a4bb442a46aedd4c68c547e8e56f4 Eric Wong committed with Eric Wong
Showing with 6 additions and 6 deletions.
  1. +3 −3 bin/unicorn
  2. +3 −3 bin/unicorn_rails
View
6 bin/unicorn
@@ -47,9 +47,9 @@ op = OptionParser.new("", 24, ' ') do |opts|
rackup_opts[:set_listener] = true
end
- opts.on("-p", "--port PORT",
- "use PORT (default: #{Unicorn::Const::DEFAULT_PORT})") do |p|
- rackup_opts[:port] = p.to_i
+ opts.on("-p", "--port PORT", Integer,
+ "use PORT (default: #{Unicorn::Const::DEFAULT_PORT})") do |port|
+ rackup_opts[:port] = port
rackup_opts[:set_listener] = true
end
View
6 bin/unicorn_rails
@@ -48,9 +48,9 @@ op = OptionParser.new("", 24, ' ') do |opts|
rackup_opts[:set_listener] = true
end
- opts.on("-p", "--port PORT",
- "use PORT (default: #{Unicorn::Const::DEFAULT_PORT})") do |p|
- rackup_opts[:port] = p.to_i
+ opts.on("-p", "--port PORT", Integer,
+ "use PORT (default: #{Unicorn::Const::DEFAULT_PORT})") do |port|
+ rackup_opts[:port] = port
rackup_opts[:set_listener] = true
end

0 comments on commit d5870cc

Please sign in to comment.
Something went wrong with that request. Please try again.