diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-04-18 15:09:49 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-04-18 15:09:49 +0000 |
commit | c23a9376ca543d9fe05776cbfb478b8b23cee27f (patch) | |
tree | ef61df25d15ea58c8a9d875cfafa9b3827a9b690 /time.c | |
parent | 5b54488e780490ae367f58286401e6a717c1e4d5 (diff) | |
download | bundler-c23a9376ca543d9fe05776cbfb478b8b23cee27f.tar.gz |
time.c: fix non-terminated string
* time.c (month_arg, time_strftime): RSTRING_PTR() may not be
NUL-terminated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45630 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r-- | time.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -2585,11 +2585,11 @@ month_arg(VALUE arg) int i, mon; VALUE s = rb_check_string_type(arg); - if (!NIL_P(s)) { + if (!NIL_P(s) && RSTRING_LEN(s) > 0) { mon = 0; for (i=0; i<12; i++) { if (RSTRING_LEN(s) == 3 && - STRCASECMP(months[i], RSTRING_PTR(s)) == 0) { + STRNCASECMP(months[i], RSTRING_PTR(s), 3) == 0) { mon = i+1; break; } @@ -4569,7 +4569,7 @@ time_strftime(VALUE time, VALUE format) if (len == 0) { rb_warning("strftime called with empty format string"); } - else if (memchr(fmt, '\0', len)) { + else if (fmt[len] || memchr(fmt, '\0', len)) { /* Ruby string may contain \0's. */ const char *p = fmt, *pe = fmt + len; @@ -4828,7 +4828,7 @@ end_submicro: ; } if (!NIL_P(zone)) { zone = rb_str_new_frozen(zone); - tobj->vtm.zone = RSTRING_PTR(zone); + tobj->vtm.zone = StringValueCStr(zone); rb_ivar_set(time, id_zone, zone); } |