Ticket #20: charcnv.diff

File charcnv.diff, 1.5 KB (added by guest, 17 years ago)

Check the max len of string more precisely in next_codepoint()

  • lib/charcnv.c

     
    14241424    /* It cannot occupy more than 4 bytes in UTF16 format */
    14251425    uint8_t buf[4];
    14261426    smb_iconv_t descriptor;
     1427    size_t ilen_max;
    14271428    size_t ilen_orig;
    14281429    size_t ilen;
    14291430    size_t olen_orig;
     
    14311432    const char *inbuf;
    14321433    char *outbuf;
    14331434
     1435    *size = 1;
     1436
    14341437    if ((str[0] & 0x80) == 0) {
    1435         *size = 1;
    14361438        return (codepoint_t)str[0];
    14371439    }
    14381440
     
    14401442
    14411443    descriptor = conv_handles[CH_UNIX][CH_UTF16LE];
    14421444    if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) {
    1443         *size = 1;
    14441445        return INVALID_CODEPOINT;
    14451446    }
    14461447
    1447     *size = 1;
     1448    /* We assume that no multi-byte character can take
     1449       more than 5 bytes. This is OK as we only
     1450       support codepoints up to 1M */
     1451
     1452    ilen_max = strnlen( str, 5 );
     1453
    14481454    ilen_orig = 1;
    14491455    olen_orig = 2;
    14501456    while( 1 )
     
    14661472                break;
    14671473
    14681474            case EINVAL :
    1469                 /* We assume that no multi-byte character can take
    1470                    more than 5 bytes. This is OK as we only
    1471                    support codepoints up to 1M */
    1472                 if( ilen_orig < 5 )
     1475                if( ilen_orig < ilen_max )
    14731476                    ilen_orig++;
    14741477                else
    14751478                    return INVALID_CODEPOINT;