提交 6256b1de 编写于 作者: A Aaron Patterson 提交者: Rafael Mendonça França

Correctly escape PostgreSQL arrays.

Thanks Godfrey Chan for reporting this!

Fixes: CVE-2014-0080
上级 08d0a11a
...@@ -142,12 +142,16 @@ def escape_hstore(value) ...@@ -142,12 +142,16 @@ def escape_hstore(value)
end end
end end
ARRAY_ESCAPE = "\\" * 2 * 2 # escape the backslash twice for PG arrays
def quote_and_escape(value) def quote_and_escape(value)
case value case value
when "NULL" when "NULL"
value value
else else
"\"#{value.gsub(/"/,"\\\"")}\"" value = value.gsub(/\\/, ARRAY_ESCAPE)
value.gsub!(/"/,"\\\"")
"\"#{value}\""
end end
end end
......
...@@ -78,6 +78,14 @@ def teardown ...@@ -78,6 +78,14 @@ def teardown
PostgresqlBitString, PostgresqlOid, PostgresqlTimestampWithZone, PostgresqlUUID].each(&:delete_all) PostgresqlBitString, PostgresqlOid, PostgresqlTimestampWithZone, PostgresqlUUID].each(&:delete_all)
end end
def test_array_escaping
unknown = %(foo\\",bar,baz,\\)
nicknames = ["hello_#{unknown}"]
ar = PostgresqlArray.create!(nicknames: nicknames, id: 100)
ar.reload
assert_equal nicknames, ar.nicknames
end
def test_data_type_of_array_types def test_data_type_of_array_types
assert_equal :integer, @first_array.column_for_attribute(:commission_by_quarter).type assert_equal :integer, @first_array.column_for_attribute(:commission_by_quarter).type
assert_equal :text, @first_array.column_for_attribute(:nicknames).type assert_equal :text, @first_array.column_for_attribute(:nicknames).type
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册