You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.3 KiB
42 lines
1.3 KiB
From 02c738a767bb837acb8d0366ace09804120283e6 Mon Sep 17 00:00:00 2001
|
|
From: Pavel Boldin <pboldin@cloudlinux.com>
|
|
Date: Fri, 15 Mar 2024 15:21:16 +0000
|
|
Subject: [PATCH 2/2] CanonicalizePath: fix 'a/b/.._foo' -> 'a' replacement
|
|
|
|
Signed-off-by: Pavel Boldin <pboldin@cloudlinux.com>
|
|
---
|
|
src/util.cc | 2 +-
|
|
src/util_test.cc | 4 ++++
|
|
2 files changed, 5 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/src/util.cc b/src/util.cc
|
|
index dcb6abc..ff624ba 100644
|
|
--- a/src/util.cc
|
|
+++ b/src/util.cc
|
|
@@ -253,7 +253,7 @@ void CanonicalizePath(char* path, size_t* len, uint64_t* slash_bits) {
|
|
if (src[0] == '.') {
|
|
if (component_len == 1)
|
|
break; // Ignore trailing '.' (e.g. 'foo/.' -> 'foo/')
|
|
- if (src[1] == '.') {
|
|
+ if (component_len == 2 && src[1] == '.') {
|
|
// Handle '..'. Back up if possible.
|
|
if (component_count > 0) {
|
|
while (--dst > dst0 && !IsPathSeparator(dst[-1])) {
|
|
diff --git a/src/util_test.cc b/src/util_test.cc
|
|
index 8467e2a..d76954c 100644
|
|
--- a/src/util_test.cc
|
|
+++ b/src/util_test.cc
|
|
@@ -152,6 +152,10 @@ TEST(CanonicalizePath, PathSamples) {
|
|
path = "foo/..";
|
|
CanonicalizePath(&path);
|
|
EXPECT_EQ(".", path);
|
|
+
|
|
+ path = "foo/.._bar";
|
|
+ CanonicalizePath(&path);
|
|
+ EXPECT_EQ("foo/.._bar", path);
|
|
}
|
|
|
|
#ifdef _WIN32
|
|
--
|
|
2.45.0.windows.1
|
|
|
|
|