VirtualBox

Changeset 5966 in vbox


Ignore:
Timestamp:
Dec 5, 2007 4:10:11 PM (17 years ago)
Author:
vboxsync
Message:

Escape problematic chars in the description.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/STAM.cpp

    r5275 r5966  
    877877
    878878    if (pThis->fWithDesc && pDesc->pszDesc)
    879         return stamR3SnapshotPrintf(pThis, " desc=\"%s\"/>\n", pDesc->pszDesc);
     879    {
     880        /*
     881         * The description is a bit tricky as it may include chars that
     882         * xml requires to be escaped.
     883         */
     884        const char *pszBadChar = strpbrk(pDesc->pszDesc, "&<>\"'");
     885        if (!pszBadChar)
     886            return stamR3SnapshotPrintf(pThis, " desc=\"%s\"/>\n", pDesc->pszDesc);
     887
     888        stamR3SnapshotPrintf(pThis, " desc=\"");
     889        const char *pszCur = pDesc->pszDesc;
     890        do
     891        {
     892            stamR3SnapshotPrintf(pThis, "%.*s", pszBadChar - pszCur, pszCur);
     893            switch (*pszBadChar)
     894            {
     895                case '&':   stamR3SnapshotPrintf(pThis, "&amp;");   break;
     896                case '<':   stamR3SnapshotPrintf(pThis, "&lt;");    break;
     897                case '>':   stamR3SnapshotPrintf(pThis, "&gt;");    break;
     898                case '"':   stamR3SnapshotPrintf(pThis, "&quot;");  break;
     899                case '\'':  stamR3SnapshotPrintf(pThis, "&apos;");  break;
     900                default:    AssertMsgFailed(("%c", *pszBadChar));    break;
     901            }
     902            pszCur = pszBadChar + 1;
     903            pszBadChar = strpbrk(pszCur, "&<>\"'");
     904        } while (pszBadChar);
     905        return stamR3SnapshotPrintf(pThis, "%s\"/>\n", pszCur);
     906    }
    880907    return stamR3SnapshotPrintf(pThis, "/>\n");
    881908}
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