Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1479,20 +1479,29 @@ struct RealPathTestCase {
const char* exp;
};

/* On Zephyr, wolfSSH_RealPath preserves the trailing slash after a drive-root
* colon (e.g. /C:/) rather than stripping it (e.g. /C:), due to the
* WOLFSSH_ZEPHYR guard in the ".." handler. */
#ifdef WOLFSSH_ZEPHYR
#define WOLFSSH_TEST_DRIVE_ROOT "/C:/"
#else
#define WOLFSSH_TEST_DRIVE_ROOT "/C:"
#endif

struct RealPathTestCase realPathDefault[] = {
{ ".", "/C:/Users/fred" },
{ "", "/C:/Users/fred" },
{ "/C:/Users/fred/..", "/C:/Users" },
{ "..", "/C:/Users" },
{ "../..", "/C:" },
{ "../..", WOLFSSH_TEST_DRIVE_ROOT },
{ "../barney", "/C:/Users/barney" },
{ "/C:/Users/..", "/C:" },
{ "/C:/Users/..", WOLFSSH_TEST_DRIVE_ROOT },
{ "/C:/..", "/" },
{ "/C:/../../../../../../../..", "/" },
{ "/", "/" },
{ "/C:/Users/fred/../..", "/C:" },
{ "/C:/Users/fred/../..", WOLFSSH_TEST_DRIVE_ROOT },
{ "/C:/Users/fred/././././.", "/C:/Users/fred" },
{ "/C:/Users/fred/../././..", "/C:" },
{ "/C:/Users/fred/../././..", WOLFSSH_TEST_DRIVE_ROOT },
{ "./.ssh", "/C:/Users/fred/.ssh" },
{ "./.ssh/../foo", "/C:/Users/fred/foo" },
{ "./.ssh/../foo", "/C:/Users/fred/foo" },
Expand All @@ -1514,13 +1523,19 @@ struct RealPathTestCase realPathDefault[] = {
"/C:/Users/fred/Documents/junk.txt" },
{ "/C:\\Users\\fred/Documents\\junk.txt",
"/C:/Users/fred/Documents/junk.txt" },
/* Root-preservation / canonicalization of leading ".." */
{ "/../etc/passwd", "/etc/passwd" },
{ "/../../../etc/passwd", "/etc/passwd" },
{ "/C:/../../etc/passwd", "/etc/passwd" },
};

struct RealPathTestCase realPathNull[] = {
{ ".", "/" },
{ "", "/" },
{ "..", "/" },
{ "../barney", "/barney" },
{ "/../etc/passwd", "/etc/passwd" },
{ "/../../../etc/passwd", "/etc/passwd" },
};

static void DoRealPathTestCase(const char* path, struct RealPathTestCase* tc)
Expand All @@ -1534,14 +1549,8 @@ static void DoRealPathTestCase(const char* path, struct RealPathTestCase* tc)
WMEMSET(checkPath, 0, sizeof checkPath);
err = wolfSSH_RealPath(path, testPath,
checkPath, sizeof checkPath);
if (err || WSTRCMP(tc->exp, checkPath) != 0) {
fprintf(stderr, "RealPath failure (%d)\n"
" defaultPath: %s\n"
" input: %s\n"
" expected: %s\n"
" output: %s\n", err,
path, tc->in, tc->exp, checkPath);
}
AssertIntEQ(err, WS_SUCCESS);
AssertStrEQ(tc->exp, checkPath);
}


Expand Down Expand Up @@ -1571,14 +1580,7 @@ static void DoRealPathTestFailCase(struct RealPathTestFailCase* tc)
WMEMSET(checkPath, 0, sizeof checkPath);
err = wolfSSH_RealPath(tc->defaultPath, testPath,
checkPath, tc->checkPathSz);
if (err != tc->expErr) {
fprintf(stderr, "RealPath fail check failure (%d)\n"
" defaultPath: %s\n"
" input: %s\n"
" checkPathSz: %u\n"
" expected: %d\n", err,
tc->defaultPath, tc->in, tc->checkPathSz, tc->expErr);
}
AssertIntEQ(err, tc->expErr);
}


Expand Down
Loading