@@ -1479,20 +1479,29 @@ struct RealPathTestCase {
14791479 const char * exp ;
14801480};
14811481
1482+ /* On Zephyr, wolfSSH_RealPath preserves the trailing slash after a drive-root
1483+ * colon (e.g. /C:/) rather than stripping it (e.g. /C:), due to the
1484+ * WOLFSSH_ZEPHYR guard in the ".." handler. */
1485+ #ifdef WOLFSSH_ZEPHYR
1486+ #define WOLFSSH_TEST_DRIVE_ROOT "/C:/"
1487+ #else
1488+ #define WOLFSSH_TEST_DRIVE_ROOT "/C:"
1489+ #endif
1490+
14821491struct RealPathTestCase realPathDefault [] = {
14831492 { "." , "/C:/Users/fred" },
14841493 { "" , "/C:/Users/fred" },
14851494 { "/C:/Users/fred/.." , "/C:/Users" },
14861495 { ".." , "/C:/Users" },
1487- { "../.." , "/C:" },
1496+ { "../.." , WOLFSSH_TEST_DRIVE_ROOT },
14881497 { "../barney" , "/C:/Users/barney" },
1489- { "/C:/Users/.." , "/C:" },
1498+ { "/C:/Users/.." , WOLFSSH_TEST_DRIVE_ROOT },
14901499 { "/C:/.." , "/" },
14911500 { "/C:/../../../../../../../.." , "/" },
14921501 { "/" , "/" },
1493- { "/C:/Users/fred/../.." , "/C:" },
1502+ { "/C:/Users/fred/../.." , WOLFSSH_TEST_DRIVE_ROOT },
14941503 { "/C:/Users/fred/././././." , "/C:/Users/fred" },
1495- { "/C:/Users/fred/../././.." , "/C:" },
1504+ { "/C:/Users/fred/../././.." , WOLFSSH_TEST_DRIVE_ROOT },
14961505 { "./.ssh" , "/C:/Users/fred/.ssh" },
14971506 { "./.ssh/../foo" , "/C:/Users/fred/foo" },
14981507 { "./.ssh/../foo" , "/C:/Users/fred/foo" },
@@ -1514,13 +1523,19 @@ struct RealPathTestCase realPathDefault[] = {
15141523 "/C:/Users/fred/Documents/junk.txt" },
15151524 { "/C:\\Users\\fred/Documents\\junk.txt" ,
15161525 "/C:/Users/fred/Documents/junk.txt" },
1526+ /* Root-preservation / canonicalization of leading ".." */
1527+ { "/../etc/passwd" , "/etc/passwd" },
1528+ { "/../../../etc/passwd" , "/etc/passwd" },
1529+ { "/C:/../../etc/passwd" , "/etc/passwd" },
15171530};
15181531
15191532struct RealPathTestCase realPathNull [] = {
15201533 { "." , "/" },
15211534 { "" , "/" },
15221535 { ".." , "/" },
15231536 { "../barney" , "/barney" },
1537+ { "/../etc/passwd" , "/etc/passwd" },
1538+ { "/../../../etc/passwd" , "/etc/passwd" },
15241539};
15251540
15261541static void DoRealPathTestCase (const char * path , struct RealPathTestCase * tc )
@@ -1534,14 +1549,8 @@ static void DoRealPathTestCase(const char* path, struct RealPathTestCase* tc)
15341549 WMEMSET (checkPath , 0 , sizeof checkPath );
15351550 err = wolfSSH_RealPath (path , testPath ,
15361551 checkPath , sizeof checkPath );
1537- if (err || WSTRCMP (tc -> exp , checkPath ) != 0 ) {
1538- fprintf (stderr , "RealPath failure (%d)\n"
1539- " defaultPath: %s\n"
1540- " input: %s\n"
1541- " expected: %s\n"
1542- " output: %s\n" , err ,
1543- path , tc -> in , tc -> exp , checkPath );
1544- }
1552+ AssertIntEQ (err , WS_SUCCESS );
1553+ AssertStrEQ (tc -> exp , checkPath );
15451554}
15461555
15471556
@@ -1571,14 +1580,7 @@ static void DoRealPathTestFailCase(struct RealPathTestFailCase* tc)
15711580 WMEMSET (checkPath , 0 , sizeof checkPath );
15721581 err = wolfSSH_RealPath (tc -> defaultPath , testPath ,
15731582 checkPath , tc -> checkPathSz );
1574- if (err != tc -> expErr ) {
1575- fprintf (stderr , "RealPath fail check failure (%d)\n"
1576- " defaultPath: %s\n"
1577- " input: %s\n"
1578- " checkPathSz: %u\n"
1579- " expected: %d\n" , err ,
1580- tc -> defaultPath , tc -> in , tc -> checkPathSz , tc -> expErr );
1581- }
1583+ AssertIntEQ (err , tc -> expErr );
15821584}
15831585
15841586
0 commit comments