From 3711c63b6a2513348a4dc991ec25198244636d2a Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 13 Aug 2009 06:37:39 +0000 Subject: [PATCH] * regenc.c (onigenc_strlen_null, onigenc_str_bytelen_null): fixed infinite loop for wide encodings. reported by Ralf Junker at [ruby-core:24892]. [ruby-core:24904] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24521 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ regenc.c | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index d64bbb7bf5..c3c14b22e2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Thu Aug 13 15:37:33 2009 Nobuyoshi Nakada + + * regenc.c (onigenc_strlen_null, onigenc_str_bytelen_null): fixed + infinite loop for wide encodings. reported by Ralf Junker a + [ruby-core:24892]. [ruby-core:24904] + Wed Aug 12 21:07:46 2009 NAKAMURA Usaku * ext/socket/extconf.rb: if ipv6 is enabled, the version of Windows diff --git a/regenc.c b/regenc.c index bb180367da..065e4d298a 100644 --- a/regenc.c +++ b/regenc.c @@ -136,7 +136,7 @@ onigenc_strlen_null(OnigEncoding enc, const UChar* s) { int n = 0; UChar* p = (UChar* )s; - UChar* e = p + strlen((const char *)s); + UChar* e; while (1) { if (*p == '\0') { @@ -152,6 +152,7 @@ onigenc_strlen_null(OnigEncoding enc, const UChar* s) } if (len == 1) return n; } + e = p + ONIGENC_MBC_MAXLEN(enc); p += ONIGENC_MBC_ENC_LEN(enc, p, e); n++; } @@ -162,7 +163,7 @@ onigenc_str_bytelen_null(OnigEncoding enc, const UChar* s) { UChar* start = (UChar* )s; UChar* p = (UChar* )s; - UChar* e = p + strlen((const char *)s); + UChar* e; while (1) { if (*p == '\0') { @@ -178,6 +179,7 @@ onigenc_str_bytelen_null(OnigEncoding enc, const UChar* s) } if (len == 1) return (int )(p - start); } + e = p + ONIGENC_MBC_MAXLEN(enc); p += ONIGENC_MBC_ENC_LEN(enc, p, e); } }