[libcxx-commits] [libcxx] [libc++][TZDB] Fixes relative path resolving. (PR #87882)
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Apr 6 10:02:05 PDT 2024
https://github.com/mordante created https://github.com/llvm/llvm-project/pull/87882
The path /etc/localtime is a symlink. This symlink can be a relative path. This fixes resolving a relative symlink.
Since the path used is hard-coded based on the user's system there is no good way to test this.
Fixes: https://github.com/llvm/llvm-project/issues/87872
>From c5331c73f6ae8acad19078c3afdb48989fcc66be Mon Sep 17 00:00:00 2001
From: Mark de Wever <koraq at xs4all.nl>
Date: Sat, 6 Apr 2024 18:59:17 +0200
Subject: [PATCH] [libc++][TZDB] Fixes relative path resolving.
The path /etc/localtime is a symlink. This symlink can be a relative
path. This fixes resolving a relative symlink.
Since the path used is hard-coded based on the user's system there is no
good way to test this.
Fixes: https://github.com/llvm/llvm-project/issues/87872
---
libcxx/src/tzdb.cpp | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/libcxx/src/tzdb.cpp b/libcxx/src/tzdb.cpp
index 2c82a4a4317a81..9d06eb920e5cdf 100644
--- a/libcxx/src/tzdb.cpp
+++ b/libcxx/src/tzdb.cpp
@@ -717,8 +717,12 @@ void __init_tzdb(tzdb& __tzdb, __tz::__rules_storage_type& __rules) {
std::__throw_runtime_error("tzdb: the path '/etc/localtime' is not a symlink");
filesystem::path __tz = filesystem::read_symlink(__path);
- string __name = filesystem::relative(__tz, "/usr/share/zoneinfo/");
+ // The path may be a relative path, in that case convert it to an absolute
+ // path based on the proper initial directory.
+ if (__tz.is_relative())
+ __tz = filesystem::canonical("/etc" / __tz);
+ string __name = filesystem::relative(__tz, "/usr/share/zoneinfo/");
if (const time_zone* __result = tzdb.__locate_zone(__name))
return __result;
More information about the libcxx-commits
mailing list