diff options
author | tadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-11-22 11:32:52 +0000 |
---|---|---|
committer | tadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-11-22 11:32:52 +0000 |
commit | d6ec400148f58061118917fb5ed3977425244f0d (patch) | |
tree | 62794c204ed06c50021f43c50d05ed74f14b35c0 | |
parent | 84a57715e1b20e4d06f90139687d8131705ffc18 (diff) | |
download | ruby-d6ec400148f58061118917fb5ed3977425244f0d.tar.gz |
* complex.c (string_to_c_strict, string_to_c): check NUL.
* rational.c (string_to_r_strict, string_to_r): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37804 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | complex.c | 24 | ||||
-rw-r--r-- | rational.c | 24 |
3 files changed, 47 insertions, 6 deletions
@@ -1,3 +1,8 @@ +Thu Nov 22 20:32:07 2012 Tadayoshi Funaba <tadf@dotrb.org> + + * complex.c (string_to_c_strict, string_to_c): check NUL. + * rational.c (string_to_r_strict, string_to_r): ditto. + Thu Nov 22 20:21:45 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com> * Makefile.in (.dmyh.h): removed $(VPATH). GNU make don't @@ -1776,16 +1776,25 @@ parse_comp(const char *s, int strict, static VALUE string_to_c_strict(VALUE self) { - const char *s; + char *s; VALUE num; rb_must_asciicompat(self); s = RSTRING_PTR(self); - if (memchr(s, 0, RSTRING_LEN(self))) + if (!s || memchr(s, '\0', RSTRING_LEN(self))) rb_raise(rb_eArgError, "string contains null byte"); + if (s && s[RSTRING_LEN(self)]) { + rb_str_modify(self); + s = RSTRING_PTR(self); + s[RSTRING_LEN(self)] = '\0'; + } + + if (!s) + s = (char *)""; + if (!parse_comp(s, 1, &num)) { VALUE ins = f_inspect(self); rb_raise(rb_eArgError, "invalid value for convert(): %s", @@ -1819,13 +1828,22 @@ string_to_c_strict(VALUE self) static VALUE string_to_c(VALUE self) { - const char *s; + char *s; VALUE num; rb_must_asciicompat(self); s = RSTRING_PTR(self); + if (s && s[RSTRING_LEN(self)]) { + rb_str_modify(self); + s = RSTRING_PTR(self); + s[RSTRING_LEN(self)] = '\0'; + } + + if (!s) + s = (char *)""; + (void)parse_comp(s, 0, &num); return num; diff --git a/rational.c b/rational.c index b72f85119a..855b187b1d 100644 --- a/rational.c +++ b/rational.c @@ -2143,16 +2143,25 @@ parse_rat(const char *s, int strict, static VALUE string_to_r_strict(VALUE self) { - const char *s; + char *s; VALUE num; rb_must_asciicompat(self); s = RSTRING_PTR(self); - if (memchr(s, 0, RSTRING_LEN(self))) + if (!s || memchr(s, '\0', RSTRING_LEN(self))) rb_raise(rb_eArgError, "string contains null byte"); + if (s && s[RSTRING_LEN(self)]) { + rb_str_modify(self); + s = RSTRING_PTR(self); + s[RSTRING_LEN(self)] = '\0'; + } + + if (!s) + s = (char *)""; + if (!parse_rat(s, 1, &num)) { VALUE ins = f_inspect(self); rb_raise(rb_eArgError, "invalid value for convert(): %s", @@ -2188,13 +2197,22 @@ string_to_r_strict(VALUE self) static VALUE string_to_r(VALUE self) { - const char *s; + char *s; VALUE num; rb_must_asciicompat(self); s = RSTRING_PTR(self); + if (s && s[RSTRING_LEN(self)]) { + rb_str_modify(self); + s = RSTRING_PTR(self); + s[RSTRING_LEN(self)] = '\0'; + } + + if (!s) + s = (char *)""; + (void)parse_rat(s, 0, &num); if (RB_TYPE_P(num, T_FLOAT)) |