Date: Thu, 21 Jul 2011 17:20:45 +0000 (UTC) From: Gabor Kovesdan <gabor@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r224247 - user/gabor/tre-integration/contrib/tre/lib Message-ID: <201107211720.p6LHKjq8078771@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: gabor Date: Thu Jul 21 17:20:44 2011 New Revision: 224247 URL: http://svn.freebsd.org/changeset/base/224247 Log: - Add some sanity checks for REG_STARTEND offsets - Use btowc() instead of mbrtowc() if input is not in a multibyte charset Modified: user/gabor/tre-integration/contrib/tre/lib/fastmatch.c user/gabor/tre-integration/contrib/tre/lib/regexec.c Modified: user/gabor/tre-integration/contrib/tre/lib/fastmatch.c ============================================================================== --- user/gabor/tre-integration/contrib/tre/lib/fastmatch.c Thu Jul 21 16:32:13 2011 (r224246) +++ user/gabor/tre-integration/contrib/tre/lib/fastmatch.c Thu Jul 21 17:20:44 2011 (r224247) @@ -333,6 +333,10 @@ tre_fastexec(const fastmatch_t *fg, cons switch (type) { case STR_BYTE: + ch = startptr; + wc = btowc(ch[0]); + r = hashtable_get(fg->qsBc, &wc, &k); + break; case STR_MBS: ch = startptr; mbrtowc(&wc, ch, MB_CUR_MAX, NULL); @@ -379,6 +383,10 @@ tre_fastexec(const fastmatch_t *fg, cons switch (type) { case STR_BYTE: + ch = startptr; + wc = btowc(ch[0]); + r = hashtable_get(fg->qsBc, &wc, &k); + break; case STR_MBS: ch = startptr; mbrtowc(&wc, ch, MB_CUR_MAX, NULL); Modified: user/gabor/tre-integration/contrib/tre/lib/regexec.c ============================================================================== --- user/gabor/tre-integration/contrib/tre/lib/regexec.c Thu Jul 21 16:32:13 2011 (r224246) +++ user/gabor/tre-integration/contrib/tre/lib/regexec.c Thu Jul 21 17:20:44 2011 (r224247) @@ -225,10 +225,13 @@ tre_regnexec(const regex_t *preg, const if (eflags & REG_STARTEND) { + if ((len != (unsigned)-1) && (pmatch[0].rm_eo > len)) + return REG_NOMATCH; + if ((long long)pmatch[0].rm_eo - pmatch[0].rm_so < 0) + return REG_NOMATCH; size_t slen = (size_t)(pmatch[0].rm_eo - pmatch[0].rm_so); size_t offset = pmatch[0].rm_so; - str = &str[offset]; - int ret = tre_match(tnfa, str, slen, type, nmatch, pmatch, eflags, + int ret = tre_match(tnfa, &str[offset], slen, type, nmatch, pmatch, eflags, preg->shortcut); pmatch[0].rm_so += offset; pmatch[0].rm_eo += offset; @@ -267,10 +270,13 @@ tre_regwnexec(const regex_t *preg, const if (eflags & REG_STARTEND) { + if ((len != (unsigned)-1) && (pmatch[0].rm_eo > len)) + return REG_NOMATCH; + if ((long long)pmatch[0].rm_eo - pmatch[0].rm_so < 0) + return REG_NOMATCH; size_t slen = (size_t)(pmatch[0].rm_eo - pmatch[0].rm_so); size_t offset = pmatch[0].rm_so; - str = &str[offset]; - int ret = tre_match(tnfa, str, slen, STR_WIDE, nmatch, pmatch, eflags, + int ret = tre_match(tnfa, &str[offset], slen, STR_WIDE, nmatch, pmatch, eflags, preg->shortcut); pmatch[0].rm_so += offset; pmatch[0].rm_eo += offset;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201107211720.p6LHKjq8078771>