develooper Front page | perl.perl5.porters | Postings from July 2011

Re: Broken API for is_utf8_char()

Thread Previous | Thread Next
From:
Karl Williamson
Date:
July 2, 2011 21:16
Subject:
Re: Broken API for is_utf8_char()
Message ID:
4E0FED12.7060105@khwilliamson.com
For those of you who didn't read all the way to the end, Eric's code 
does not solve the problem, because the input isn't necessarily null 
terminated.  Therefore, I still think the API needs to change to prevent 
possible crashes and security breaches.

  On 06/29/2011 04:53 PM, Eric Brine wrote:
> On Wed, Jun 29, 2011 at 6:02 PM, Karl Williamson
> <public@khwilliamson.com <mailto:public@khwilliamson.com>> wrote:
>
>     It has no way of knowing how big the buffer is.  I propose changing
>     the public interface to pass the buffer size.
>
>
>     The function is not called in cpan
>
>
> I'd suggest changing
>
> STRLEN
> Perl_is_utf8_char(const U8 *s)
> {
>      const STRLEN len = UTF8SKIP(s);
>
>      PERL_ARGS_ASSERT_IS_UTF8_CHAR;
> #ifdef IS_UTF8_CHAR
>      if (IS_UTF8_CHAR_FAST(len))
>          return IS_UTF8_CHAR(s, len) ? len : 0;
> #endif /* #ifdef IS_UTF8_CHAR */
>      return is_utf8_char_slow(s, len);
> }
>
> into
>
> STRLEN
> Perl_is_utf8_char(const U8 *s)
> {
>      PERL_ARGS_ASSERT_IS_UTF8_CHAR;
>      return Perl_is_utf8_charn(s, strlen((const char*)s));
> }
>
> STRLEN
> Perl_is_utf8_charn(const U8 *s, STRLEN len)
> {
>      PERL_ARGS_ASSERT_IS_UTF8_CHARN;
> #ifdef IS_UTF8_CHAR
>      if (IS_UTF8_CHAR_FAST(len))
>          return IS_UTF8_CHAR(s, len) ? len : 0;
> #endif /* #ifdef IS_UTF8_CHAR */
>      return is_utf8_char_slow(s, len);
> }
>
> except that C<< s >> is not guaranteed to be NUL-terminated.
>


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About