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:
parent
5b54488e78
commit
c23a9376ca
1 changed files with 4 additions and 4 deletions
8
time.c
8
time.c
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue