* lib/net/imap.rb: validate data before sending to a server.

[ruby-core:20320]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21998 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
shugo 2009-02-03 05:14:26 +00:00
Родитель bb9435a75c
Коммит 3f59f0e06c
2 изменённых файлов: 60 добавлений и 4 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Tue Feb 3 14:12:10 2009 Shugo Maeda <shugo@ruby-lang.org>
* lib/net/imap.rb: validate data before sending to a server.
[ruby-core:20320]
Tue Feb 3 12:09:08 2009 Shugo Maeda <shugo@ruby-lang.org>
* lib/net/imap.rb (hmac_md5): should use String#ord to get ascii

Просмотреть файл

@ -1062,6 +1062,9 @@ module Net
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 @@ module Net
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 @@ module Net
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 @@ module Net
imap.send(:put_string, @data)
end
def validate
end
private
def initialize(data)
@ -1321,6 +1343,9 @@ module Net
imap.send(:put_string, @data)
end
def validate
end
private
def initialize(data)
@ -1333,6 +1358,9 @@ module Net
imap.send(:send_quoted_string, @data)
end
def validate
end
private
def initialize(data)
@ -1345,6 +1373,9 @@ module Net
imap.send(:send_literal, @data)
end
def validate
end
private
def initialize(data)
@ -1357,6 +1388,10 @@ module Net
imap.send(:put_string, format_internal(@data))
end
def validate
validate_internal(@data)
end
private
def initialize(data)
@ -1368,7 +1403,6 @@ module Net
when "*"
return data
when Integer
ensure_nz_number(data)
if data == -1
return "*"
else
@ -1382,6 +1416,23 @@ module Net
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