aboutsummaryrefslogtreecommitdiff
path: root/contrib/tzcode/localtime.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/tzcode/localtime.c')
-rw-r--r--contrib/tzcode/localtime.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/contrib/tzcode/localtime.c b/contrib/tzcode/localtime.c
index c98134f7be7c..1668475ea646 100644
--- a/contrib/tzcode/localtime.c
+++ b/contrib/tzcode/localtime.c
@@ -672,26 +672,29 @@ tzloadbody(char const *name, struct state *sp, char tzloadflags,
if ((tzloadflags & TZLOAD_FROMENV) && strcmp(name, TZDEFAULT) == 0)
tzloadflags &= ~TZLOAD_FROMENV;
relname = name;
- if (strncmp(relname, TZDIR "/", strlen(TZDIR) + 1) == 0)
+ if (strncmp(relname, TZDIR "/", strlen(TZDIR) + 1) == 0) {
relname += strlen(TZDIR) + 1;
- dd = open(TZDIR, O_DIRECTORY | O_RDONLY);
+ while (*relname == '/')
+ relname++;
+ }
+ dd = open(TZDIR, O_DIRECTORY | O_SEARCH | O_CLOEXEC);
if ((tzloadflags & TZLOAD_FROMENV) && issetugid()) {
if (dd < 0)
return errno;
- if (fstatat(dd, name, &sb, AT_RESOLVE_BENEATH) < 0) {
+ if (fstatat(dd, relname, &sb, AT_RESOLVE_BENEATH) < 0) {
fid = -1;
} else if (!S_ISREG(sb.st_mode)) {
fid = -1;
errno = EINVAL;
} else {
- fid = openat(dd, relname, O_RDONLY | O_BINARY, AT_RESOLVE_BENEATH);
+ fid = openat(dd, relname, O_RDONLY | O_CLOEXEC | O_RESOLVE_BENEATH);
}
} else {
if (dd < 0) {
relname = name;
dd = AT_FDCWD;
}
- fid = openat(dd, relname, O_RDONLY | O_BINARY, 0);
+ fid = openat(dd, relname, O_RDONLY | O_CLOEXEC);
}
if (dd != AT_FDCWD && dd >= 0) {
serrno = errno;