aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-09-30 16:15:42 -0700
committerElliott Hughes <enh@google.com>2014-09-30 16:40:41 -0700
commit31e072fc9bcf6517d763c7af6d872efd1784629e (patch)
tree579255b857eac677bec2b2e74e1ecf827b04059b
parent1f7d5ac53854a09bbcace08b3a1d1b9cf3f2eed3 (diff)
downloadandroid_bionic-31e072fc9bcf6517d763c7af6d872efd1784629e.tar.gz
android_bionic-31e072fc9bcf6517d763c7af6d872efd1784629e.tar.bz2
android_bionic-31e072fc9bcf6517d763c7af6d872efd1784629e.zip
Update our FreeBSD realpath(3) to upstream head.
Change-Id: I8c89728184ecd2c1a28a05cefa84a5037d28b552
-rw-r--r--libc/upstream-freebsd/lib/libc/stdlib/realpath.c26
-rw-r--r--tests/stdlib_test.cpp12
2 files changed, 18 insertions, 20 deletions
diff --git a/libc/upstream-freebsd/lib/libc/stdlib/realpath.c b/libc/upstream-freebsd/lib/libc/stdlib/realpath.c
index 8fd5457af..c4bd953e9 100644
--- a/libc/upstream-freebsd/lib/libc/stdlib/realpath.c
+++ b/libc/upstream-freebsd/lib/libc/stdlib/realpath.c
@@ -132,26 +132,7 @@ realpath(const char * __restrict path, char * __restrict resolved)
resolved[resolved_len] = '\0';
}
if (next_token[0] == '\0') {
- /*
- * Handle consequential slashes. The path
- * before slash shall point to a directory.
- *
- * Only the trailing slashes are not covered
- * by other checks in the loop, but we verify
- * the prefix for any (rare) "//" or "/\0"
- * occurence to not implement lookahead.
- */
- if (lstat(resolved, &sb) != 0) {
- if (m)
- free(resolved);
- return (NULL);
- }
- if (!S_ISDIR(sb.st_mode)) {
- if (m)
- free(resolved);
- errno = ENOTDIR;
- return (NULL);
- }
+ /* Handle consequential slashes. */
continue;
}
else if (strcmp(next_token, ".") == 0)
@@ -236,6 +217,11 @@ realpath(const char * __restrict path, char * __restrict resolved)
}
}
left_len = strlcpy(left, symlink, sizeof(left));
+ } else if (!S_ISDIR(sb.st_mode) && p != NULL) {
+ if (m)
+ free(resolved);
+ errno = ENOTDIR;
+ return (NULL);
}
}
diff --git a/tests/stdlib_test.cpp b/tests/stdlib_test.cpp
index e814ef714..9ad96fd81 100644
--- a/tests/stdlib_test.cpp
+++ b/tests/stdlib_test.cpp
@@ -99,6 +99,18 @@ TEST(stdlib, realpath__ENOENT) {
ASSERT_EQ(ENOENT, errno);
}
+TEST(stdlib, realpath__component_after_non_directory) {
+ errno = 0;
+ char* p = realpath("/dev/null/.", NULL);
+ ASSERT_TRUE(p == NULL);
+ ASSERT_EQ(ENOTDIR, errno);
+
+ errno = 0;
+ p = realpath("/dev/null/..", NULL);
+ ASSERT_TRUE(p == NULL);
+ ASSERT_EQ(ENOTDIR, errno);
+}
+
TEST(stdlib, realpath) {
// Get the name of this executable.
char executable_path[PATH_MAX];