Skip to content

Commit 3fb7d2c

Browse files
committedNov 24, 2021
Fix integer overflow
Make use of the check in rb_alloc_tmp_buffer2. https://hackerone.com/reports/1328463 When parsing cookies, only decode the values Bump version Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org> Co-authored-by: Yusuke Endoh <mame@ruby-lang.org>
1 parent 02dfd5a commit 3fb7d2c

File tree

5 files changed

+9
-4
lines changed

5 files changed

+9
-4
lines changed
 

‎ext/cgi/escape/escape.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ static VALUE
3636
optimized_escape_html(VALUE str)
3737
{
3838
VALUE vbuf;
39-
char *buf = ALLOCV_N(char, vbuf, RSTRING_LEN(str) * HTML_ESCAPE_MAX_LEN);
39+
typedef char escape_buf[HTML_ESCAPE_MAX_LEN];
40+
char *buf = *ALLOCV_N(escape_buf, vbuf, RSTRING_LEN(str));
4041
const char *cstr = RSTRING_PTR(str);
4142
const char *end = cstr + RSTRING_LEN(str);
4243

‎lib/cgi.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@
288288
#
289289

290290
class CGI
291-
VERSION = "0.2.0"
291+
VERSION = "0.2.1"
292292
end
293293

294294
require 'cgi/core'

‎lib/cgi/cookie.rb

-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ def self.parse(raw_cookie)
159159
raw_cookie.split(/;\s?/).each do |pairs|
160160
name, values = pairs.split('=',2)
161161
next unless name and values
162-
name = CGI.unescape(name)
163162
values ||= ""
164163
values = values.split('&').collect{|v| CGI.unescape(v,@@accept_charset) }
165164
if cookies.has_key?(name)

‎test/cgi/test_cgi_cookie.rb

+5
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ def test_cgi_cookie_parse
101101
end
102102
end
103103

104+
def test_cgi_cookie_parse_not_decode_name
105+
cookie_str = "%66oo=baz;foo=bar"
106+
cookies = CGI::Cookie.parse(cookie_str)
107+
assert_equal({"%66oo" => ["baz"], "foo" => ["bar"]}, cookies)
108+
end
104109

105110
def test_cgi_cookie_arrayinterface
106111
cookie = CGI::Cookie.new('name1', 'a', 'b', 'c')

‎version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
1313
#define RUBY_VERSION_TEENY 3
1414
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
15-
#define RUBY_PATCHLEVEL 156
15+
#define RUBY_PATCHLEVEL 157
1616

1717
#define RUBY_RELEASE_YEAR 2021
1818
#define RUBY_RELEASE_MONTH 11

0 commit comments

Comments
 (0)
Failed to load comments.