--- misc/plugin/attach/attach.cgi	2013-11-06 05:12:30.689109000 +0900
+++ attach.cgi	2013-12-03 22:21:30.408524979 +0900
@@ -1,4 +1,4 @@
-#!/usr/bin/ruby
+#!/usr/bin/ruby1.9.1
 # $Id: attach.cgi,v 1.20 2008-01-24 15:42:11 znz Exp $
 # Copyright (C) 2003 TAKEUCHI Hitoshi <hitoshi@namaraii.com>
 
@@ -6,10 +6,10 @@
 
 $SAFE     = 1
 
-if FileTest.symlink?( __FILE__ ) then
-  org_path = File.dirname( File.expand_path( File.readlink( __FILE__ ) ) )
+if FileTest.symlink?( __FILE__.untaint ) then
+  org_path = File.dirname( File.expand_path( File.readlink( __FILE__.untaint ) ) )
 else
-  org_path = File.dirname( File.expand_path( __FILE__ ) )
+  org_path = File.dirname( File.expand_path( __FILE__.untaint ) )
 end
 $:.unshift( org_path.untaint, "#{org_path.untaint}/hiki" )
 $:.delete(".") if File.writable?(".")
@@ -26,29 +26,28 @@
   cgi = CGI.new
 
   params     = cgi.params
-  page       = params['p'] ? params['p'].read : 'FrontPage'
-  command = params['command'] ? params['command'].read : 'view'
+  page       = params['p'][0] ? params['p'][0].read : 'FrontPage'
+  command = params['command'][0] ? params['command'][0].read : 'view'
   command = 'view' unless ['view', 'edit'].index(command)
   r = ''
 
   max_size = @conf.options['attach_size'] || 1048576
 
-  if cgi.params['attach']
+  if cgi.params['attach'][0]
     begin
-      raise 'Invalid request.' unless params['p'] && params['attach_file']
-
-      filename   = File.basename(params['attach_file'].original_filename.gsub(/\\/, '/'))
+      raise 'Invalid request.' unless params['p'][0] && params['attach_file'][0]
+      filename   = File.basename(params['attach_file'][0].original_filename.gsub(/\\/, '/'))
       cache_path = "#{@conf.cache_path}/attach"
 
       Dir.mkdir(cache_path) unless test(?e, cache_path.untaint)
       attach_path = "#{cache_path}/#{escape(page)}"
       Dir.mkdir(attach_path) unless test(?e, attach_path.untaint)
       path = "#{attach_path}/#{escape(filename.to_euc)}"
-      if params['attach_file'].size > max_size
+      if params['attach_file'][0].size > max_size
         raise "File size is larger than limit (#{max_size} bytes)."
       end
       unless filename.empty?
-        content = params['attach_file'].read
+        content = params['attach_file'][0].read
         if (!@conf.options['attach.allow_script']) && (/<script\b/i =~ content)
           raise "You cannot attach a file that contains scripts."
         else
@@ -65,14 +64,14 @@
       print cgi.header( 'type' => 'text/plain' )
       puts ex.message
     end
-  elsif cgi.params['detach'] then
+  elsif cgi.params['detach'][0] then
     attach_path = "#{@conf.cache_path}/attach/#{escape(page)}"
 
     begin
       Dir.foreach(attach_path) do |file|
-        next unless params["file_#{file}"]
+        next unless params["file_#{file}"][0]
         path = "#{attach_path}/#{file}"
-        if FileTest.file?(path.untaint) and params["file_#{file}"].read
+        if FileTest.file?(path.untaint) and params["file_#{file}"][0].read
           File.unlink(path)
           r << "FILE        = #{File.basename(path)}\n"
         end
