From d5870ccc714a4bb442a46aedd4c68c547e8e56f4 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 1 Nov 2013 20:02:47 +0000 Subject: [PATCH] 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. --- bin/unicorn | 6 +++--- bin/unicorn_rails | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/unicorn b/bin/unicorn index 01984f8f..c272e43a 100755 --- a/bin/unicorn +++ b/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 diff --git a/bin/unicorn_rails b/bin/unicorn_rails index 4bd599f3..b080846d 100755 --- a/bin/unicorn_rails +++ b/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 -- 2.11.4.GIT