Skip to content

Commit 03022c9

Browse files
committed
merge revision(s) 30903:
* test/ruby/test_exception.rb (TestException::test_to_s_taintness_propagation): Test for below. * error.c (exc_to_s): untainted strings can be tainted via Exception#to_s, which enables attackers to overwrite sane strings. Reported by: Yusuke Endoh <mame at tsg.ne.jp>. * error.c (name_err_to_s): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@30911 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 4f4dc7b commit 03022c9

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

ChangeLog

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
Fri Feb 18 21:18:55 2011 Shugo Maeda <shugo@ruby-lang.org>
2+
3+
* test/ruby/test_exception.rb (TestException::test_to_s_taintness_propagation):
4+
Test for below.
5+
6+
Fri Feb 18 21:18:55 2011 URABE Shyouhei <shyouhei@ruby-lang.org>
7+
8+
* error.c (exc_to_s): untainted strings can be tainted via
9+
Exception#to_s, which enables attackers to overwrite sane strings.
10+
Reported by: Yusuke Endoh <mame at tsg.ne.jp>.
11+
12+
* error.c (name_err_to_s): ditto.
13+
114
Fri Feb 18 21:17:22 2011 Shugo Maeda <shugo@ruby-lang.org>
215

316
* lib/fileutils.rb (FileUtils::remove_entry_secure): there is a

error.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,6 @@ exc_to_s(exc)
403403
VALUE mesg = rb_attr_get(exc, rb_intern("mesg"));
404404

405405
if (NIL_P(mesg)) return rb_class_name(CLASS_OF(exc));
406-
if (OBJ_TAINTED(exc)) OBJ_TAINT(mesg);
407406
return mesg;
408407
}
409408

@@ -667,10 +666,9 @@ name_err_to_s(exc)
667666
if (NIL_P(mesg)) return rb_class_name(CLASS_OF(exc));
668667
StringValue(str);
669668
if (str != mesg) {
670-
rb_iv_set(exc, "mesg", mesg = str);
669+
OBJ_INFECT(str, mesg);
671670
}
672-
if (OBJ_TAINTED(exc)) OBJ_TAINT(mesg);
673-
return mesg;
671+
return str;
674672
}
675673

676674
/*

test/ruby/test_exception.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,26 @@ def test_else
184184
assert(false)
185185
end
186186
end
187+
188+
def test_to_s_taintness_propagation
189+
for exc in [Exception, NameError]
190+
m = "abcdefg"
191+
e = exc.new(m)
192+
e.taint
193+
s = e.to_s
194+
assert_equal(false, m.tainted?,
195+
"#{exc}#to_s should not propagate taintness")
196+
assert_equal(false, s.tainted?,
197+
"#{exc}#to_s should not propagate taintness")
198+
end
199+
200+
o = Object.new
201+
def o.to_str
202+
"foo"
203+
end
204+
o.taint
205+
e = NameError.new(o)
206+
s = e.to_s
207+
assert_equal(true, s.tainted?)
208+
end
187209
end

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define RUBY_RELEASE_DATE "2011-02-18"
33
#define RUBY_VERSION_CODE 187
44
#define RUBY_RELEASE_CODE 20110218
5-
#define RUBY_PATCHLEVEL 333
5+
#define RUBY_PATCHLEVEL 334
66

77
#define RUBY_VERSION_MAJOR 1
88
#define RUBY_VERSION_MINOR 8

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy