aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPo Lu2023-05-17 09:16:48 +0800
committerPo Lu2023-05-17 09:16:48 +0800
commitbb95cdaa0693ecea2953d14f2808a23b66ac9446 (patch)
tree0baff93b05b3d75ce7cec9f491ea7c687942adb5 /lib
parentbb8bf9203ed33de0bb269c8ff69067aa7b3a692a (diff)
parent6cb963b73c3768958e13e96b2534d1e99239a3ff (diff)
downloademacs-bb95cdaa0693ecea2953d14f2808a23b66ac9446.tar.gz
emacs-bb95cdaa0693ecea2953d14f2808a23b66ac9446.zip
Merge remote-tracking branch 'origin/master' into feature/android
Diffstat (limited to 'lib')
-rw-r--r--lib/file-has-acl.c37
-rw-r--r--lib/gettime.c4
-rw-r--r--lib/gettimeofday.c14
-rw-r--r--lib/nanosleep.c3
-rw-r--r--lib/pselect.c6
-rw-r--r--lib/stat-time.h33
-rw-r--r--lib/timespec.h5
-rw-r--r--lib/utimens.c20
8 files changed, 61 insertions, 61 deletions
diff --git a/lib/file-has-acl.c b/lib/file-has-acl.c
index 38bc806dc49..4cddc80bd13 100644
--- a/lib/file-has-acl.c
+++ b/lib/file-has-acl.c
@@ -29,7 +29,10 @@
29 29
30#include "acl-internal.h" 30#include "acl-internal.h"
31 31
32#include "minmax.h"
33
32#if USE_ACL && HAVE_LINUX_XATTR_H && HAVE_LISTXATTR 34#if USE_ACL && HAVE_LINUX_XATTR_H && HAVE_LISTXATTR
35# include <stdckdint.h>
33# include <string.h> 36# include <string.h>
34# include <arpa/inet.h> 37# include <arpa/inet.h>
35# include <sys/xattr.h> 38# include <sys/xattr.h>
@@ -181,32 +184,44 @@ file_has_acl (char const *name, struct stat const *sb)
181 && errno == ERANGE) 184 && errno == ERANGE)
182 { 185 {
183 free (heapbuf); 186 free (heapbuf);
184 listbufsize = listxattr (name, NULL, 0); 187 ssize_t newsize = listxattr (name, NULL, 0);
185 if (listbufsize < 0) 188 if (newsize <= 0)
186 return -1; 189 return newsize;
187 if (SIZE_MAX < listbufsize) 190
191 /* Grow LISTBUFSIZE to at least NEWSIZE. Grow it by a
192 nontrivial amount too, to defend against denial of
193 service by an adversary that fiddles with ACLs. */
194 bool overflow = ckd_add (&listbufsize, listbufsize, listbufsize >> 1);
195 listbufsize = MAX (listbufsize, newsize);
196 if (overflow || SIZE_MAX < listbufsize)
188 { 197 {
189 errno = ENOMEM; 198 errno = ENOMEM;
190 return -1; 199 return -1;
191 } 200 }
201
192 listbuf = heapbuf = malloc (listbufsize); 202 listbuf = heapbuf = malloc (listbufsize);
193 if (!listbuf) 203 if (!listbuf)
194 return -1; 204 return -1;
195 } 205 }
196 206
207 /* In Fedora 39, a file can have both NFSv4 and POSIX ACLs,
208 but if it has an NFSv4 ACL that's the one that matters.
209 In earlier Fedora the two types of ACLs were mutually exclusive.
210 Attempt to work correctly on both kinds of systems. */
211 bool nfsv4_acl
212 = 0 < listsize && have_xattr (XATTR_NAME_NFSV4_ACL, listbuf, listsize);
197 int ret 213 int ret
198 = (listsize < 0 ? -1 214 = (listsize <= 0 ? listsize
199 : (have_xattr (XATTR_NAME_POSIX_ACL_ACCESS, listbuf, listsize) 215 : (nfsv4_acl
216 || have_xattr (XATTR_NAME_POSIX_ACL_ACCESS, listbuf, listsize)
200 || (S_ISDIR (sb->st_mode) 217 || (S_ISDIR (sb->st_mode)
201 && have_xattr (XATTR_NAME_POSIX_ACL_DEFAULT, 218 && have_xattr (XATTR_NAME_POSIX_ACL_DEFAULT,
202 listbuf, listsize)))); 219 listbuf, listsize))));
203 bool nfsv4_acl_but_no_posix_acl
204 = ret == 0 && have_xattr (XATTR_NAME_NFSV4_ACL, listbuf, listsize);
205 free (heapbuf); 220 free (heapbuf);
206 221
207 /* If there is an NFSv4 ACL but no POSIX ACL, follow up with a 222 /* If there is an NFSv4 ACL, follow up with a getxattr syscall
208 getxattr syscall to see whether the NFSv4 ACL is nontrivial. */ 223 to see whether the NFSv4 ACL is nontrivial. */
209 if (nfsv4_acl_but_no_posix_acl) 224 if (nfsv4_acl)
210 { 225 {
211 ret = getxattr (name, XATTR_NAME_NFSV4_ACL, 226 ret = getxattr (name, XATTR_NAME_NFSV4_ACL,
212 stackbuf.xattr, sizeof stackbuf.xattr); 227 stackbuf.xattr, sizeof stackbuf.xattr);
diff --git a/lib/gettime.c b/lib/gettime.c
index f86cc4efbff..ec40ff903e1 100644
--- a/lib/gettime.c
+++ b/lib/gettime.c
@@ -35,8 +35,8 @@ gettime (struct timespec *ts)
35#else 35#else
36 struct timeval tv; 36 struct timeval tv;
37 gettimeofday (&tv, NULL); 37 gettimeofday (&tv, NULL);
38 ts->tv_sec = tv.tv_sec; 38 *ts = (struct timespec) { .tv_sec = tv.tv_sec,
39 ts->tv_nsec = tv.tv_usec * 1000; 39 .tv_nsec = tv.tv_usec * 1000 };
40#endif 40#endif
41} 41}
42 42
diff --git a/lib/gettimeofday.c b/lib/gettimeofday.c
index d896ec132b9..c71629cbc57 100644
--- a/lib/gettimeofday.c
+++ b/lib/gettimeofday.c
@@ -113,8 +113,10 @@ gettimeofday (struct timeval *restrict tv, void *restrict tz)
113 ULONGLONG since_1970 = 113 ULONGLONG since_1970 =
114 since_1601 - (ULONGLONG) 134774 * (ULONGLONG) 86400 * (ULONGLONG) 10000000; 114 since_1601 - (ULONGLONG) 134774 * (ULONGLONG) 86400 * (ULONGLONG) 10000000;
115 ULONGLONG microseconds_since_1970 = since_1970 / (ULONGLONG) 10; 115 ULONGLONG microseconds_since_1970 = since_1970 / (ULONGLONG) 10;
116 tv->tv_sec = microseconds_since_1970 / (ULONGLONG) 1000000; 116 *tv = (struct timeval) {
117 tv->tv_usec = microseconds_since_1970 % (ULONGLONG) 1000000; 117 .tv_sec = microseconds_since_1970 / (ULONGLONG) 1000000,
118 .tv_usec = microseconds_since_1970 % (ULONGLONG) 1000000
119 };
118 120
119 return 0; 121 return 0;
120 122
@@ -127,10 +129,7 @@ gettimeofday (struct timeval *restrict tv, void *restrict tz)
127 struct timeval otv; 129 struct timeval otv;
128 int result = gettimeofday (&otv, (struct timezone *) tz); 130 int result = gettimeofday (&otv, (struct timezone *) tz);
129 if (result == 0) 131 if (result == 0)
130 { 132 *tv = otv;
131 tv->tv_sec = otv.tv_sec;
132 tv->tv_usec = otv.tv_usec;
133 }
134# else 133# else
135 int result = gettimeofday (tv, (struct timezone *) tz); 134 int result = gettimeofday (tv, (struct timezone *) tz);
136# endif 135# endif
@@ -143,8 +142,7 @@ gettimeofday (struct timeval *restrict tv, void *restrict tz)
143# error "Only 1-second nominal clock resolution found. Is that intended?" \ 142# error "Only 1-second nominal clock resolution found. Is that intended?" \
144 "If so, compile with the -DOK_TO_USE_1S_CLOCK option." 143 "If so, compile with the -DOK_TO_USE_1S_CLOCK option."
145# endif 144# endif
146 tv->tv_sec = time (NULL); 145 *tv = (struct timeval) { .tv_sec = time (NULL), .tv_usec = 0 };
147 tv->tv_usec = 0;
148 146
149 return 0; 147 return 0;
150 148
diff --git a/lib/nanosleep.c b/lib/nanosleep.c
index 3f295f49b5d..10974df461e 100644
--- a/lib/nanosleep.c
+++ b/lib/nanosleep.c
@@ -60,8 +60,7 @@ nanosleep (const struct timespec *requested_delay,
60 static_assert (TYPE_MAXIMUM (time_t) / 24 / 24 / 60 / 60); 60 static_assert (TYPE_MAXIMUM (time_t) / 24 / 24 / 60 / 60);
61 const time_t limit = 24 * 24 * 60 * 60; 61 const time_t limit = 24 * 24 * 60 * 60;
62 time_t seconds = requested_delay->tv_sec; 62 time_t seconds = requested_delay->tv_sec;
63 struct timespec intermediate; 63 struct timespec intermediate = *requested_delay;
64 intermediate.tv_nsec = requested_delay->tv_nsec;
65 64
66 while (limit < seconds) 65 while (limit < seconds)
67 { 66 {
diff --git a/lib/pselect.c b/lib/pselect.c
index 52d38378783..1b8c19130c2 100644
--- a/lib/pselect.c
+++ b/lib/pselect.c
@@ -59,8 +59,10 @@ pselect (int nfds, fd_set *restrict rfds,
59 return -1; 59 return -1;
60 } 60 }
61 61
62 tv.tv_sec = timeout->tv_sec; 62 tv = (struct timeval) {
63 tv.tv_usec = (timeout->tv_nsec + 999) / 1000; 63 .tv_sec = timeout->tv_sec,
64 .tv_usec = (timeout->tv_nsec + 999) / 1000
65 };
64 tvp = &tv; 66 tvp = &tv;
65 } 67 }
66 else 68 else
diff --git a/lib/stat-time.h b/lib/stat-time.h
index 5b2702356ee..af084102dae 100644
--- a/lib/stat-time.h
+++ b/lib/stat-time.h
@@ -122,10 +122,8 @@ get_stat_atime (struct stat const *st)
122#ifdef STAT_TIMESPEC 122#ifdef STAT_TIMESPEC
123 return STAT_TIMESPEC (st, st_atim); 123 return STAT_TIMESPEC (st, st_atim);
124#else 124#else
125 struct timespec t; 125 return (struct timespec) { .tv_sec = st->st_atime,
126 t.tv_sec = st->st_atime; 126 .tv_nsec = get_stat_atime_ns (st) };
127 t.tv_nsec = get_stat_atime_ns (st);
128 return t;
129#endif 127#endif
130} 128}
131 129
@@ -136,10 +134,8 @@ get_stat_ctime (struct stat const *st)
136#ifdef STAT_TIMESPEC 134#ifdef STAT_TIMESPEC
137 return STAT_TIMESPEC (st, st_ctim); 135 return STAT_TIMESPEC (st, st_ctim);
138#else 136#else
139 struct timespec t; 137 return (struct timespec) { .tv_sec = st->st_ctime,
140 t.tv_sec = st->st_ctime; 138 .tv_nsec = get_stat_ctime_ns (st) };
141 t.tv_nsec = get_stat_ctime_ns (st);
142 return t;
143#endif 139#endif
144} 140}
145 141
@@ -150,10 +146,8 @@ get_stat_mtime (struct stat const *st)
150#ifdef STAT_TIMESPEC 146#ifdef STAT_TIMESPEC
151 return STAT_TIMESPEC (st, st_mtim); 147 return STAT_TIMESPEC (st, st_mtim);
152#else 148#else
153 struct timespec t; 149 return (struct timespec) { .tv_sec = st->st_mtime,
154 t.tv_sec = st->st_mtime; 150 .tv_nsec = get_stat_mtime_ns (st) };
155 t.tv_nsec = get_stat_mtime_ns (st);
156 return t;
157#endif 151#endif
158} 152}
159 153
@@ -168,8 +162,8 @@ get_stat_birthtime (_GL_UNUSED struct stat const *st)
168 || defined HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC) 162 || defined HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC)
169 t = STAT_TIMESPEC (st, st_birthtim); 163 t = STAT_TIMESPEC (st, st_birthtim);
170#elif defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC 164#elif defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC
171 t.tv_sec = st->st_birthtime; 165 t = (struct timespec) { .tv_sec = st->st_birthtime,
172 t.tv_nsec = st->st_birthtimensec; 166 .tv_nsec = st->st_birthtimensec };
173#elif defined _WIN32 && ! defined __CYGWIN__ 167#elif defined _WIN32 && ! defined __CYGWIN__
174 /* Native Windows platforms (but not Cygwin) put the "file creation 168 /* Native Windows platforms (but not Cygwin) put the "file creation
175 time" in st_ctime (!). See 169 time" in st_ctime (!). See
@@ -177,13 +171,11 @@ get_stat_birthtime (_GL_UNUSED struct stat const *st)
177# if _GL_WINDOWS_STAT_TIMESPEC 171# if _GL_WINDOWS_STAT_TIMESPEC
178 t = st->st_ctim; 172 t = st->st_ctim;
179# else 173# else
180 t.tv_sec = st->st_ctime; 174 t = (struct timespec) { .tv_sec = st->st_ctime };
181 t.tv_nsec = 0;
182# endif 175# endif
183#else 176#else
184 /* Birth time is not supported. */ 177 /* Birth time is not supported. */
185 t.tv_sec = -1; 178 t = (struct timespec) { .tv_sec = -1, .tv_nsec = -1 };
186 t.tv_nsec = -1;
187#endif 179#endif
188 180
189#if (defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC \ 181#if (defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC \
@@ -195,10 +187,7 @@ get_stat_birthtime (_GL_UNUSED struct stat const *st)
195 sometimes returns junk in the birth time fields; work around this 187 sometimes returns junk in the birth time fields; work around this
196 bug if it is detected. */ 188 bug if it is detected. */
197 if (! (t.tv_sec && 0 <= t.tv_nsec && t.tv_nsec < 1000000000)) 189 if (! (t.tv_sec && 0 <= t.tv_nsec && t.tv_nsec < 1000000000))
198 { 190 t = (struct timespec) { .tv_sec = -1, .tv_nsec = -1 };
199 t.tv_sec = -1;
200 t.tv_nsec = -1;
201 }
202#endif 191#endif
203 192
204 return t; 193 return t;
diff --git a/lib/timespec.h b/lib/timespec.h
index 0bdfd76ef78..e94da75defe 100644
--- a/lib/timespec.h
+++ b/lib/timespec.h
@@ -55,10 +55,7 @@ enum { LOG10_TIMESPEC_RESOLUTION = LOG10_TIMESPEC_HZ };
55_GL_TIMESPEC_INLINE struct timespec 55_GL_TIMESPEC_INLINE struct timespec
56make_timespec (time_t s, long int ns) 56make_timespec (time_t s, long int ns)
57{ 57{
58 struct timespec r; 58 return (struct timespec) { .tv_sec = s, .tv_nsec = ns };
59 r.tv_sec = s;
60 r.tv_nsec = ns;
61 return r;
62} 59}
63 60
64/* Return negative, zero, positive if A < B, A == B, A > B, respectively. */ 61/* Return negative, zero, positive if A < B, A == B, A > B, respectively. */
diff --git a/lib/utimens.c b/lib/utimens.c
index 4c5377eca0f..faa197e6cb5 100644
--- a/lib/utimens.c
+++ b/lib/utimens.c
@@ -405,10 +405,10 @@ fdutimens (int fd, char const *file, struct timespec const timespec[2])
405 struct timeval *t; 405 struct timeval *t;
406 if (ts) 406 if (ts)
407 { 407 {
408 timeval[0].tv_sec = ts[0].tv_sec; 408 timeval[0] = (struct timeval) { .tv_sec = ts[0].tv_sec,
409 timeval[0].tv_usec = ts[0].tv_nsec / 1000; 409 .tv_usec = ts[0].tv_nsec / 1000 };
410 timeval[1].tv_sec = ts[1].tv_sec; 410 timeval[1] = (struct timeval) { .tv_sec = ts[1].tv_sec,
411 timeval[1].tv_usec = ts[1].tv_nsec / 1000; 411 .tv_usec = ts[1].tv_nsec / 1000 };
412 t = timeval; 412 t = timeval;
413 } 413 }
414 else 414 else
@@ -502,8 +502,8 @@ fdutimens (int fd, char const *file, struct timespec const timespec[2])
502 struct utimbuf *ut; 502 struct utimbuf *ut;
503 if (ts) 503 if (ts)
504 { 504 {
505 utimbuf.actime = ts[0].tv_sec; 505 utimbuf = (struct utimbuf) { .actime = ts[0].tv_sec,
506 utimbuf.modtime = ts[1].tv_sec; 506 .modtime = ts[1].tv_sec };
507 ut = &utimbuf; 507 ut = &utimbuf;
508 } 508 }
509 else 509 else
@@ -621,10 +621,10 @@ lutimens (char const *file, struct timespec const timespec[2])
621 int result; 621 int result;
622 if (ts) 622 if (ts)
623 { 623 {
624 timeval[0].tv_sec = ts[0].tv_sec; 624 timeval[0] = (struct timeval) { .tv_sec = ts[0].tv_sec,
625 timeval[0].tv_usec = ts[0].tv_nsec / 1000; 625 .tv_usec = ts[0].tv_nsec / 1000 };
626 timeval[1].tv_sec = ts[1].tv_sec; 626 timeval[1] = (struct timeval) { .tv_sec = ts[1].tv_sec,
627 timeval[1].tv_usec = ts[1].tv_nsec / 1000; 627 .tv_usec = ts[1].tv_nsec / 1000 };
628 t = timeval; 628 t = timeval;
629 } 629 }
630 else 630 else