VirtualBox

Changeset 103439 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Feb 19, 2024 1:43:33 PM (11 months ago)
Author:
vboxsync
Message:

IPRT/xml.cpp: Simplified the XmlFileWriter::write() path handling. bugref:3409

File:
1 edited

Legend:

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

    r103285 r103439  
    23062306
    23072307        /* Construct both filenames first to ease error handling.  */
     2308        size_t const cchFilename = strlen(pcszFilename);
     2309        size_t const cchTmpSuff  = strlen(s_pszTmpSuff);
     2310        size_t const cchPrevSuff = strlen(s_pszPrevSuff);
     2311        AssertStmt(cchFilename + RT_MAX(cchTmpSuff, cchPrevSuff) < RTPATH_MAX,
     2312                   throw EIPRTFailure(VERR_BUFFER_OVERFLOW, "filename to long (%zu)", cchFilename));
     2313
    23082314        char szTmpFilename[RTPATH_MAX];
    2309         int rc = RTStrCopy(szTmpFilename, sizeof(szTmpFilename) - strlen(s_pszTmpSuff), pcszFilename);
    2310         if (RT_FAILURE(rc))
    2311             throw EIPRTFailure(rc, "RTStrCopy");
    2312         rc = RTStrCat(szTmpFilename, sizeof(szTmpFilename), s_pszTmpSuff);
    2313         if (RT_FAILURE(rc))
    2314             throw EIPRTFailure(rc, "RTStrCat");
     2315        memcpy(mempcpy(szTmpFilename, pcszFilename, cchFilename), s_pszTmpSuff, cchTmpSuff + 1);
    23152316
    23162317        char szPrevFilename[RTPATH_MAX];
    2317         rc = RTStrCopy(szPrevFilename, sizeof(szPrevFilename) - strlen(s_pszPrevSuff), pcszFilename);
    2318         if (RT_FAILURE(rc))
    2319             throw EIPRTFailure(rc, "RTStrCopy");
    2320         strcat(szPrevFilename, s_pszPrevSuff);
     2318        memcpy(mempcpy(szPrevFilename, pcszFilename, cchFilename), s_pszPrevSuff, cchPrevSuff + 1);
    23212319
    23222320        /* Write the XML document to the temporary file.  */
     
    23252323        /* Make a backup of any existing file (ignore failure). */
    23262324        uint64_t cbPrevFile;
    2327         rc = RTFileQuerySizeByPath(pcszFilename, &cbPrevFile);
     2325        int rc = RTFileQuerySizeByPath(pcszFilename, &cbPrevFile);
    23282326        if (RT_SUCCESS(rc) && cbPrevFile >= 16)
    23292327            RTFileRename(pcszFilename, szPrevFilename, RTPATHRENAME_FLAGS_REPLACE);
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