VirtualBox

Changeset 66861 in vbox for trunk/src/VBox/Runtime/common


Ignore:
Timestamp:
May 10, 2017 12:56:16 PM (8 years ago)
Author:
vboxsync
Message:

RTGetOptArgvFromString: Fixed incorrect handling of escape sequences inside double quotes in bourne shell mode. Only double quote, backslash, backtick, dollar and newline are valid characters to escape.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/misc/getoptargv.cpp

    r65642 r66861  
    276276         * Parse and copy the string over.
    277277         */
    278         RTUNICP Cp;
     278        RTUNICP uc;
    279279        if ((fFlags & RTGETOPTARGV_CNV_QUOTE_MASK) == RTGETOPTARGV_CNV_QUOTE_BOURNE_SH)
    280280        {
     
    282282             * Bourne shell style.
    283283             */
    284             RTUNICP CpQuote = 0;
     284            RTUNICP ucQuote = 0;
    285285            for (;;)
    286286            {
    287                 rc = RTStrGetCpEx(&pszSrc, &Cp);
    288                 if (RT_FAILURE(rc) || !Cp)
     287                rc = RTStrGetCpEx(&pszSrc, &uc);
     288                if (RT_FAILURE(rc) || !uc)
    289289                    break;
    290                 if (!CpQuote)
    291                 {
    292                     if (Cp == '"' || Cp == '\'')
    293                         CpQuote = Cp;
    294                     else if (rtGetOptIsCpInSet(Cp, pszSeparators, cchSeparators))
     290                if (!ucQuote)
     291                {
     292                    if (uc == '"' || uc == '\'')
     293                        ucQuote = uc;
     294                    else if (rtGetOptIsCpInSet(uc, pszSeparators, cchSeparators))
    295295                        break;
    296                     else if (Cp != '\\')
    297                         pszDst = RTStrPutCp(pszDst, Cp);
     296                    else if (uc != '\\')
     297                        pszDst = RTStrPutCp(pszDst, uc);
    298298                    else
    299299                    {
    300300                        /* escaped char */
    301                         rc = RTStrGetCpEx(&pszSrc, &Cp);
    302                         if (RT_FAILURE(rc) || !Cp)
     301                        rc = RTStrGetCpEx(&pszSrc, &uc);
     302                        if (RT_FAILURE(rc) || !uc)
    303303                            break;
    304                         pszDst = RTStrPutCp(pszDst, Cp);
     304                        pszDst = RTStrPutCp(pszDst, uc);
    305305                    }
    306306                }
    307                 else if (CpQuote != Cp)
    308                 {
    309                     if (Cp != '\\' || CpQuote == '\'')
    310                         pszDst = RTStrPutCp(pszDst, Cp);
     307                else if (ucQuote != uc)
     308                {
     309                    if (uc != '\\' || ucQuote == '\'')
     310                        pszDst = RTStrPutCp(pszDst, uc);
    311311                    else
    312312                    {
    313313                        /* escaped char */
    314                         rc = RTStrGetCpEx(&pszSrc, &Cp);
    315                         if (RT_FAILURE(rc) || !Cp)
     314                        rc = RTStrGetCpEx(&pszSrc, &uc);
     315                        if (RT_FAILURE(rc) || !uc)
    316316                            break;
    317                         pszDst = RTStrPutCp(pszDst, Cp);
     317                        if (   uc != '"'
     318                            && uc != '\\'
     319                            && uc != '`'
     320                            && uc != '$'
     321                            && uc != '\n')
     322                            pszDst = RTStrPutCp(pszDst, ucQuote);
     323                        pszDst = RTStrPutCp(pszDst, uc);
    318324                    }
    319325                }
    320326                else
    321                     CpQuote = 0;
     327                    ucQuote = 0;
    322328            }
    323329        }
     
    331337            for (;;)
    332338            {
    333                 rc = RTStrGetCpEx(&pszSrc, &Cp);
    334                 if (RT_FAILURE(rc) || !Cp)
     339                rc = RTStrGetCpEx(&pszSrc, &uc);
     340                if (RT_FAILURE(rc) || !uc)
    335341                    break;
    336                 if (Cp == '"')
     342                if (uc == '"')
    337343                {
    338344                    /* Two double quotes insides a quoted string in an escape
     
    349355                    }
    350356                }
    351                 else if (!fInQuote && rtGetOptIsCpInSet(Cp, pszSeparators, cchSeparators))
     357                else if (!fInQuote && rtGetOptIsCpInSet(uc, pszSeparators, cchSeparators))
    352358                    break;
    353                 else if (Cp != '\\')
    354                     pszDst = RTStrPutCp(pszDst, Cp);
     359                else if (uc != '\\')
     360                    pszDst = RTStrPutCp(pszDst, uc);
    355361                else
    356362                {
     
    387393
    388394        *pszDst++ = '\0';
    389         if (RT_FAILURE(rc) || !Cp)
     395        if (RT_FAILURE(rc) || !uc)
    390396            break;
    391397    }
Note: See TracChangeset for help on using the changeset viewer.

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