Skip to content

Commit f57cadd

Browse files
committed
Always invoke umask at start
* zic.c (ALL_PERMS, TROUBLE_PERMS): New macros. (MKDIR_PERMS): Define in terms of these macros. (main): Always invoke umask at start, using TROUBLE_PERMS.
1 parent 242a833 commit f57cadd

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

zic.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,29 @@ enum { FORMAT_LEN_GROWTH_BOUND = 5 };
6868
# include <sys/random.h>
6969
#endif
7070

71+
7172
#if HAVE_SYS_STAT_H
7273
# include <sys/stat.h>
7374
#endif
74-
#ifdef S_IRUSR
75-
# define MKDIR_PERMS (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
75+
76+
#ifdef S_IRWXU
77+
/* All file permission bits. */
78+
# define ALL_PERMS (S_IRWXU | S_IRWXG | S_IRWXO)
79+
80+
/* Troublesome file permission bits. */
81+
# define TROUBLE_PERMS (S_IWGRP | S_IWOTH)
7682
#else
77-
# define MKDIR_PERMS 0755
83+
# define ALL_PERMS 0777
84+
# define TROUBLE_PERMS 0022
7885
#endif
7986

87+
/* File permission bits for making directories.
88+
The initial umask modifies these bits.
89+
Although the "& ~TROUBLE_PERMS" is redundant because we remove
90+
TROUBLE_PERMS from the umask early on, the redundancy does not hurt. */
91+
#define MKDIR_PERMS (ALL_PERMS & ~TROUBLE_PERMS)
92+
93+
8094
/* The minimum alignment of a type, for pre-C23 platforms.
8195
The __SUNPRO_C test is because Oracle Developer Studio 12.6 lacks
8296
<stdalign.h> even though __STDC_VERSION__ == 201112. */
@@ -993,9 +1007,10 @@ main(int argc, char **argv)
9931007
register ptrdiff_t i, j;
9941008
bool timerange_given = false;
9951009

996-
#ifdef S_IWGRP
997-
umask(umask(S_IWGRP | S_IWOTH) | (S_IWGRP | S_IWOTH));
998-
#endif
1010+
/* Adjust umask so that created files lack troublesome permission bits.
1011+
Needed because regular files are created via fopen not openat. */
1012+
umask(umask(TROUBLE_PERMS) | TROUBLE_PERMS);
1013+
9991014
#if HAVE_GETTEXT
10001015
setlocale(LC_ALL, "");
10011016
# ifdef TZ_DOMAINDIR

0 commit comments

Comments
 (0)