1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2014-04-18 15:09:49 +00:00
parent 5b54488e78
commit c23a9376ca

8
time.c
View file

@ -2585,11 +2585,11 @@ month_arg(VALUE arg)
int i, mon; int i, mon;
VALUE s = rb_check_string_type(arg); VALUE s = rb_check_string_type(arg);
if (!NIL_P(s)) { if (!NIL_P(s) && RSTRING_LEN(s) > 0) {
mon = 0; mon = 0;
for (i=0; i<12; i++) { for (i=0; i<12; i++) {
if (RSTRING_LEN(s) == 3 && if (RSTRING_LEN(s) == 3 &&
STRCASECMP(months[i], RSTRING_PTR(s)) == 0) { STRNCASECMP(months[i], RSTRING_PTR(s), 3) == 0) {
mon = i+1; mon = i+1;
break; break;
} }
@ -4569,7 +4569,7 @@ time_strftime(VALUE time, VALUE format)
if (len == 0) { if (len == 0) {
rb_warning("strftime called with empty format string"); 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. */ /* Ruby string may contain \0's. */
const char *p = fmt, *pe = fmt + len; const char *p = fmt, *pe = fmt + len;
@ -4828,7 +4828,7 @@ end_submicro: ;
} }
if (!NIL_P(zone)) { if (!NIL_P(zone)) {
zone = rb_str_new_frozen(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); rb_ivar_set(time, id_zone, zone);
} }