VirtualBox

Changeset 90821 in vbox for trunk/src


Ignore:
Timestamp:
Aug 23, 2021 10:04:06 PM (3 years ago)
Author:
vboxsync
Message:

IPRT: More VALID_PTR -> RT_VALID_PTR with some bad-printf-pointer details thrown in.

Location:
trunk/src/VBox/Runtime
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/string/strformat.cpp

    r90779 r90821  
    4949 * Deals with bad pointers.
    5050 */
    51 static size_t rtStrFormatBadPointer(size_t cch, PFNRTSTROUTPUT pfnOutput, void *pvArgOutput, int cchWidth,
    52                                     unsigned fFlags, void const *pvStr, char szTmp[64], const char *pszTag, int cchTag)
     51DECLHIDDEN(size_t) rtStrFormatBadPointer(size_t cch, PFNRTSTROUTPUT pfnOutput, void *pvArgOutput, int cchWidth,
     52                                         unsigned fFlags, void const *pvStr, char szTmp[64], const char *pszTag, int cchTag)
    5353{
    5454    static char const s_szNull[] = "<NULL>";
  • trunk/src/VBox/Runtime/common/string/strformatrt.cpp

    r88200 r90821  
    356356#undef STRMEM
    357357                };
    358                 static const char s_szNull[] = "<NULL>";
    359358
    360359                const char *pszType = *ppszFormat - 1;
     
    572571
    573572                    case RTSF_IPV6:
    574                     {
    575                         if (VALID_PTR(u.pIpv6Addr))
     573                        if (RT_VALID_PTR(u.pIpv6Addr))
    576574                            return rtstrFormatIPv6(pfnOutput, pvArgOutput, u.pIpv6Addr);
    577                         return pfnOutput(pvArgOutput, s_szNull, sizeof(s_szNull) - 1);
    578                     }
     575                        return rtStrFormatBadPointer(0, pfnOutput, pvArgOutput, cchWidth, fFlags, u.pIpv6Addr,
     576                                                     szBuf, RT_STR_TUPLE("!BadIPv6"));
    579577
    580578                    case RTSF_MAC:
    581                     {
    582                         if (VALID_PTR(u.pMac))
     579                        if (RT_VALID_PTR(u.pMac))
    583580                            return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0,
    584581                                               "%02x:%02x:%02x:%02x:%02x:%02x",
     
    589586                                               u.pMac->au8[4],
    590587                                               u.pMac->au8[5]);
    591                         return pfnOutput(pvArgOutput, s_szNull, sizeof(s_szNull) - 1);
    592                     }
     588                        return rtStrFormatBadPointer(0, pfnOutput, pvArgOutput, cchWidth, fFlags, u.pMac,
     589                                                     szBuf, RT_STR_TUPLE("!BadMac"));
    593590
    594591                    case RTSF_NETADDR:
    595                     {
    596                         if (VALID_PTR(u.pNetAddr))
     592                        if (RT_VALID_PTR(u.pNetAddr))
    597593                        {
    598594                            switch (u.pNetAddr->enmType)
     
    639635                            }
    640636                        }
    641                         return pfnOutput(pvArgOutput, s_szNull, sizeof(s_szNull) - 1);
    642                     }
     637                        return rtStrFormatBadPointer(0, pfnOutput, pvArgOutput, cchWidth, fFlags, u.pNetAddr,
     638                                                     szBuf, RT_STR_TUPLE("!BadNetAddr"));
    643639
    644640                    case RTSF_UUID:
    645                     {
    646                         if (VALID_PTR(u.pUuid))
    647                         {
     641                        if (RT_VALID_PTR(u.pUuid))
    648642                            /* cannot call RTUuidToStr because of GC/R0. */
    649643                            return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0,
     
    660654                                               u.pUuid->Gen.au8Node[4],
    661655                                               u.pUuid->Gen.au8Node[5]);
    662                         }
    663                         return pfnOutput(pvArgOutput, s_szNull, sizeof(s_szNull) - 1);
    664                     }
     656                        return rtStrFormatBadPointer(0, pfnOutput, pvArgOutput, cchWidth, fFlags, u.pUuid,
     657                                                     szBuf, RT_STR_TUPLE("!BadUuid"));
    665658
    666659                    case RTSF_ERRINFO:
    667660                    case RTSF_ERRINFO_MSG_ONLY:
    668                     {
    669                         if (VALID_PTR(u.pErrInfo) && RTErrInfoIsSet(u.pErrInfo))
     661                        if (RT_VALID_PTR(u.pErrInfo) && RTErrInfoIsSet(u.pErrInfo))
    670662                        {
    671663                            cch = 0;
     
    690682                        }
    691683                        return 0;
    692                     }
    693684
    694685                    default:
     
    717708                        const char *pszLastSep;
    718709                        const char *psz = pszLastSep = va_arg(*pArgs, const char *);
    719                         if (!VALID_PTR(psz))
    720                             return pfnOutput(pvArgOutput, RT_STR_TUPLE("<null>"));
     710                        if (!RT_VALID_PTR(psz))
     711                            return rtStrFormatBadPointer(0, pfnOutput, pvArgOutput, cchWidth, fFlags, psz,
     712                                                         szBuf, RT_STR_TUPLE("!BadBaseName"));
    721713
    722714                        while ((ch = *psz) != '\0')
     
    813805                        int cAngle = 0;
    814806
    815                         if (!VALID_PTR(psz))
    816                             return pfnOutput(pvArgOutput, RT_STR_TUPLE("<null>"));
     807                        if (!RT_VALID_PTR(psz))
     808                            return rtStrFormatBadPointer(0, pfnOutput, pvArgOutput, cchWidth, fFlags, psz,
     809                                                         szBuf, RT_STR_TUPLE("!BadFnNm"));
    817810
    818811                        while ((ch = *psz) != '\0' && ch != '(')
     
    13431336                 * If it's a pointer, we'll check if it's valid before going on.
    13441337                 */
    1345                 if ((s_aTypes[i].fFlags & RTST_FLAGS_POINTER) && !VALID_PTR(u.pv))
    1346                     return pfnOutput(pvArgOutput, RT_STR_TUPLE("<null>"));
     1338                if ((s_aTypes[i].fFlags & RTST_FLAGS_POINTER) && !RT_VALID_PTR(u.pv))
     1339                    return rtStrFormatBadPointer(0, pfnOutput, pvArgOutput, cchWidth, fFlags, u.pv,
     1340                                                 szBuf, RT_STR_TUPLE("!BadRD"));
    13471341
    13481342                /*
     
    13891383                            ssize_t     offLast;
    13901384
    1391                             if (!VALID_PTR(pszStr))
     1385                            if (!RT_VALID_PTR(pszStr))
    13921386                                pszStr = "<NULL>";
    13931387                            cchStr = RTStrNLen(pszStr, (unsigned)cchPrecision);
     
    14511445                            ssize_t     offLast;
    14521446
    1453                             if (!VALID_PTR(pszStr))
     1447                            if (!RT_VALID_PTR(pszStr))
    14541448                                pszStr = "<NULL>";
    14551449                            cchStr = RTStrNLen(pszStr, (unsigned)cchPrecision);
     
    15331527                                   ("Invalid IPRT format type '%.10s'!\n", pszFormatOrg));
    15341528
    1535                     if (!VALID_PTR(pszStr))
     1529                    if (!RT_VALID_PTR(pszStr))
    15361530                        pszStr = "<NULL>";
    15371531                    cchStr = RTStrNLen(pszStr, (unsigned)cchPrecision);
  • trunk/src/VBox/Runtime/include/internal/string.h

    r82968 r90821  
    5151#endif
    5252
     53DECLHIDDEN(size_t) rtStrFormatBadPointer(size_t cch, PFNRTSTROUTPUT pfnOutput, void *pvArgOutput, int cchWidth,
     54                                         unsigned fFlags, void const *pvStr, char szTmp[64], const char *pszTag, int cchTag);
    5355DECLHIDDEN(size_t) rtstrFormatRt(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput, const char **ppszFormat, va_list *pArgs,
    5456                                 int cchWidth, int cchPrecision, unsigned fFlags, char chArgSize);
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