From e46a61775933d1ce9207fde4422ad536fed4846a Mon Sep 17 00:00:00 2001 From: matz Date: Fri, 30 Nov 2007 10:42:40 +0000 Subject: [PATCH] * ext/syck/rubyext.c (rb_syck_mktime): avoid segmentation fault. [ruby-core:13735] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14050 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ bootstraptest/test_knownbug.rb | 1 + ext/syck/rubyext.c | 8 ++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index c00973c8e6..2bc83c59c8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Nov 30 19:33:38 2007 Yukihiro Matsumoto + + * ext/syck/rubyext.c (rb_syck_mktime): avoid segmentation fault. + [ruby-core:13735] + Fri Nov 30 19:05:55 2007 Yukihiro Matsumoto * enum.c (enum_count): precise argument number check. diff --git a/bootstraptest/test_knownbug.rb b/bootstraptest/test_knownbug.rb index 0cf5cf271b..947a944225 100644 --- a/bootstraptest/test_knownbug.rb +++ b/bootstraptest/test_knownbug.rb @@ -3,6 +3,7 @@ # So all tests will cause failure. # +$:.unshift File.join(File.dirname(__FILE__), "../.ext/#{RUBY_PLATFORM}") assert_normal_exit %q{ STDERR.reopen(STDOUT) require 'yaml' diff --git a/ext/syck/rubyext.c b/ext/syck/rubyext.c index 8e01bc176d..4ee1a30bee 100644 --- a/ext/syck/rubyext.c +++ b/ext/syck/rubyext.c @@ -262,9 +262,13 @@ rb_syck_mktime(char *str, long len) { char padded[] = "000000"; char *end = ptr + 1; + char *p = end; while ( isdigit( *end ) ) end++; - MEMCPY(padded, ptr + 1, char, end - (ptr + 1)); - usec = strtol(padded, NULL, 10); + if (end - p < sizeof(padded)) { + MEMCPY(padded, ptr + 1, char, end - (ptr + 1)); + p = padded; + } + usec = strtol(p, NULL, 10); } else {