VirtualBox

Ignore:
Timestamp:
Feb 8, 2024 3:27:12 PM (13 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
161579
Message:

Re-applied r161549 again (Got rid of a lot of deprecated strcpy / strcat calls; now using the IPRT pendants (found by Parfait)), left out some stuff which wasn't wanted, less bloated version of DrvAudio.cpp. bugref:3409

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/SharedFolders/testcase/tstShflCase.cpp

    r103275 r103285  
    11/** @file
    22 * Testcase for shared folder case conversion code.
     3 *
     4 * @todo r=andy Testcase needs to be rewritten using the test framework.
     5 *              Otherwise it's almost pointless to run this on the testboxes.
    36 */
    47
     
    4245#include <iprt/path.h>
    4346#include <iprt/string.h>
     47#include <iprt/test.h>
    4448#include <iprt/uni.h>
    4549#include <stdio.h>
     
    205209}
    206210
    207 static int vbsfCorrectCasing(char *pszFullPath, char *pszStartComponent)
     211static int vbsfCorrectCasing(char *pszFullPath, char *pszStartComponent, size_t cbStartComponent)
    208212{
    209213    PRTDIRENTRYEX  pDirEntry = NULL;
     
    230234    Assert(*(pszStartComponent-1) == RTPATH_DELIMITER);
    231235    *(pszStartComponent-1) = 0;
    232     strcpy(pDirEntry->szName, pszFullPath);
     236    rc = RTStrCopy(pDirEntry->szName, sizeof(pDirEntry->szName), pszFullPath);
     237    if (RT_FAILURE(rc))
     238        goto end;
    233239    szWildCard[0] = RTPATH_DELIMITER;
    234240    szWildCard[1] = '*';
    235241    szWildCard[2] = 0;
    236     strcat(pDirEntry->szName, szWildCard);
    237 
     242    rc = RTStrCat(pDirEntry->szName, sizeof(pDirEntry->szName), szWildCard);
     243    if (RT_FAILURE(rc))
     244        goto end;
    238245    rc = RTDirOpenFiltered(&hSearch, pDirEntry->szName, RTDIRFILTER_WINNT, 0 /*fFlags*/);
    239246    *(pszStartComponent-1) = RTPATH_DELIMITER;
     
    263270        {
    264271            Log(("Found original name %s (%s)\n", &pDirEntry->szName[0], pszStartComponent));
    265             strcpy(pszStartComponent, &pDirEntry->szName[0]);
    266             rc = VINF_SUCCESS;
     272            rc = RTStrCopy(pszStartComponent, cbStartComponent, &pDirEntry->szName[0]);
    267273            break;
    268274        }
     
    282288
    283289
    284 static int testCase(char *pszFullPath, bool fWildCard = false)
     290static int testCase(char *pszFullPath, size_t cbFullPath, bool fWildCard = false)
    285291{
    286292    int rc;
     
    291297    {
    292298        /* strip off the last path component, that contains the wildcard(s) */
    293         size_t   len = strlen(pszFullPath);
    294         char    *src = pszFullPath + len - 1;
    295 
    296         while(src > pszFullPath)
    297         {
    298             if (*src == RTPATH_DELIMITER)
     299        size_t cchLlen = strlen(pszFullPath);
     300        char  *pszSrc  = pszFullPath + cchLlen - 1;
     301
     302        while(pszSrc > pszFullPath)
     303        {
     304            if (*pszSrc == RTPATH_DELIMITER)
    299305                break;
    300             src--;
    301         }
    302         if (*src == RTPATH_DELIMITER)
     306            pszSrc--;
     307        }
     308        if (*pszSrc == RTPATH_DELIMITER)
    303309        {
    304310            bool fHaveWildcards = false;
    305             char *temp = src;
     311            char *temp = pszSrc;
    306312
    307313            while(*temp)
     
    319325            if (fHaveWildcards)
    320326            {
    321                 pszWildCardComponent = src;
     327                pszWildCardComponent = pszSrc;
    322328                *pszWildCardComponent = 0;
    323329            }
     
    328334    if (rc == VERR_FILE_NOT_FOUND || rc == VERR_PATH_NOT_FOUND)
    329335    {
    330         size_t   len = strlen(pszFullPath);
    331         char    *src = pszFullPath + len - 1;
     336        size_t cchLen = strlen(pszFullPath);
     337        char  *pszSrc = pszFullPath + cchLen - 1;
    332338
    333339        Log(("Handle case insensitive guest fs on top of host case sensitive fs for %s\n", pszFullPath));
    334340
    335341        /* Find partial path that's valid */
    336         while(src > pszFullPath)
    337         {
    338             if (*src == RTPATH_DELIMITER)
     342        while(pszSrc > pszFullPath)
     343        {
     344            if (*pszSrc == RTPATH_DELIMITER)
    339345            {
    340                 *src = 0;
     346                *pszSrc = 0;
    341347                rc = RTPathQueryInfo (pszFullPath, &info, RTFSOBJATTRADD_NOTHING);
    342                 *src = RTPATH_DELIMITER;
     348                *pszSrc = RTPATH_DELIMITER;
    343349                if (rc == VINF_SUCCESS)
    344350                {
    345351#ifdef DEBUG
    346                     *src = 0;
     352                    *pszSrc = 0;
    347353                    Log(("Found valid partial path %s\n", pszFullPath));
    348                     *src = RTPATH_DELIMITER;
     354                    *pszSrc = RTPATH_DELIMITER;
    349355#endif
    350356                    break;
     
    352358            }
    353359
    354             src--;
    355         }
    356         Assert(*src == RTPATH_DELIMITER && RT_SUCCESS(rc));
    357         if (    *src == RTPATH_DELIMITER
     360            pszSrc--;
     361        }
     362        Assert(*pszSrc == RTPATH_DELIMITER && RT_SUCCESS(rc));
     363        if (    *pszSrc == RTPATH_DELIMITER
    358364            &&  RT_SUCCESS(rc))
    359365        {
    360             src++;
     366            pszSrc++;
    361367            for(;;)
    362368            {
    363                 char *end = src;
     369                char *end = pszSrc;
    364370                bool fEndOfString = true;
    365371
     
    375381                    fEndOfString = false;
    376382                    *end = 0;
    377                     rc = RTPathQueryInfo(src, &info, RTFSOBJATTRADD_NOTHING);
     383                    rc = RTPathQueryInfo(pszSrc, &info, RTFSOBJATTRADD_NOTHING);
    378384                    Assert(rc == VINF_SUCCESS || rc == VERR_FILE_NOT_FOUND || rc == VERR_PATH_NOT_FOUND);
    379385                }
    380386                else
    381                 if (end == src)
     387                if (end == pszSrc)
    382388                    rc = VINF_SUCCESS;  /* trailing delimiter */
    383389                else
     
    387393                {
    388394                    /* path component is invalid; try to correct the casing */
    389                     rc = vbsfCorrectCasing(pszFullPath, src);
     395                    rc = vbsfCorrectCasing(pszFullPath, pszSrc, cbFullPath - (pszFullPath - pszSrc));
    390396                    if (RT_FAILURE(rc))
    391397                    {
     
    400406
    401407                *end = RTPATH_DELIMITER;
    402                 src = end + 1;
     408                pszSrc = end + 1;
    403409            }
    404410            if (RT_FAILURE(rc))
     
    430436    RTLogFlags(NULL, "unbuffered");
    431437
    432     strcpy(szTest, "c:\\test Dir\\z.bAt");
    433     testCase(szTest);
    434     strcpy(szTest, "c:\\test dir\\z.bAt");
    435     testCase(szTest);
    436     strcpy(szTest, "c:\\test dir\\SUBDIR\\z.bAt");
    437     testCase(szTest);
    438     strcpy(szTest, "c:\\test dir\\SUBDiR\\atestje.bat");
    439     testCase(szTest);
    440     strcpy(szTest, "c:\\TEST dir\\subDiR\\aTestje.baT");
    441     testCase(szTest);
    442     strcpy(szTest, "c:\\TEST dir\\subDiR\\*");
    443     testCase(szTest, true);
    444     strcpy(szTest, "c:\\TEST dir\\subDiR\\");
    445     testCase(szTest ,true);
    446     strcpy(szTest, "c:\\test dir\\SUBDIR\\");
    447     testCase(szTest);
    448     strcpy(szTest, "c:\\test dir\\invalid\\SUBDIR\\test.bat");
    449     testCase(szTest);
     438    RTTESTI_CHECK_RC_OK(RTStrCopy(szTest, sizeof(szTest), "c:\\test Dir\\z.bAt"));
     439    testCase(szTest, sizeof(szTest));
     440    RTTESTI_CHECK_RC_OK(RTStrCopy(szTest, sizeof(szTest), "c:\\test dir\\z.bAt"));
     441    testCase(szTest, sizeof(szTest));
     442    RTTESTI_CHECK_RC_OK(RTStrCopy(szTest, sizeof(szTest), "c:\\test dir\\SUBDIR\\z.bAt"));
     443    testCase(szTest, sizeof(szTest));
     444    RTTESTI_CHECK_RC_OK(RTStrCopy(szTest, sizeof(szTest), "c:\\test dir\\SUBDiR\\atestje.bat"));
     445    testCase(szTest, sizeof(szTest));
     446    RTTESTI_CHECK_RC_OK(RTStrCopy(szTest, sizeof(szTest), "c:\\TEST dir\\subDiR\\aTestje.baT"));
     447    testCase(szTest, sizeof(szTest));
     448    RTTESTI_CHECK_RC_OK(RTStrCopy(szTest, sizeof(szTest), "c:\\TEST dir\\subDiR\\*"));
     449    testCase(szTest, sizeof(szTest), true);
     450    RTTESTI_CHECK_RC_OK(RTStrCopy(szTest, sizeof(szTest), "c:\\TEST dir\\subDiR\\"));
     451    testCase(szTest ,sizeof(szTest), true);
     452    RTTESTI_CHECK_RC_OK(RTStrCopy(szTest, sizeof(szTest), "c:\\test dir\\SUBDIR\\"));
     453    testCase(szTest, sizeof(szTest));
     454    RTTESTI_CHECK_RC_OK(RTStrCopy(szTest, sizeof(szTest), "c:\\test dir\\invalid\\SUBDIR\\test.bat"));
     455    testCase(szTest, sizeof(szTest));
    450456    return 0;
    451457}
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