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

ruby-changes:10927

From: yugui <ko1@a...>
Date: Sun, 22 Feb 2009 13:30:58 +0900 (JST)
Subject: [ruby-changes:10927] Ruby:r22503 (ruby_1_9_1): merges r21998 from trunk into ruby_1_9_1.

yugui	2009-02-22 13:30:46 +0900 (Sun, 22 Feb 2009)

  New Revision: 22503

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=22503

  Log:
    merges r21998 from trunk into ruby_1_9_1.
    * lib/net/imap.rb: validate data before sending to a server.
      [ruby-core:20320]

  Modified files:
    branches/ruby_1_9_1/ChangeLog
    branches/ruby_1_9_1/lib/net/imap.rb

Index: ruby_1_9_1/ChangeLog
===================================================================
--- ruby_1_9_1/ChangeLog	(revision 22502)
+++ ruby_1_9_1/ChangeLog	(revision 22503)
@@ -1,3 +1,8 @@
+Tue Feb  3 14:12:10 2009  Shugo Maeda  <shugo@r...>
+
+	* lib/net/imap.rb: validate data before sending to a server.
+	  [ruby-core:20320]
+
 Tue Feb  3 12:09:08 2009  Shugo Maeda  <shugo@r...>
 
 	* lib/net/imap.rb (hmac_md5): should use String#ord to get ascii
Index: ruby_1_9_1/lib/net/imap.rb
===================================================================
--- ruby_1_9_1/lib/net/imap.rb	(revision 22502)
+++ ruby_1_9_1/lib/net/imap.rb	(revision 22503)
@@ -1062,6 +1062,9 @@
 
     def send_command(cmd, *args, &block)
       synchronize do
+        args.each do |i|
+          validate_data(i)
+        end
         tag = generate_tag
         put_string(tag + " " + cmd)
         args.each do |i|
@@ -1105,6 +1108,25 @@
       end
     end
 
+    def validate_data(data)
+      case data
+      when nil
+      when String
+      when Integer
+        if data < 0 || data >= 4294967296
+          raise DataFormatError, num.to_s
+        end
+      when Array
+        data.each do |i|
+          validate_data(i)
+        end
+      when Time
+      when Symbol
+      else
+        data.validate
+      end
+    end
+
     def send_data(data)
       case data
       when nil
@@ -1151,9 +1173,6 @@
     end
 
     def send_number_data(num)
-      if num < 0 || num >= 4294967296
-        raise DataFormatError, num.to_s
-      end
       put_string(num.to_s)
     end
 
@@ -1309,6 +1328,9 @@
         imap.send(:put_string, @data)
       end
 
+      def validate
+      end
+
       private
 
       def initialize(data)
@@ -1321,6 +1343,9 @@
         imap.send(:put_string, @data)
       end
 
+      def validate
+      end
+
       private
 
       def initialize(data)
@@ -1333,6 +1358,9 @@
         imap.send(:send_quoted_string, @data)
       end
 
+      def validate
+      end
+
       private
 
       def initialize(data)
@@ -1345,6 +1373,9 @@
         imap.send(:send_literal, @data)
       end
 
+      def validate
+      end
+
       private
 
       def initialize(data)
@@ -1357,6 +1388,10 @@
         imap.send(:put_string, format_internal(@data))
       end
 
+      def validate
+        validate_internal(@data)
+      end
+
       private
 
       def initialize(data)
@@ -1368,7 +1403,6 @@
         when "*"
           return data
         when Integer
-          ensure_nz_number(data)
           if data == -1
             return "*"
           else
@@ -1382,6 +1416,23 @@
         when ThreadMember
           return data.seqno.to_s +
             ":" + data.children.collect {|i| format_internal(i).join(",")}
+        end
+      end
+
+      def validate_internal(data)
+        case data
+        when "*"
+        when Integer
+          ensure_nz_number(data)
+        when Range
+        when Array
+          data.each do |i|
+            validate_internal(i)
+          end
+        when ThreadMember
+          data.children.each do |i|
+            validate_internal(i)
+          end
         else
           raise DataFormatError, data.inspect
         end

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

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