diff options
author | duerst <duerst@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-06-02 01:24:52 +0000 |
---|---|---|
committer | duerst <duerst@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-06-02 01:24:52 +0000 |
commit | 3dd98b2446271f8ad2837bc4b63c459c131c579f (patch) | |
tree | afcc1e9b300fbe31a1b078c067ea5b85f01b2382 /string.c | |
parent | 2fe605911ce3b6677b160afac90b554ba69e6bf1 (diff) | |
download | ruby-3dd98b2446271f8ad2837bc4b63c459c131c579f.tar.gz |
* string.c: Raise ArgumentError when invalid string is detected in
case mapping methods.
* enc/unicode.c: Check for invalid string and signal with negative
length value.
* test/ruby/enc/test_case_mapping.rb: Add tests for above.
* test/ruby/test_m17n_comb.rb: Add a message to clarify test failure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55253 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 26 |
1 files changed, 19 insertions, 7 deletions
@@ -5785,6 +5785,7 @@ rb_str_casemap(VALUE source, OnigCaseFoldType *flags, rb_encoding *enc) mapping_buffer pre_buffer, /* only next pointer used */ *current_buffer = &pre_buffer; int buffer_count = 0; + int buffer_length_or_invalid; if (RSTRING_LEN(source) == 0) return rb_str_dup(source); @@ -5799,12 +5800,23 @@ rb_str_casemap(VALUE source, OnigCaseFoldType *flags, rb_encoding *enc) current_buffer = current_buffer->next; current_buffer->next = NULL; current_buffer->capa = capa; - target_length += current_buffer->used - = onigenc_unicode_case_map(flags, - (const OnigUChar**)&source_current, source_end, - current_buffer->space, - current_buffer->space+current_buffer->capa, - enc); + buffer_length_or_invalid = onigenc_unicode_case_map(flags, + (const OnigUChar**)&source_current, source_end, + current_buffer->space, + current_buffer->space+current_buffer->capa, + enc); + if (buffer_length_or_invalid < 0) { + mapping_buffer *previous_buffer; + + current_buffer = pre_buffer.next; + while (current_buffer) { + previous_buffer = current_buffer; + current_buffer = current_buffer->next; + xfree(previous_buffer); + } + rb_raise(rb_eArgError, "input string invalid"); + } + target_length += current_buffer->used = buffer_length_or_invalid; } /* fprintf(stderr, "Buffer count is %d\n", buffer_count); *//* for tuning */ @@ -5819,7 +5831,7 @@ rb_str_casemap(VALUE source, OnigCaseFoldType *flags, rb_encoding *enc) memcpy(target_current, current_buffer->space, current_buffer->used); target_current += current_buffer->used; previous_buffer = current_buffer; - current_buffer=current_buffer->next; + current_buffer = current_buffer->next; xfree(previous_buffer); } } |