VirtualBox

Changeset 84632 in vbox for trunk/src/VBox/Runtime/r3/linux


Ignore:
Timestamp:
Jun 2, 2020 11:07:28 AM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
138378
Message:

IPRT/sysfs.cpp: Use RTStrPrintf2V rather than RTStrPrintfV in rtLinuxConstructPathV so we can more easily check for buffer overruns.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/linux/sysfs.cpp

    r82968 r84632  
    6666 */
    6767static int rtLinuxConstructPathV(char *pszBuf, size_t cchBuf,
    68                                      const char *pszPrefix,
    69                                      const char *pszFormat, va_list va)
    70 {
    71     size_t cchPrefix = strlen(pszPrefix);
     68                                 const char *pszPrefix,
     69                                 const char *pszFormat, va_list va)
     70{
     71    size_t const cchPrefix = strlen(pszPrefix);
    7272    AssertReturn(pszPrefix[cchPrefix - 1] == '/', VERR_INVALID_PARAMETER);
    7373    AssertReturn(cchBuf > cchPrefix + 1, VERR_INVALID_PARAMETER);
    7474
    75     /** @todo While RTStrPrintfV prevents overflows, it doesn't make it easy to
    76      *        check for truncations. RTPath should provide some formatters and
    77      *        joiners which can take over this rather common task that is
    78      *        performed here. */
    79     size_t cch = RTStrPrintfV(pszBuf, cchBuf, pszFormat, va);
     75    ssize_t cch = RTStrPrintf2V(pszBuf, cchBuf, pszFormat, va);
     76    AssertReturn(cch > 0, VERR_BUFFER_OVERFLOW);
     77
    8078    if (*pszBuf != '/')
    8179    {
    82         AssertReturn(cchBuf >= cch + cchPrefix + 1, VERR_BUFFER_OVERFLOW);
    83         memmove(pszBuf + cchPrefix, pszBuf, cch + 1);
     80        AssertReturn(cchBuf >= (size_t)cch + cchPrefix + 1, VERR_BUFFER_OVERFLOW);
     81        memmove(pszBuf + cchPrefix, pszBuf, (size_t)cch + 1);
    8482        memcpy(pszBuf, pszPrefix, cchPrefix);
    85         cch += cchPrefix;
    8683    }
    8784    return VINF_SUCCESS;
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