[前][次][番号順一覧][スレッド一覧]

ruby-changes:33549

From: nobu <ko1@a...>
Date: Sat, 19 Apr 2014 00:09:54 +0900 (JST)
Subject: [ruby-changes:33549] nobu:r45630 (trunk): time.c: fix non-terminated string

nobu	2014-04-19 00:09:49 +0900 (Sat, 19 Apr 2014)

  New Revision: 45630

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45630

  Log:
    time.c: fix non-terminated string
    
    * time.c (month_arg, time_strftime): RSTRING_PTR() may not be
      NUL-terminated.

  Modified files:
    trunk/time.c
Index: time.c
===================================================================
--- time.c	(revision 45629)
+++ time.c	(revision 45630)
@@ -2585,11 +2585,11 @@ month_arg(VALUE arg) https://github.com/ruby/ruby/blob/trunk/time.c#L2585
     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) https://github.com/ruby/ruby/blob/trunk/time.c#L4569
     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: ; https://github.com/ruby/ruby/blob/trunk/time.c#L4828
     }
     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);
     }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]