VirtualBox

Changeset 40091 in vbox


Ignore:
Timestamp:
Feb 13, 2012 10:14:00 AM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
76231
Message:

Runtime/strings: add Utf-8 and Utf-16 sanitising to a white list of characters. Do not validate the string encoding in advance.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/string.h

    r40071 r40091  
    711711 *
    712712 * @returns The number of code points replaced, or a negative value if the
    713  *          string is not correctly encoded.  In this case the string will not
    714  *          be changed.
     713 *          string is not correctly encoded.  In this last case the string
     714 *          may be partially processed.
    715715 * @param   psz            The string to sanitise.
    716716 * @param   puszValidSet   A zero-terminated array of the Unicode code points
     
    33253325 *
    33263326 * @returns The number of code points replaced, or a negative value if the
    3327  *          string is not correctly encoded.  In this case the string will not
    3328  *          be changed.
     3327 *          string is not correctly encoded.  In this last case the string
     3328 *          may be partially processed.
    33293329 * @param   pwsz           The string to sanitise.
    33303330 * @param   puszValidSet   A zero-terminated array of the Unicode code points
  • trunk/src/VBox/Runtime/common/string/utf-16.cpp

    r40073 r40091  
    255255    AssertReturn(chReplacement && (unsigned)chReplacement < 128, -1);
    256256    /* Validate the encoding. */
    257     if (RT_FAILURE(RTUtf16CalcUtf8LenEx(pwsz, RTSTR_MAX, NULL)))
    258         return -1;
    259257    for (;;)
    260258    {
     
    262260        PCRTUNICP pCp;
    263261        PRTUTF16 pwszOld = pwsz;
    264         RTUtf16GetCpEx((PCRTUTF16 *)&pwsz, &Cp);
     262        if (RT_FAILURE(RTUtf16GetCpEx((PCRTUTF16 *)&pwsz, &Cp)))
     263            return -1;
    265264        if (!Cp)
    266265            break;
  • trunk/src/VBox/Runtime/common/string/utf-8.cpp

    r40073 r40091  
    356356    size_t cReplacements = 0;
    357357    AssertReturn(chReplacement && (unsigned)chReplacement < 128, -1);
    358     if (RT_FAILURE(RTStrValidateEncoding(psz)))
    359         return -1;
    360358    for (;;)
    361359    {
     
    363361        PCRTUNICP pCp;
    364362        char *pszOld = psz;
    365         RTStrGetCpEx((const char **)&psz, &Cp);
     363        if (RT_FAILURE(RTStrGetCpEx((const char **)&psz, &Cp)))
     364            return -1;
    366365        if (!Cp)
    367366            break;
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette