Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to 2024a #9

Merged
merged 1 commit into from
Mar 4, 2024
Merged

Update to 2024a #9

merged 1 commit into from
Mar 4, 2024

Conversation

Algunenano
Copy link
Member

Full diff with upstream/master:

diff --git a/src/time_zone_info.cc b/src/time_zone_info.cc
index cc4b001..13edb0d 100644
--- a/src/time_zone_info.cc
+++ b/src/time_zone_info.cc
@@ -818,6 +818,26 @@ bool TimeZoneInfo::Load(ZoneInfoSource* zip) {
   return true;
 }
 
+namespace {
+
+bool CheckTimeZoneName(const std::string& name) {
+    const char * forbidden_beginnings[] = {"/", "./", "~", ".."};
+    for (const auto & pattern : forbidden_beginnings) {
+        if (name.starts_with(pattern)) {
+            return false;
+        }
+    }
+
+    if (name.find("../") != std::string::npos) {
+        return false;
+    }
+
+    return true;
+}
+
+}  // namespace
+
+
 bool TimeZoneInfo::Load(const std::string& name) {
   // We can ensure that the loading of UTC or any other fixed-offset
   // zone never fails because the simple, fixed-offset state can be
@@ -828,6 +848,12 @@ bool TimeZoneInfo::Load(const std::string& name) {
     return ResetToBuiltinUTC(offset);
   }
 
+  // Check if timezone name contains forbidden patterns
+  // that can lead to arbitrary file open.
+  if (!CheckTimeZoneName(name)) {
+      return false;
+  }
+
   // Find and use a ZoneInfoSource to load the named zone.
   auto zip = cctz_extension::zone_info_source_factory(
       name, [](const std::string& n) -> std::unique_ptr<ZoneInfoSource> {
diff --git a/src/time_zone_lookup.cc b/src/time_zone_lookup.cc
index 75ab65d..a36a506 100644
--- a/src/time_zone_lookup.cc
+++ b/src/time_zone_lookup.cc
@@ -18,11 +18,6 @@
 #include <sys/system_properties.h>
 #endif
 
-#if defined(__APPLE__)
-#include <CoreFoundation/CFTimeZone.h>
-#include <vector>
-#endif
-
 #if defined(__Fuchsia__)
 #include <fuchsia/intl/cpp/fidl.h>
 #include <lib/async-loop/cpp/loop.h>
@@ -197,20 +192,6 @@ time_zone local_time_zone() {
     zone = sysprop;
   }
 #endif
-#if defined(__APPLE__)
-  std::vector<char> buffer;
-  CFTimeZoneRef tz_default = CFTimeZoneCopyDefault();
-  if (CFStringRef tz_name = CFTimeZoneGetName(tz_default)) {
-    CFStringEncoding encoding = kCFStringEncodingUTF8;
-    CFIndex length = CFStringGetLength(tz_name);
-    CFIndex max_size = CFStringGetMaximumSizeForEncoding(length, encoding) + 1;
-    buffer.resize(static_cast<size_t>(max_size));
-    if (CFStringGetCString(tz_name, &buffer[0], max_size, encoding)) {
-      zone = &buffer[0];
-    }
-  }
-  CFRelease(tz_default);
-#endif
 #if defined(__Fuchsia__)
   std::string primary_tz;
   [&]() {

Basically #1 + #7

@Algunenano Algunenano merged commit 7918cb7 into master Mar 4, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant