dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH 5/6] webrick/httpservlet/*handler: use File.open
Date: Thu, 21 Dec 2017 11:55:06 +0000	[thread overview]
Message-ID: <20171221115507.27500-6-e@80x24.org> (raw)
In-Reply-To: <20171221115507.27500-1-e@80x24.org>

This makes future code audits easier.  None of these changes
fix realistic remote code execution vulnerabilities because
we stat(2) before attempting Kernel#open.

* lib/webrick/httpservlet/erbhandler.rb (do_GET): use File.open
* lib/webrick/httpservlet/filehandler.rb (do_GET): use File.open
  (make_partial_content): ditto
---
 lib/webrick/httpservlet/erbhandler.rb  | 2 +-
 lib/webrick/httpservlet/filehandler.rb | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/webrick/httpservlet/erbhandler.rb b/lib/webrick/httpservlet/erbhandler.rb
index 9bcec69883..aa02ce8a1d 100644
--- a/lib/webrick/httpservlet/erbhandler.rb
+++ b/lib/webrick/httpservlet/erbhandler.rb
@@ -53,7 +53,7 @@ def do_GET(req, res)
           raise HTTPStatus::Forbidden, "ERBHandler cannot work."
         end
         begin
-          data = open(@script_filename){|io| io.read }
+          data = File.open(@script_filename, &:read)
           res.body = evaluate(ERB.new(data), req, res)
           res['content-type'] ||=
             HTTPUtils::mime_type(@script_filename, @config[:MimeTypes])
diff --git a/lib/webrick/httpservlet/filehandler.rb b/lib/webrick/httpservlet/filehandler.rb
index 3ea1eec7d0..2c02d0ffe7 100644
--- a/lib/webrick/httpservlet/filehandler.rb
+++ b/lib/webrick/httpservlet/filehandler.rb
@@ -57,7 +57,7 @@ def do_GET(req, res)
           res['content-type'] = mtype
           res['content-length'] = st.size
           res['last-modified'] = mtime.httpdate
-          res.body = open(@local_path, "rb")
+          res.body = File.open(@local_path, "rb")
         end
       end
 
@@ -92,7 +92,7 @@ def make_partial_content(req, res, filename, filesize)
           raise HTTPStatus::BadRequest,
             "Unrecognized range-spec: \"#{req['range']}\""
         end
-        open(filename, "rb"){|io|
+        File.open(filename, "rb"){|io|
           if ranges.size > 1
             time = Time.now
             boundary = "#{time.sec}_#{time.usec}_#{Process::pid}"
-- 
EW


  parent reply	other threads:[~2017-12-21 11:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-21 11:55 [PATCH 0/6] webrick: audit and fix Kernel#open misuse Eric Wong
2017-12-21 11:55 ` [PATCH 1/6] webrick: httpauth requires regular files Eric Wong
2017-12-21 11:55 ` [PATCH 2/6] webrick/httpservlet/cgi_runner.rb: remove unnecessary open Eric Wong
2017-12-21 11:55 ` [PATCH 3/6] webrick: add test for WEBrick::HTTPServlet::ERBHandler Eric Wong
2017-12-21 11:55 ` [PATCH 4/6] webrick: WEBrick::Log requires path arg when given string Eric Wong
2017-12-21 11:55 ` Eric Wong [this message]
2017-12-21 11:55 ` [PATCH 6/6] webrick/httputils: note Kernel#open behavior Eric Wong

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

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

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

  git send-email \
    --in-reply-to=20171221115507.27500-6-e@80x24.org \
    --to=e@80x24.org \
    --cc=spew@80x24.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
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).