HomeFreeBSD

tzcode: Fix issues when TZ is an absolute path

Description

tzcode: Fix issues when TZ is an absolute path

  • If TZ starts with TZDIR, strip any additional slashes so relname does not end up looking like an absolute path. For instance, TZ=/usr/share/zoneinfo//UTC should result in UTC, not /UTC.
  • In the setugid case, we were incorrectly passing name rather than relname to fstatat().
  • Modify the tz_env and tz_env_setugid test cases to exercise both of these scenarios.
  • Also add test cases for invalid values of TZ, which I wrote earlier but forgot to include in a5f14e4f9069.

Reported by: Paul Eggert <eggert@cs.ucla.edu>
MFC after: 3 days
Fixes: 967a49a21a27 ("Update tzcode to 2025b")
Fixes: a5f14e4f9069 ("tzcode: Use -00 only for invalid time zones")
Reviewed by: philip
Differential Revision: https://reviews.freebsd.org/D52753

(cherry picked from commit df8bc705eb04aff2f718678fffb9d5d4f5d7c223)

tzcode: Really fix issues when TZ is an absolute path

This was accidentally left out of the previous commit.

Fixes: df8bc705eb04 ("tzcode: Fix issues when TZ is an absolute path")
(cherry picked from commit 202b59c35ead5bd2b71331169bdeb4845cb655c1)

tzcode: Tweak open flags.

Upstream uses a set of flags that reduces to O_RDONLY | O_CLOEXEC when
you ignore flags that either don't exist in FreeBSD or have no effect.
We were using O_RDONLY | O_BINARY, which reduces to O_RDONLY. Add
O_CLOEXEC. Also replace O_RDONLY with the more accurate O_SEARCH when
opening TZDIR.

MFC after: 3 days
Fixes: 967a49a21a27 ("Update tzcode to 2025b")

(cherry picked from commit d28e4ce6cb61916b4f6bedcf4205a4da1ae121e1)

Details

Provenance
desAuthored on Sat, Sep 27, 5:07 PM
Reviewer
philip
Differential Revision
D52753: tzcode: Fix issues when TZ is an absolute path
Parents
rGa46136a8beb6: tzcode: Drop libc namespace
Branches
Unknown
Tags
Unknown