Skip to content

Commit

Permalink
Address the other bugs/nits found when handling badly formed paths in
Browse files Browse the repository at this point in the history
path_subst_uservar().
  • Loading branch information
Castaglia committed Jun 17, 2016
1 parent e4faed7 commit 5d616c4
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions tests/api/misc.c
Expand Up @@ -48,6 +48,7 @@ static void set_up(void) {
PR_TUNABLE_FS_STATCACHE_MAX_AGE, 0);

if (getenv("TEST_VERBOSE") != NULL) {
pr_trace_set_levels("auth", 1, 20);
pr_trace_set_levels("fsio", 1, 20);
pr_trace_set_levels("fs.statcache", 1, 20);
}
Expand All @@ -64,6 +65,7 @@ static void tear_down(void) {
PR_TUNABLE_FS_STATCACHE_MAX_AGE, 0);

if (getenv("TEST_VERBOSE") != NULL) {
pr_trace_set_levels("auth", 0, 0);
pr_trace_set_levels("fsio", 0, 0);
pr_trace_set_levels("fs.statcache", 0, 0);
}
Expand Down Expand Up @@ -1108,11 +1110,22 @@ START_TEST (path_subst_uservar_test) {
fail_unless(strcmp(res, expected) == 0, "Expected '%s', got '%s'", expected,
res);

/* Attempt to use an invalid index */
session.user = "user";
original = "/home/users/%u[a]/%u[b]%u[c]/%u";
expected = original;
path = pstrdup(p, original);
mark_point();
res = path_subst_uservar(p, &path);
fail_unless(res != NULL, "Failed to handle path '%s': %s", path,
strerror(errno));
fail_unless(strcmp(res, expected) == 0, "Expected '%s', got '%s'", expected,
res);

/* Attempt to use an out-of-bounds index */
session.user = "user";
original = "/home/users/%u[0]/%u[-1]%u[1]/%u";
/* XXX TODO: This SHOULD be ??? */
expected = "s/user";
expected = original;
path = pstrdup(p, original);
mark_point();
res = path_subst_uservar(p, &path);
Expand All @@ -1124,8 +1137,7 @@ START_TEST (path_subst_uservar_test) {
/* Attempt to use an out-of-bounds index */
session.user = "user";
original = "/home/users/%u[0]/%u[0]%u[4]/%u";
/* XXX TODO: This SHOULD be ??? */
expected = "user";
expected = original;
path = pstrdup(p, original);
mark_point();
res = path_subst_uservar(p, &path);
Expand Down

0 comments on commit 5d616c4

Please sign in to comment.