diff --git a/plugins/sudoers/rationalize.c b/plugins/sudoers/rationalize.c index d2961133e5..190a2a98f0 100644 --- a/plugins/sudoers/rationalize.c +++ b/plugins/sudoers/rationalize.c @@ -52,6 +52,13 @@ rationalize_path(char *path, bool dotdot) /* The size argument includes the terminating NUL byte. */ memmove(cp, ep, (size_t)(path_end - ep) + 1); + + /* An absolute path must not collapse to the empty string. */ + if (cp == path && *cp == '\0') { + /* /. -> / */ + path[0] = '/'; + path[1] = '\0'; + } continue; } diff --git a/plugins/sudoers/regress/rationalize/check_rationalize.c b/plugins/sudoers/regress/rationalize/check_rationalize.c index 37a562e23f..34668c1825 100644 --- a/plugins/sudoers/regress/rationalize/check_rationalize.c +++ b/plugins/sudoers/regress/rationalize/check_rationalize.c @@ -54,6 +54,10 @@ static struct test_data rationalize_test_data[] = { { "/etc/../usr/lib", "/usr/lib" }, /* 19 */ { "/etc/../usr/..", "/" }, /* 20 */ { "/usr/lib/../../etc", "/etc" }, /* 21 */ + { "/.", "/" }, /* 22 */ + { "//.", "/" }, /* 23 */ + { "/.//.", "/" }, /* 24 */ + { "/usr/..//.", "/" }, /* 25 */ { NULL } };