CRUX-ARM : Home

Home :: Documentation :: Download :: Development :: Community :: Ports :: Packages :: Bugs :: Links :: About :: Donors
glibc: updated to 2.28
[ports/core-arm.git] / glibc / glibc-2.27-3.patch
CommitLineData
79da3d52 1diff --git a/ChangeLog b/ChangeLog
da524a4e 2index f3fe2716b2..2f1e82b61c 100644
79da3d52
VM
3--- a/ChangeLog
4+++ b/ChangeLog
da524a4e
VM
5@@ -1,3 +1,644 @@
6+2018-11-27 Florian Weimer <fweimer@redhat.com>
7+
8+ [BZ #23927]
9+ CVE-2018-19591
10+ * sysdeps/unix/sysv/linux/if_index.c (__if_nametoindex): Avoid
11+ descriptor leak in case of ENODEV error.
12+
13+2018-11-08 Alexandra Hájková <ahajkova@redhat.com>
14+
15+ [BZ #17630]
16+ * resolv/tst-resolv-network.c: Add test for getnetbyname.
17+
18+2018-11-05 Andreas Schwab <schwab@suse.de>
19+
20+ [BZ #22927]
21+ * resolv/gai_misc.c (__gai_enqueue_request): Don't crash if
22+ creating the first helper thread failed.
23+
24+2018-10-23 Adhemerval Zanella <adhemerval.zanella@linaro.org>
25+
26+ [BZ #23709]
27+ * sysdeps/x86/cpu-features.c (init_cpu_features): Set TSX bits
28+ independently of other flags.
29+
30+2018-10-26 Szabolcs Nagy <szabolcs.nagy@arm.com>
31+
32+ [BZ #23822]
33+ * sysdeps/ia64/fpu/e_exp2f.S (exp2f): Use WEAK_LIBM_ENTRY.
34+ * sysdeps/ia64/fpu/e_log2f.S (log2f): Likewise.
35+ * sysdeps/ia64/fpu/e_exp2f.S (powf): Likewise.
36+
37+2018-10-25 Florian Weimer <fweimer@redhat.com>
38+
39+ [BZ #23562]
40+ [BZ #23821]
41+ XFAIL siginfo_t si_band conform test on sparc64.
42+ * sysdeps/unix/sysv/linux/sparc/bits/siginfo-arch.h
43+ (__SI_BAND_TYPE): Only override long int default type on sparc64.
44+ * sysdeps/unix/sysv/linux/sparc/sparc64/Makefile
45+ (conformtest-xfail-conds): Add sparc64-linux.
46+ * conform/data/signal.h-data (siginfo_t): XFAIL si_band test on
47+ sparc64.
48+ * conform/data/sys/wait.h-data (siginfo_t): Likewise.
49+
50+2018-10-19 Ilya Yu. Malakhov <malakhov@mcst.ru>
51+
52+ [BZ #23562]
53+ * sysdeps/unix/sysv/linux/bits/types/siginfo_t.h
54+ (struct siginfo_t): Use correct type for si_band.
55+
56+2018-10-17 Stefan Liebler <stli@linux.ibm.com>
57+
58+ [BZ #23275]
59+ * nptl/tst-mutex10.c: New File.
60+ * nptl/Makefile (tests): Add tst-mutex10.
61+ (tst-mutex10-ENV): New variable.
62+ * sysdeps/unix/sysv/linux/s390/force-elision.h: (FORCE_ELISION):
63+ Ensure that elision path is used if elision is available.
64+ * sysdeps/unix/sysv/linux/powerpc/force-elision.h (FORCE_ELISION):
65+ Likewise.
66+ * sysdeps/unix/sysv/linux/x86/force-elision.h: (FORCE_ELISION):
67+ Likewise.
68+ * nptl/pthreadP.h (PTHREAD_MUTEX_TYPE, PTHREAD_MUTEX_TYPE_ELISION)
69+ (PTHREAD_MUTEX_PSHARED): Use atomic_load_relaxed.
70+ * nptl/pthread_mutex_consistent.c (pthread_mutex_consistent): Likewise.
71+ * nptl/pthread_mutex_getprioceiling.c (pthread_mutex_getprioceiling):
72+ Likewise.
73+ * nptl/pthread_mutex_lock.c (__pthread_mutex_lock_full)
74+ (__pthread_mutex_cond_lock_adjust): Likewise.
75+ * nptl/pthread_mutex_setprioceiling.c (pthread_mutex_setprioceiling):
76+ Likewise.
77+ * nptl/pthread_mutex_timedlock.c (__pthread_mutex_timedlock): Likewise.
78+ * nptl/pthread_mutex_trylock.c (__pthread_mutex_trylock): Likewise.
79+ * nptl/pthread_mutex_unlock.c (__pthread_mutex_unlock_full): Likewise.
80+ * sysdeps/nptl/bits/thread-shared-types.h (struct __pthread_mutex_s):
81+ Add comments.
82+ * nptl/pthread_mutex_destroy.c (__pthread_mutex_destroy):
83+ Use atomic_load_relaxed and atomic_store_relaxed.
84+ * nptl/pthread_mutex_init.c (__pthread_mutex_init):
85+ Use atomic_store_relaxed.
86+
87+2018-09-28 Adhemerval Zanella <adhemerval.zanella@linaro.org>
88+
89+ [BZ #23579]
90+ * misc/tst-preadvwritev2-common.c (do_test_with_invalid_fd,
91+ do_test_with_invalid_iov): New tests.
92+ * misc/tst-preadvwritev2.c, misc/tst-preadvwritev64v2.c (do_test):
93+ Call do_test_with_invalid_fd and do_test_with_invalid_iov.
94+ * sysdeps/unix/sysv/linux/preadv2.c (preadv2): Use fallback code iff
95+ errno is ENOSYS.
96+ * sysdeps/unix/sysv/linux/preadv64v2.c (preadv64v2): Likewise.
97+ * sysdeps/unix/sysv/linux/pwritev2.c (pwritev2): Likewise.
98+ * sysdeps/unix/sysv/linux/pwritev64v2.c (pwritev64v2): Likewise.
99+ * NEWS: Add bug fixed.
100+
101+2018-09-28 Florian Weimer <fweimer@redhat.com>
102+
103+ [BZ #22753]
104+ * sysdeps/posix/preadv2.c (preadv2): Handle offset == -1.
105+ * sysdeps/posix/preadv64v2.c (preadv64v2): Likewise.
106+ * sysdeps/posix/pwritev2.c (pwritev2): Likewise.
107+ * sysdeps/posix/pwritev64v2.c (pwritev64v2): Likweise.
108+ * sysdeps/unix/sysv/linux/preadv2.c (preadv2): Likewise.
109+ * sysdeps/unix/sysv/linux/preadv64v2.c (preadv64v2): Likewise.
110+ * sysdeps/unix/sysv/linux/pwritev2.c (pwritev2): Likewise.
111+ * sysdeps/unix/sysv/linux/pwritev64v2.c (pwritev64v2): Likweise.
112+ * manual/llio.texi (Scatter-Gather): Mention offset -1.
113+ * misc/tst-preadvwritev-common.c (do_test_without_offset): New.
114+ * misc/tst-preadvwritev2.c (do_test): Call it.
115+ * misc/tst-preadvwritev64v2.c (do_test): Likewise.
116+ * NEWS: Add bug fixed.
117+
118+2018-09-06 Stefan Liebler <stli@linux.ibm.com>
119+
120+ * sysdeps/unix/sysv/linux/spawni.c (maybe_script_execute):
121+ Increment size of new_argv by one.
122+
123+2018-08-27 Martin Kuchta <martin.kuchta@netapp.com>
124+ Torvald Riegel <triegel@redhat.com>
125+
126+ [BZ #23538]
127+ * nptl/pthread_cond_common.c (__condvar_quiesce_and_switch_g1):
128+ Update r to include the set wake-request flag if waiters are
129+ remaining after spinning.
130+
131+2018-07-29 H.J. Lu <hongjiu.lu@intel.com>
132+
133+ [BZ #23459]
134+ * sysdeps/x86/cpu-features.c (get_extended_indices): New
135+ function.
136+ (init_cpu_features): Call get_extended_indices for both Intel
137+ and AMD CPUs.
138+ * sysdeps/x86/cpu-features.h (COMMON_CPUID_INDEX_80000001):
139+ Remove "for AMD" comment.
140+
141+2018-07-29 H.J. Lu <hongjiu.lu@intel.com>
142+
143+ [BZ #23456]
144+ * sysdeps/x86/cpu-features.h (index_cpu_LZCNT): Set to
145+ COMMON_CPUID_INDEX_80000001.
146+
147+2018-07-10 Florian Weimer <fweimer@redhat.com>
148+
149+ [BZ #23036]
150+ * posix/regexec.c (check_node_accept_bytes): When comparing
151+ weights, do not compare an extra byte after the end of the
152+ weights.
153+
154+2018-06-29 Sylvain Lesage <severo@rednegra.net>
155+
156+ [BZ #22996]
157+ * localedata/locales/es_BO (LC_PAPER): Change to “copy "en_US"”.
158+
159+2018-07-06 Florian Weimer <fweimer@redhat.com>
160+
161+ * conform/conformtest.pl (checknamespace): Escape literal braces
162+ in regular expressions.
163+
164+2018-06-21 Florian Weimer <fweimer@redhat.com>
165+
166+ [BZ #23253]
167+ * sysdeps/generic/math_private.h (default_libc_feholdsetround_ctx):
168+ Renamed from libc_feholdsetround_ctx.
169+ (default_libc_feresetround_ctx): Renamed from
170+ libc_feresetround_ctx.
171+ (default_libc_feholdsetround_noex_ctx): Renamed from
172+ libc_feholdsetround_noex_ctx.
173+ (default_libc_feresetround_noex_ctx): Renamed from
174+ libc_feresetround_noex_ctx.
175+ [!HAVE_RM_CTX] (libc_feholdsetround_ctx, libc_feresetround_ctx)
176+ (libc_feholdsetround_noex_ctx, libc_feresetround_noex_ctx): Macros
177+ forwardning to the old implementations under the new names.
178+ * sysdeps/i386/fpu/fenv_private.h [__SSE_MATH__]
179+ (libc_feholdexcept_setround_ctx, libc_fesetenv_ctx)
180+ (libc_feupdateenv_ctx, libc_feholdsetround_ctx)
181+ (libc_feresetround_ctx): Forward to default implements for i386
182+ and MATH_SET_BOTH_ROUNDING_MODES.
183+ * sysdeps/i386/Makefile [$(subdir) == math] (CFLAGS-e_gamma_r.c):
184+ Add -DMATH_SET_BOTH_ROUNDING_MODES.
185+
186+2018-07-03 Florian Weimer <fweimer@redhat.com>
187+
188+ [BZ #23363]
189+ * stdio-common/tst-printf.c (DEC, INT, UNS, fp_test): Remove.
190+ * stdio-common/tst-printf.sh: Adjust expected output.
191+ * LICENSES: Update.
192+
193+2018-06-26 Florian Weimer <fweimer@redhat.com>
194+
195+ * libio/Makefile (tests-internal): Add tst-vtables,
196+ tst-vtables-interposed.
197+ * libio/tst-vtables.c: New file.
198+ * libio/tst-vtables-common.c: Likewise.
199+ * libio/tst-vtables-interposed.c: Likewise.
200+
201+2018-06-26 Florian Weimer <fweimer@redhat.com>
202+
203+ [BZ #23313]
204+ * libio/vtables.c (check_stdfiles_vtables): New ELF constructor.
205+
206+2018-06-29 Daniel Alvarez <dalvarez@redhat.com>
207+ Jakub Sitnicki <jkbs@redhat.com>
208+
209+ [BZ #21812]
210+ * sysdeps/unix/sysv/linux/ifaddrs.c (getifaddrs_internal): Retry
211+ on NLM_F_DUMP_INTR.
212+
213+2018-06-28 Florian Weimer <fweimer@redhat.com>
214+
215+ [BZ #23349]
216+ * time/bits/types/struct_timespec.h: Change header inclusion guard to
217+ _STRUCT_TIMESPEC.
218+
79da3d52
VM
219+2018-05-24 Gabriel F. T. Gomes <gabriel@inconstante.eti.br>
220+
221+ [BZ #23171]
222+ * math/math.h [C++] (iseqsig): Fix parameter type for the long
223+ double version.
224+
225+2018-06-12 Carlos O'Donell <carlos@redhat.com>
226+ Andreas Schwab <schwab@suse.de>
227+ Dmitry V. Levin <ldv@altlinux.org>
228+ Florian Weimer <fweimer@redhat.com>
229+
230+ [BZ #23102]
231+ [BZ #21942]
232+ [BZ #18018]
233+ [BZ #23259]
234+ CVE-2011-0536
235+ * elf/dl-dst.h: Remove DL_DST_COUNT.
236+ * elf/dl-deps.c (expand_dst): Call _dl_dst_count.
237+ * elf/dl-load.c (is_trusted_path_normalize): Don't handle colons.
238+ (is_dst): Comment. Support ELF gABI.
239+ (_dl_dst_count): Comment. Simplify and count DSTs.
240+ (_dl_dst_substitute): Comment. Support __libc_enable_secure handling.
241+ (expand_dybamic_string_token): Comment. Call _dl_dst_count. Rename
242+ locals.
243+
244+2018-06-12 Florian Weimer <fweimer@redhat.com>
245+
246+ x86: Make strncmp usable from rtld.
247+ * sysdeps/i386/i686/multiarch/strncmp-c.c: Only rename strncmp to
248+ __strncmp_ia32 if in libc (and not in rtld).
249+ * sysdeps/x86_64/multiarch/strncmp-sse2.S: Rename strcmp to
250+ strncmp if not in libc (and not to __strncmp_sse2).
251+
252+2018-06-01 Florian Weimer <fweimer@redhat.com>
253+
254+ * sysdeps/i386/i686/fpu/multiarch/libm-test-ulps: Update from master
255+ branch, commit e02c026f38505cd474ff1bdaa88fc671804f5805.
256+ * sysdeps/i386/fpu/libm-test-ulps: Likewise.
257+
258+2018-06-08 Adhemerval Zanella <adhemerval.zanella@linaro.org>
259+
260+ [BZ #23264]
261+ * include/unistd.h (__execvpex): New prototype.
262+ * posix/Makefile (tests): Add tst-spawn4.
263+ (tests-internal): Add tst-spawn4-compat.
264+ * posix/execvpe.c (__execvpe_common, __execvpex): New functions.
265+ * posix/tst-spawn4-compat.c: New file.
266+ * posix/tst-spawn4.c: Likewise.
267+ * sysdeps/unix/sysv/linux/spawni.c (__spawni): Do not interpret invalid
268+ binaries as shell scripts.
269+ * sysdeps/posix/spawni.c (__spawni): Likewise.
270+ * NEWS: Add BZ#22264.
271+
272+2018-06-01 Florian Weimer <fweimer@redhat.com>
273+
274+ [BZ #23236]
275+ * libio/strfile.h (struct _IO_str_fields): Rename members to
276+ discourage their use and add comment.
277+ (_IO_STR_DYNAMIC): Remove unused macro.
278+ * libio/strops.c (_IO_str_init_static_internal): Do not use
279+ callback pointers. Call malloc and free.
280+ (_IO_str_overflow): Do not use callback pointers. Call malloc
281+ and free.
282+ (enlarge_userbuf): Likewise.
283+ (_IO_str_finish): Call free.
284+ * libio/wstrops.c (_IO_wstr_init_static): Initialize
285+ _allocate_buffer_unused.
286+ (_IO_wstr_overflow): Do not use callback pointers. Call malloc
287+ and free.
288+ (enlarge_userbuf): Likewise.
289+ (_IO_wstr_finish): Call free.
290+ * debug/vasprintf_chk.c (__vasprintf_chk): Initialize
291+ _allocate_buffer_unused, _free_buffer_unused.
292+ * libio/memstream.c (__open_memstream): Likewise.
293+ * libio/vasprintf.c (_IO_vasprintf): Likewise.
294+ * libio/wmemstream.c (open_wmemstream): Likewise.
295+
296+2018-05-23 H.J. Lu <hongjiu.lu@intel.com>
297+
298+ [BZ #23196]
299+ * string/test-memcpy.c (do_test1): New function.
300+ (test_main): Call it.
301+
302+2018-05-23 Andreas Schwab <schwab@suse.de>
303+
304+ [BZ #23196]
305+ CVE-2018-11237
306+ * sysdeps/x86_64/multiarch/memmove-avx512-no-vzeroupper.S
307+ (L(preloop_large)): Save initial destination pointer in %r11 and
308+ use it instead of %rax after the loop.
309+ * string/test-mempcpy.c (MIN_PAGE_SIZE): Define.
310+
311+2018-05-11 Florian Weimer <fweimer@redhat.com>
312+
313+ [BZ #23166]
314+ * include/rpc/clnt.h (rpc_createerr): Declare hidden alias.
315+ * include/rpc/svc.h (svc_pollfd, svc_max_pollfd, svc_fdset):
316+ Likewise.
317+ * sunrpc/rpc_common.c (svc_fdset, rpc_createerr, svc_pollfd)
318+ (svc_max_pollfd): Add nocommon attribute and hidden alias. Do not
319+ export without --enable-obsolete-rpc.
320+ * sunrpc/svcauth_des.c (svcauthdes_stats): Turn into compatibility
321+ symbol. This should not have been exported, ever.
322+
323+2018-05-11 Rafal Luzynski <digitalfreak@lingonborough.com>
324+
325+ [BZ #23152]
326+ * localedata/locales/gd_GB (abmon): Fix typo in May:
327+ "Mhàrt" -> "Cèit". Adjust the comment according to the change.
328+
329+2018-05-09 Paul Pluzhnikov <ppluzhnikov@google.com>
330+
331+ [BZ #22786]
332+ CVE-2018-11236
333+ * stdlib/canonicalize.c (__realpath): Fix overflow in path length
334+ computation.
335+ * stdlib/Makefile (test-bz22786): New test.
336+ * stdlib/test-bz22786.c: New test.
337+
338+2018-05-05 Paul Pluzhnikov <ppluzhnikov@google.com>
339+
340+ [BZ #20419]
341+ * elf/dl-load.c (open_verify): Fix stack overflow.
342+ * elf/Makefile (tst-big-note): New test.
343+ * elf/tst-big-note-lib.S: New.
344+ * elf/tst-big-note.c: New.
345+
346+2018-05-04 Stefan Liebler <stli@linux.vnet.ibm.com>
347+
348+ [BZ #23137]
349+ * sysdeps/nptl/lowlevellock.h (lll_wait_tid):
350+ Use atomic_load_acquire to load __tid.
351+
352+2018-04-24 Joseph Myers <joseph@codesourcery.com>
353+
354+ * sysdeps/unix/sysv/linux/sys/ptrace.h
355+ (PTRACE_SECCOMP_GET_METADATA): New enum value and macro.
356+ * sysdeps/unix/sysv/linux/bits/ptrace-shared.h
357+ (struct __ptrace_seccomp_metadata): New type.
358+ * sysdeps/unix/sysv/linux/aarch64/sys/ptrace.h
359+ (PTRACE_SECCOMP_GET_METADATA): Likewise.
360+ * sysdeps/unix/sysv/linux/arm/sys/ptrace.h
361+ (PTRACE_SECCOMP_GET_METADATA): Likewise.
362+ * sysdeps/unix/sysv/linux/ia64/sys/ptrace.h
363+ (PTRACE_SECCOMP_GET_METADATA): Likewise.
364+ * sysdeps/unix/sysv/linux/powerpc/sys/ptrace.h
365+ (PTRACE_SECCOMP_GET_METADATA): Likewise.
366+ * sysdeps/unix/sysv/linux/s390/sys/ptrace.h
367+ (PTRACE_SECCOMP_GET_METADATA): Likewise.
368+ * sysdeps/unix/sysv/linux/sparc/sys/ptrace.h
369+ (PTRACE_SECCOMP_GET_METADATA): Likewise.
370+ * sysdeps/unix/sysv/linux/tile/sys/ptrace.h
371+ (PTRACE_SECCOMP_GET_METADATA): Likewise.
372+ * sysdeps/unix/sysv/linux/x86/sys/ptrace.h
373+ (PTRACE_SECCOMP_GET_METADATA): Likewise.
374+
375+2018-04-09 Florian Weimer <fweimer@redhat.com>
376+
377+ [BZ #23037]
378+ * resolv/res_send.c (send_dg): Use designated initializers instead
379+ of assignment to zero-initialize other fields of struct mmsghdr.
380+
381+2018-04-06 Andreas Schwab <schwab@linux-m68k.org>
382+
383+ * manual/charset.texi (Converting a Character): Fix typo.
384+
385+2018-04-05 Florian Weimer <fweimer@redhat.com>
386+
387+ * manual/examples/mbstouwcs.c (mbstouwcs): Fix loop termination,
388+ integer overflow, memory leak on error, and indeterminate errno
389+ value. Add a null wide character to terminate the result string.
390+ * manual/charset.texi (Converting a Character): Mention embedded
391+ null bytes in the mbrtowc input string. Explain what happens in
392+ the -2 result case. Do not claim that mbrtowc is simple or
393+ obvious to use. Adjust the description of the code example. Use
394+ @code, not @var, for concrete variables.
395+
396+2018-04-05 Florian Weimer <fweimer@redhat.com>
397+
398+ * manual/examples/mbstouwcs.c: New file.
399+ * manual/charset.texi (Converting a Character): Include it.
400+
401+2018-04-03 H.J. Lu <hongjiu.lu@intel.com>
402+
403+ [BZ #22947]
404+ * bits/uio-ext.h (RWF_APPEND): New.
405+ * sysdeps/unix/sysv/linux/bits/uio-ext.h (RWF_APPEND): Likewise.
406+ * manual/llio.texi: Document RWF_APPEND.
407+ * misc/tst-preadvwritev2-common.c (RWF_APPEND): New.
408+ (RWF_SUPPORTED): Add RWF_APPEND.
409+
410+2018-03-27 Jesse Hathaway <jesse@mbuki-mvuki.org>
411+
412+ * sysdeps/unix/sysv/linux/getlogin_r.c (__getlogin_r_loginuid): Return
413+ early when linux sentinel value is set.
414+
415+2018-03-27 Andreas Schwab <schwab@suse.de>
416+
417+ [BZ #23005]
418+ * resolv/res_send.c (__res_context_send): Return ENOMEM if
419+ allocation of private copy of nsaddr_list fails.
420+
421+2018-03-20 Joseph Myers <joseph@codesourcery.com>
422+
423+ [BZ #17343]
424+ * stdlib/random_r.c (__random_r): Use unsigned arithmetic for
425+ possibly overflowing computations.
426+
427+2018-04-26 Aurelien Jarno <aurelien@aurel32.net>
428+
429+ * signal/tst-sigaction.c: New file to test BZ #23069.
430+ * signal/Makefile (tests): Fix indentation. Add tst-sigaction.
431+
432+2018-04-28 Aurelien Jarno <aurelien@aurel32.net>
433+
434+ [BZ #23069]
435+ * sysdeps/unix/sysv/linux/riscv/kernel_sigaction.h: New file.
436+
437+2018-03-29 Florian Weimer <fweimer@redhat.com>
438+
439+ * sysdeps/unix/sysv/linux/i386/tst-bz21269.c (do_test): Also
440+ capture SIGBUS.
441+
442+2018-03-23 Andrew Senkevich <andrew.senkevich@intel.com>
443+ Max Horn <max@quendi.de>
444+
445+ [BZ #22644]
446+ CVE-2017-18269
447+ * sysdeps/i386/i686/multiarch/memcpy-sse2-unaligned.S: Fixed
448+ branch conditions.
449+ * string/test-memmove.c (do_test2): New testcase.
450+
451+2018-02-22 Andrew Waterman <andrew@sifive.com>
452+
453+ [BZ # 22884]
454+ * sysdeps/riscv/rvd/s_fmax.c (__fmax): Handle sNaNs correctly.
455+ * sysdeps/riscv/rvd/s_fmin.c (__fmin): Likewise.
456+ * sysdeps/riscv/rvf/s_fmaxf.c (__fmaxf): Likewise.
457+ * sysdeps/riscv/rvf/s_fminf.c (__fminf): Likewise.
458+
459+2018-02-22 DJ Delorie <dj@delorie.com>
460+
461+ * sysdeps/riscv/tls-macros.h: Do not initialize $gp.
462+
463+2018-03-16 Rafal Luzynski <digitalfreak@lingonborough.com>
464+
465+ [BZ #22963]
466+ * localedata/locales/cs_CZ (mon): Rename to...
467+ (alt_mon): This.
468+ (mon): Import from CLDR (genitive case).
469+
470+2018-03-16 Rafal Luzynski <digitalfreak@lingonborough.com>
471+
472+ [BZ #22937]
473+ * localedata/locales/el_CY (abmon): Rename to...
474+ (ab_alt_mon): This.
475+ (abmon): Import from CLDR (abbreviated genitive case).
476+ * localedata/locales/el_GR (abmon): Rename to...
477+ (ab_alt_mon): This.
478+ (abmon): Import from CLDR (abbreviated genitive case).
479+
480+2018-03-16 Rafal Luzynski <digitalfreak@lingonborough.com>
481+
482+ [BZ #22932]
483+ * localedata/locales/lt_LT (abmon): Synchronize with CLDR.
484+
485+2018-03-16 Robert Buj <robert.buj@gmail.com>
486+
487+ [BZ #22848]
488+ * localedata/locales/ca_ES (abmon): Rename to...
489+ (ab_alt_mon): This, then synchronize with CLDR (nominative case).
490+ (mon): Rename to...
491+ (alt_mon): This.
492+ (abmon): Import from CLDR (genitive case, month names preceded by
493+ "de" or "d’").
494+ (mon): Likewise.
495+ (abday): Synchronize with CLDR.
496+ (d_t_fmt): Likewise.
497+ (d_fmt): Likewise.
498+ (am_pm): Likewise.
499+
500+ (LC_TIME): Improve indentation.
501+ (LC_TELEPHONE): Likewise.
502+ (LC_NAME): Likewise.
503+ (LC_ADDRESS): Likewise.
504+
505+2018-03-12 Dmitry V. Levin <ldv@altlinux.org>
506+
507+ * po/pt_BR.po: Update translations.
508+
509+2018-03-03 Adhemerval Zanella <adhemerval.zanella@linaro.org>
510+
511+ [BZ #21269]
512+ * sysdeps/unix/sysv/linux/i386/Makefile (tests): Add tst-bz21269.
513+ * sysdeps/unix/sysv/linux/i386/sigaction.c (SET_SA_RESTORER): Clear
514+ sa_restorer for vDSO case.
515+ * sysdeps/unix/sysv/linux/i386/tst-bz21269.c: New file.
516+
517+2018-03-03 Andreas Schwab <schwab@linux-m68k.org>
518+
519+ [BZ #22918]
520+ * nss/nsswitch.h (DEFINE_DATABASE): Don't define __nss_*_database.
521+ * nss/nsswitch.c (DEFINE_DATABASE): Define __nss_*_database here.
522+ * nscd/gai.c (__nss_hosts_database): Readd definition.
523+ * posix/tst-rfc3484.c (__nss_hosts_database): Likewise.
524+ * posix/tst-rfc3484-3.c (__nss_hosts_database): Likewise.
525+ * posix/tst-rfc3484-2.c (__nss_hosts_database): Likewise.
526+
527+2018-03-01 DJ Delorie <dj@delorie.com>
528+
529+ [BZ #22342]
530+ * nscd/netgroupcache.c (addinnetgrX): Include trailing NUL in
531+ key value.
532+
533+2018-02-26 Dmitry V. Levin <ldv@altlinux.org>
534+
535+ [BZ #22433]
536+ [BZ #22807]
537+ * sysdeps/unix/sysv/linux/powerpc/sys/ptrace.h (__ptrace_request): Add
538+ PTRACE_GETREGS, PTRACE_SETREGS, PTRACE_GETFPREGS, PTRACE_SETFPREGS,
539+ PTRACE_GETVRREGS, PTRACE_SETVRREGS, PTRACE_GETEVRREGS,
540+ PTRACE_SETEVRREGS, PTRACE_GETREGS64, PTRACE_SETREGS64,
541+ PTRACE_GET_DEBUGREG, PTRACE_SET_DEBUGREG, PTRACE_GETVSRREGS,
542+ PTRACE_SETVSRREGS, and PTRACE_SINGLEBLOCK.
543+
544+2018-02-26 Tulio Magno Quites Machado Filho <tuliom@linux.vnet.ibm.com>
545+
546+ * sysdeps/unix/sysv/linux/powerpc/sys/ptrace.h: Undefine Linux
547+ macros used in __ptrace_request.
548+
549+2018-02-21 Mike FABIAN <mfabian@redhat.com>
550+
551+ [BZ #22517]
552+ * localedata/locales/et_EE (LC_COLLATE): add missing “reorder-end”
553+
554+2018-02-21 Rical Jasan <ricaljasan@pacific.net>
555+
556+ * io/fcntl.h: Fix a typo in a comment.
557+
558+2018-02-20 Rical Jasan <ricaljasan@pacific.net>
559+
560+ * manual/creature.texi (_ISOC99_SOURCE): Update the dated
561+ description.
562+
563+ [BZ #16335]
564+ * manual/creature.texi (_POSIX_C_SOURCE): Document special values
565+ of 199606L, 200112L, and 200809L.
566+ (_XOPEN_SOURCE): Document special values of 600 and 700.
567+ (_ISOC11_SOURCE): Document macro.
568+ (_ATFILE_SOURCE): Likewise.
569+ (_FORTIFY_SOURCE): Likewise.
570+
571+2018-03-09 Aurelien Jarno <aurelien@aurel32.net>
572+
573+ [BZ #22919]
574+ * sysdeps/unix/sysv/linux/sparc/sparc32/setcontext.S (__startcontext):
575+ Add nop before __startcontext, add explaining comments.
576+
577+2018-03-07 Adhemerval Zanella <adhemerval.zanella@linaro.org>
578+
579+ [BZ #22926]
580+ * sysdeps/powerpc/powerpc32/sysdep.h (ABORT_TRANSACTION_IMPL): Define
581+ empty for __SPE__.
582+ * sysdeps/powerpc/sysdep.h (ABORT_TRANSACTION): Likewise.
583+ * sysdeps/unix/sysv/linux/powerpc/elision-lock.c (__lll_lock_elision):
584+ Do not build hardware transactional code for __SPE__.
585+ * sysdeps/unix/sysv/linux/powerpc/elision-trylock.c
586+ (__lll_trylock_elision): Likewise.
587+ * sysdeps/unix/sysv/linux/powerpc/elision-unlock.c
588+ (__lll_unlock_elision): Likewise.
589+
590+2018-02-19 Rical Jasan <ricaljasan@pacific.net>
591+
592+ [BZ #6889]
593+ * manual/filesys.texi (get_current_dir_name): Clarify behaviour.
594+
595+2018-02-16 Rical Jasan <ricaljasan@pacific.net>
596+
597+ * manual/platform.texi (__riscv_flush_icache): Fix @deftypefun
598+ syntax.
599+
600+2018-02-09 Rical Jasan <ricaljasan@pacific.net>
601+
602+ * manual/creature.texi: Convert references to gcc.info to gcc.
603+ * manual/stdio.texi: Likewise.
604+ * manual/string.texi: Likewise.
605+
606+2018-02-18 Aurelien Jarno <aurelien@aurel32.net>
607+
608+ [BZ #22818]
609+ * posix/tst-glob_lstat_compat.c [__alpha__] (glob): Access
610+ the GLIBC_2.1 version.
611+
612+2018-02-02 Sean McKean <smckean83@gmail.com>
613+
614+ [BZ #22735]
615+ * time/time.h (clock): Reference CLOCKS_PER_SEC in comment.
616+
617+2018-02-10 Dmitry V. Levin <ldv@altlinux.org>
618+
619+ [BZ #22433]
620+ * sysdeps/unix/sysv/linux/aarch64/sys/ptrace.h (__ptrace_request):
621+ Remove arm-specific PTRACE_GET_THREAD_AREA, PTRACE_GETHBPREGS,
622+ and PTRACE_SETHBPREGS.
623+
624+2018-02-14 Adhemerval Zanella <adhemerval.zanella@linaro.org>
625+
626+ * sysdeps/sh/libm-test-ulps: Update.
627+
628+2018-02-09 DJ Delorie <dj@redhat.com>
629+
630+ [BZ #22827]
631+ * sysdeps/unix/sysv/linux/riscv/readelflib.c (process_elf_file): Use
632+ 64-bit ELF type for 64-bit ELF objects.
633+
634+2018-02-07 Igor Gnatenko <ignatenko@redhat.com>
635+
636+ [BZ #22797]
637+ * sysdeps/unix/sysv/linux/bits/mman-shared.h (pkey_get): Add
638+ missing second underscore to parameter name.
639+
640+2018-02-05 H.J. Lu <hongjiu.lu@intel.com>
641+
642+ [BZ #22638]
643+ * sysdeps/sparc/sparc32/start.S (_start): Check PIC instead of
644+ SHARED.
645+ * sysdeps/sparc/sparc64/start.S (_start): Likewise.
646+
647 2018-02-01 Dmitry V. Levin <ldv@altlinux.org>
648
649 * version.h (RELEASE): Set to "stable".
da524a4e 650@@ -710,7 +1351,9 @@
79da3d52
VM
651 2018-01-18 Arjun Shankar <arjun@redhat.com>
652
653 [BZ #22343]
654+ [BZ #22774]
655 CVE-2018-6485
656+ CVE-2018-6551
657 * malloc/malloc.c (checked_request2size): call REQUEST_OUT_OF_RANGE
658 after padding.
659 (_int_memalign): check for integer overflow before calling
da524a4e
VM
660diff --git a/LICENSES b/LICENSES
661index 80f7f14879..858076d9d3 100644
662--- a/LICENSES
663+++ b/LICENSES
664@@ -441,15 +441,6 @@ Permission to use, copy, modify, and distribute this
665 software is freely granted, provided that this notice
666 is preserved.
667 \f
668-Part of stdio-common/tst-printf.c is copyright C E Chew:
669-
670-(C) Copyright C E Chew
671-
672-Feel free to copy, use and distribute this software provided:
673-
674- 1. you do not pretend that you wrote it
675- 2. you leave this copyright notice intact.
676-\f
677 Various long double libm functions are copyright Stephen L. Moshier:
678
679 Copyright 2001 by Stephen L. Moshier <moshier@na-net.ornl.gov>
79da3d52 680diff --git a/NEWS b/NEWS
da524a4e 681index a71c1038a8..e1a23f076b 100644
79da3d52
VM
682--- a/NEWS
683+++ b/NEWS
da524a4e 684@@ -5,6 +5,105 @@ See the end for copying conditions.
79da3d52
VM
685 Please send GNU C library bug reports via <https://sourceware.org/bugzilla/>
686 using `glibc' in the "product" field.
687 \f
688+Version 2.27.1
689+
690+Major new features:
691+
692+* Nominative and genitive month names are now supported for the Catalan and
693+ Czech languages. The Catalan and Greek languages now support abbreviated
694+ alternative month names.
695+
696+* Parsing of dynamic string tokens in DT_RPATH, DT_RUNPATH, DT_NEEDED,
697+ DT_AUXILIARY, and DT_FILTER has been expanded to support the full
698+ range of ELF gABI expressions including such constructs as
699+ '$ORIGIN$ORIGIN' (if valid). For SUID/GUID applications the rules
700+ have been further restricted, and where in the past a dynamic string
701+ token sequence may have been interpreted as a literal string it will
702+ now cause a load failure. These load failures were always considered
703+ unspecified behaviour from the perspective of the dynamic loader, and
704+ for safety are now load errors e.g. /foo/${ORIGIN}.so in DT_NEEDED
705+ results in a load failure now.
706+
707+Security related changes:
708+
709+ CVE-2017-18269: An SSE2-based memmove implementation for the i386
710+ architecture could corrupt memory. Reported by Max Horn.
711+
712+ CVE-2018-11236: Very long pathname arguments to realpath function could
713+ result in an integer overflow and buffer overflow. Reported by Alexey
714+ Izbyshev.
715+
716+ CVE-2018-11237: The mempcpy implementation for the Intel Xeon Phi
717+ architecture could write beyond the target buffer, resulting in a buffer
718+ overflow. Reported by Andreas Schwab.
719+
da524a4e
VM
720+ CVE-2018-19591: A file descriptor leak in if_nametoindex can lead to a
721+ denial of service due to resource exhaustion when processing getaddrinfo
722+ calls with crafted host names. Reported by Guido Vranken.
723+
79da3d52
VM
724+The following bugs are resolved with this release:
725+
726+ [6889] 'PWD' mentioned but not specified
727+ [16335] Feature test macro documentation incomplete and out of date
728+ [17343] Signed integer overflow in /stdlib/random_r.c
729+ [18018] Additional $ORIGIN handling issues (CVE-2011-0536)
730+ [20419] files with large allocated notes crash in open_verify
731+ [21269] i386 sigaction sa_restorer handling is wrong
da524a4e 732+ [21812] getifaddrs: Don't return ifa entries with NULL names
79da3d52
VM
733+ [21942] _dl_dst_substitute incorrectly handles $ORIGIN: with AT_SECURE=1
734+ [22342] NSCD not properly caching netgroup
735+ [22638] sparc: static binaries are broken if glibc is built by gcc
736+ configured with --enable-default-pie
737+ [22644] memmove-sse2-unaligned on 32bit x86 produces garbage when crossing
738+ 2GB threshold
739+ [22735] Misleading typo in time.h source comment regarding CLOCKS_PER_SECOND
da524a4e 740+ [22753] libc: preadv2/pwritev2 fallback code should handle offset=-1
79da3d52
VM
741+ [22786] Stack buffer overflow in realpath() if input size is close
742+ to SSIZE_MAX
743+ [22797] Linux: use reserved name __key in pkey_get
744+ [22807] PTRACE_* constants missing for powerpc
745+ [22818] posix/tst-glob_lstat_compat failure on alpha
746+ [22827] RISC-V ELF64 parser mis-reads flag in ldconfig
747+ [22848] ca_ES: update date definitions from CLDR
748+ [22884] RISCV fmax/fmin handle signalling NANs incorrectly
749+ [22918] multiple common of `__nss_shadow_database'
750+ [22919] sparc32: backtrace yields infinite backtrace with makecontext
751+ [22926] FTBFS on powerpcspe
da524a4e 752+ [22927] libanl: properly cleanup if first helper thread creation failed
79da3d52
VM
753+ [22932] lt_LT: Update of abbreviated month names from CLDR required
754+ [22937] Greek (el_GR, el_CY) locales actually need ab_alt_mon
755+ [22947] FAIL: misc/tst-preadvwritev2
756+ [22963] cs_CZ: Add alternative month names
da524a4e 757+ [22996] localedata: change LC_PAPER to en_US in es_BO locale
79da3d52 758+ [23005] Crash in __res_context_send after memory allocation failure
da524a4e 759+ [23036] regexec: Fix off-by-one bug in weight comparison
79da3d52
VM
760+ [23037] initialize msg_flags to zero for sendmmsg() calls
761+ [23069] sigaction broken on riscv64-linux-gnu
762+ [23102] Incorrect parsing of consecutive $ variables in runpath entries
763+ [23137] s390: pthread_join sometimes block indefinitely (on 31bit and libc
764+ build with -Os)
765+ [23152] gd_GB: Fix typo in "May" (abbreviated)
766+ [23166] sunrpc: Remove stray exports without --enable-obsolete-rpc
767+ [23171] Fix parameter type in C++ version of iseqsig
768+ [23196] __mempcpy_avx512_no_vzeroupper mishandles large copies
769+ [23236] Harden function pointers in _IO_str_fields
da524a4e 770+ [23253] Set 387 and SSE2 rounding mode for tgamma on i386
79da3d52
VM
771+ [23259] Unsubstituted ${ORIGIN} remains in DT_NEEDED for AT_SECURE
772+ [23264] libc: posix_spawnp wrongly executes ENOEXEC in non compat mode
da524a4e
VM
773+ [23313] libio: Disable vtable validation in case of interposition
774+ [23349] Various glibc headers no longer compatible with <linux/time.h>
775+ [23363] stdio-common/tst-printf.c has non-free license
776+ [23456] Wrong index_cpu_LZCNT
777+ [23459] COMMON_CPUID_INDEX_80000001 isn't populated for Intel processors
778+ [23538] pthread_cond_broadcast: Fix waiters-after-spinning case
779+ [23562] signal: Use correct type for si_band in siginfo_t
780+ [23579] libc: Errors misreported in preadv2
781+ [23709] Fix CPU string flags for Haswell-type CPUs
782+ [23821] si_band in siginfo_t has wrong type long int on sparc64
783+ [23822] ia64 static libm.a is missing exp2f, log2f and powf symbols
784+ [23927] Linux if_nametoindex() does not close descriptor (CVE-2018-19591)
79da3d52
VM
785+
786+\f
787 Version 2.27
788
789 Major new features:
da524a4e 790@@ -262,6 +361,10 @@ Security related changes:
79da3d52
VM
791 an object size near the value of SIZE_MAX, would return a pointer to a
792 buffer which is too small, instead of NULL. Reported by Jakub Wilk.
793
794+ CVE-2018-6551: The malloc function, when called with an object size near
795+ the value of SIZE_MAX, would return a pointer to a buffer which is too
796+ small, instead of NULL.
797+
798 The following bugs are resolved with this release:
799
800 [866] glob: glob should match dangling symlinks
801diff --git a/bits/uio-ext.h b/bits/uio-ext.h
802index 8c15a05d9a..d5aa06fd08 100644
803--- a/bits/uio-ext.h
804+++ b/bits/uio-ext.h
805@@ -28,5 +28,6 @@
806 #define RWF_DSYNC 0x00000002 /* per-IO O_DSYNC. */
807 #define RWF_SYNC 0x00000004 /* per-IO O_SYNC. */
808 #define RWF_NOWAIT 0x00000008 /* per-IO nonblocking mode. */
809+#define RWF_APPEND 0x00000010 /* per-IO O_APPEND. */
810
811 #endif /* sys/uio_ext.h */
da524a4e
VM
812diff --git a/conform/conformtest.pl b/conform/conformtest.pl
813index cb500f0e76..a4ef756105 100644
814--- a/conform/conformtest.pl
815+++ b/conform/conformtest.pl
816@@ -367,7 +367,7 @@ while ($#headers >= 0) {
817 s/^optional-//;
818 $optional = 1;
819 }
820- if (/^element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
821+ if (/^element *(\{([^}]*)\}|([^{ ]*)) *(\{([^}]*)\}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
822 my($struct) = "$2$3";
823 my($type) = "$5$6";
824 my($member) = "$7";
825@@ -556,7 +556,7 @@ while ($#headers >= 0) {
826 "Symbol \"$symbol\" has not the right value.", $res,
827 $xfail);
828 }
829- } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
830+ } elsif (/^type *(\{([^}]*)|([a-zA-Z0-9_]*))/) {
831 my($type) = "$2$3";
832 my($maybe_opaque) = 0;
833
834@@ -586,7 +586,7 @@ while ($#headers >= 0) {
835 ? "NOT AVAILABLE"
836 : "Type \"$type\" not available."), $missing, $optional,
837 $xfail);
838- } elsif (/^tag *({([^}]*)|([a-zA-Z0-9_]*))/) {
839+ } elsif (/^tag *(\{([^}]*)|([a-zA-Z0-9_]*))/) {
840 my($type) = "$2$3";
841
842 # Remember that this name is allowed.
843@@ -607,7 +607,7 @@ while ($#headers >= 0) {
844
845 compiletest ($fnamebase, "Testing for type $type",
846 "Type \"$type\" not available.", $missing, 0, $xfail);
847- } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
848+ } elsif (/^function *(\{([^}]*)\}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
849 my($rettype) = "$2$3";
850 my($fname) = "$4";
851 my($args) = "$5";
852@@ -644,7 +644,7 @@ while ($#headers >= 0) {
853 "Function \"$fname\" has incorrect type.", $res, 0,
854 $xfail);
855 }
856- } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
857+ } elsif (/^function *(\{([^}]*)\}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
858 my($rettype) = "$2$3";
859 my($fname) = "$4";
860 my($args) = "$5";
861@@ -681,7 +681,7 @@ while ($#headers >= 0) {
862 "Function \"$fname\" has incorrect type.", $res, 0,
863 $xfail);
864 }
865- } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) *(.*)/) {
866+ } elsif (/^variable *(\{([^}]*)\}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) *(.*)/) {
867 my($type) = "$2$3";
868 my($vname) = "$4";
869 my($rest) = "$5";
870@@ -713,7 +713,7 @@ while ($#headers >= 0) {
871
872 compiletest ($fnamebase, "Test for type of variable $fname",
873 "Variable \"$vname\" has incorrect type.", $res, 0, $xfail);
874- } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
875+ } elsif (/^macro-function *(\{([^}]*)\}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
876 my($rettype) = "$2$3";
877 my($fname) = "$4";
878 my($args) = "$5";
879@@ -812,11 +812,11 @@ while ($#headers >= 0) {
880
881 s/^xfail(\[([^\]]*)\])?-//;
882 s/^optional-//;
883- if (/^element *({([^}]*)}|([^ ]*)) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
884+ if (/^element *(\{([^}]*)\}|([^ ]*)) *(\{([^}]*)\}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
885 push @allow, $7;
886 } elsif (/^(macro|constant|macro-constant|macro-int-constant) +([a-zA-Z0-9_]*) *(?:{([^}]*)} *)?(?:([>=<!]+) ([A-Za-z0-9_-]*))?/) {
887 push @allow, $2;
888- } elsif (/^(type|tag) *({([^}]*)|([a-zA-Z0-9_]*))/) {
889+ } elsif (/^(type|tag) *(\{([^}]*)|([a-zA-Z0-9_]*))/) {
890 my($type) = "$3$4";
891
892 # Remember that this name is allowed.
893@@ -827,13 +827,13 @@ while ($#headers >= 0) {
894 } else {
895 push @allow, $type;
896 }
897- } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
898+ } elsif (/^function *(\{([^}]*)\}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
899 push @allow, $4;
900- } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
901+ } elsif (/^function *(\{([^}]*)\}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
902 push @allow, $4;
903- } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) {
904+ } elsif (/^variable *(\{([^}]*)\}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) {
905 push @allow, $4;
906- } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
907+ } elsif (/^macro-function *(\{([^}]*)\}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
908 push @allow, $4;
909 } elsif (/^symbol *([a-zA-Z0-9_]*) *([A-Za-z0-9_-]*)?/) {
910 push @allow, $1;
911diff --git a/conform/data/signal.h-data b/conform/data/signal.h-data
912index fa841cfdbe..88c1f5eba2 100644
913--- a/conform/data/signal.h-data
914+++ b/conform/data/signal.h-data
915@@ -170,7 +170,8 @@ element siginfo_t pid_t si_pid
916 element siginfo_t uid_t si_uid
917 element siginfo_t {void*} si_addr
918 element siginfo_t int si_status
919-element siginfo_t long si_band
920+// Bug 23821: si_band has type int on sparc64.
921+xfail[sparc64-linux]-element siginfo_t long si_band
922 # endif
923 # ifndef XPG42
924 element siginfo_t {union sigval} si_value
925diff --git a/conform/data/sys/wait.h-data b/conform/data/sys/wait.h-data
926index 559ebdf677..a6713461ea 100644
927--- a/conform/data/sys/wait.h-data
928+++ b/conform/data/sys/wait.h-data
929@@ -44,7 +44,8 @@ element siginfo_t pid_t si_pid
930 element siginfo_t uid_t si_uid
931 element siginfo_t {void*} si_addr
932 element siginfo_t int si_status
933-element siginfo_t long si_band
934+// Bug 23821: si_band has type int on sparc64.
935+xfail[sparc64-linux]-element siginfo_t long si_band
936 # ifndef XPG42
937 element siginfo_t {union sigval} si_value
938 # endif
79da3d52
VM
939diff --git a/debug/vasprintf_chk.c b/debug/vasprintf_chk.c
940index a00ef771e6..3eb64617fd 100644
941--- a/debug/vasprintf_chk.c
942+++ b/debug/vasprintf_chk.c
943@@ -55,8 +55,8 @@ __vasprintf_chk (char **result_ptr, int flags, const char *format,
944 _IO_JUMPS (&sf._sbf) = &_IO_str_jumps;
945 _IO_str_init_static_internal (&sf, string, init_string_size, string);
946 sf._sbf._f._flags &= ~_IO_USER_BUF;
947- sf._s._allocate_buffer = (_IO_alloc_type) malloc;
948- sf._s._free_buffer = (_IO_free_type) free;
949+ sf._s._allocate_buffer_unused = (_IO_alloc_type) malloc;
950+ sf._s._free_buffer_unused = (_IO_free_type) free;
951
952 /* For flags > 0 (i.e. __USE_FORTIFY_LEVEL > 1) request that %n
953 can only come from read-only format strings. */
954diff --git a/elf/Makefile b/elf/Makefile
955index 2a432d8bee..2d8fe88aa6 100644
956--- a/elf/Makefile
957+++ b/elf/Makefile
958@@ -187,7 +187,7 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \
959 tst-tlsalign tst-tlsalign-extern tst-nodelete-opened \
960 tst-nodelete2 tst-audit11 tst-audit12 tst-dlsym-error tst-noload \
961 tst-latepthread tst-tls-manydynamic tst-nodelete-dlclose \
962- tst-debug1 tst-main1
963+ tst-debug1 tst-main1 tst-big-note
964 # reldep9
965 tests-internal += loadtest unload unload2 circleload1 \
966 neededtest neededtest2 neededtest3 neededtest4 \
967@@ -272,7 +272,9 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
968 tst-audit12mod1 tst-audit12mod2 tst-audit12mod3 tst-auditmod12 \
969 tst-latepthreadmod $(tst-tls-many-dynamic-modules) \
970 tst-nodelete-dlclose-dso tst-nodelete-dlclose-plugin \
971- tst-main1mod tst-libc_dlvsym-dso
972+ tst-main1mod tst-libc_dlvsym-dso \
973+ tst-big-note-lib
974+
975 ifeq (yes,$(have-mtls-dialect-gnu2))
976 tests += tst-gnu2-tls1
977 modules-names += tst-gnu2-tls1mod
978@@ -1446,3 +1448,5 @@ $(objpfx)tst-libc_dlvsym-static: $(common-objpfx)dlfcn/libdl.a
979 tst-libc_dlvsym-static-ENV = \
980 LD_LIBRARY_PATH=$(objpfx):$(common-objpfx):$(common-objpfx)dlfcn
981 $(objpfx)tst-libc_dlvsym-static.out: $(objpfx)tst-libc_dlvsym-dso.so
982+
983+$(objpfx)tst-big-note: $(objpfx)tst-big-note-lib.so
984diff --git a/elf/dl-deps.c b/elf/dl-deps.c
985index c975fcffd7..20b8e94f2e 100644
986--- a/elf/dl-deps.c
987+++ b/elf/dl-deps.c
988@@ -100,7 +100,7 @@ struct list
989 ({ \
990 const char *__str = (str); \
991 const char *__result = __str; \
992- size_t __dst_cnt = DL_DST_COUNT (__str); \
993+ size_t __dst_cnt = _dl_dst_count (__str); \
994 \
995 if (__dst_cnt != 0) \
996 { \
997diff --git a/elf/dl-dst.h b/elf/dl-dst.h
998index 32de5d225a..859032be0d 100644
999--- a/elf/dl-dst.h
1000+++ b/elf/dl-dst.h
1001@@ -18,19 +18,6 @@
1002
1003 #include "trusted-dirs.h"
1004
1005-/* Determine the number of DST elements in the name. Only if IS_PATH is
1006- nonzero paths are recognized (i.e., multiple, ':' separated filenames). */
1007-#define DL_DST_COUNT(name) \
1008- ({ \
1009- size_t __cnt = 0; \
1010- const char *__sf = strchr (name, '$'); \
1011- \
1012- if (__glibc_unlikely (__sf != NULL)) \
1013- __cnt = _dl_dst_count (__sf); \
1014- \
1015- __cnt; })
1016-
1017-
1018 #ifdef SHARED
1019 # define IS_RTLD(l) (l) == &GL(dl_rtld_map)
1020 #else
1021diff --git a/elf/dl-load.c b/elf/dl-load.c
1022index 7554a99b5a..b20e2a46d0 100644
1023--- a/elf/dl-load.c
1024+++ b/elf/dl-load.c
1025@@ -122,12 +122,6 @@ is_trusted_path_normalize (const char *path, size_t len)
1026 if (len == 0)
1027 return false;
1028
1029- if (*path == ':')
1030- {
1031- ++path;
1032- --len;
1033- }
1034-
1035 char *npath = (char *) alloca (len + 2);
1036 char *wnp = npath;
1037 while (*path != '\0')
1038@@ -178,114 +172,165 @@ is_trusted_path_normalize (const char *path, size_t len)
1039 return false;
1040 }
1041
1042+/* Given a substring starting at INPUT, just after the DST '$' start
1043+ token, determine if INPUT contains DST token REF, following the
1044+ ELF gABI rules for DSTs:
1045+
1046+ * Longest possible sequence using the rules (greedy).
1047
1048+ * Must start with a $ (enforced by caller).
1049+
1050+ * Must follow $ with one underscore or ASCII [A-Za-z] (caller
1051+ follows these rules for REF) or '{' (start curly quoted name).
1052+
1053+ * Must follow first two characters with zero or more [A-Za-z0-9_]
1054+ (enforced by caller) or '}' (end curly quoted name).
1055+
1056+ If the sequence is a DST matching REF then the length of the DST
1057+ (excluding the $ sign but including curly braces, if any) is
1058+ returned, otherwise 0. */
1059 static size_t
1060-is_dst (const char *start, const char *name, const char *str, int secure)
1061+is_dst (const char *input, const char *ref)
1062 {
1063- size_t len;
1064 bool is_curly = false;
1065
1066- if (name[0] == '{')
1067+ /* Is a ${...} input sequence? */
1068+ if (input[0] == '{')
1069 {
1070 is_curly = true;
1071- ++name;
1072- }
1073-
1074- len = 0;
1075- while (name[len] == str[len] && name[len] != '\0')
1076- ++len;
1077-
1078- if (is_curly)
1079- {
1080- if (name[len] != '}')
1081- return 0;
1082-
1083- /* Point again at the beginning of the name. */
1084- --name;
1085- /* Skip over closing curly brace and adjust for the --name. */
1086- len += 2;
1087+ ++input;
1088 }
1089- else if (name[len] != '\0' && name[len] != '/')
1090- return 0;
1091
1092- if (__glibc_unlikely (secure)
1093- && ((name[len] != '\0' && name[len] != '/')
1094- || (name != start + 1)))
1095+ /* Check for matching name, following closing curly brace (if
1096+ required), or trailing characters which are part of an
1097+ identifier. */
1098+ size_t rlen = strlen (ref);
1099+ if (strncmp (input, ref, rlen) != 0
1100+ || (is_curly && input[rlen] != '}')
1101+ || ((input[rlen] >= 'A' && input[rlen] <= 'Z')
1102+ || (input[rlen] >= 'a' && input[rlen] <= 'z')
1103+ || (input[rlen] >= '0' && input[rlen] <= '9')
1104+ || (input[rlen] == '_')))
1105 return 0;
1106
1107- return len;
1108+ if (is_curly)
1109+ /* Count the two curly braces. */
1110+ return rlen + 2;
1111+ else
1112+ return rlen;
1113 }
1114
1115-
1116+/* INPUT is the start of a DST sequence at the first '$' occurrence.
1117+ If there is a DST we call into _dl_dst_count to count the number of
1118+ DSTs. We count all known DSTs regardless of __libc_enable_secure;
1119+ the caller is responsible for enforcing the security of the
1120+ substitution rules (usually _dl_dst_substitute). */
1121 size_t
1122-_dl_dst_count (const char *name)
1123+_dl_dst_count (const char *input)
1124 {
1125- const char *const start = name;
1126 size_t cnt = 0;
1127
1128+ input = strchr (input, '$');
1129+
1130+ /* Most likely there is no DST. */
1131+ if (__glibc_likely (input == NULL))
1132+ return 0;
1133+
1134 do
1135 {
1136 size_t len;
1137
1138- /* $ORIGIN is not expanded for SUID/GUID programs (except if it
1139- is $ORIGIN alone) and it must always appear first in path. */
1140- ++name;
1141- if ((len = is_dst (start, name, "ORIGIN", __libc_enable_secure)) != 0
1142- || (len = is_dst (start, name, "PLATFORM", 0)) != 0
1143- || (len = is_dst (start, name, "LIB", 0)) != 0)
1144+ ++input;
1145+ /* All DSTs must follow ELF gABI rules, see is_dst (). */
1146+ if ((len = is_dst (input, "ORIGIN")) != 0
1147+ || (len = is_dst (input, "PLATFORM")) != 0
1148+ || (len = is_dst (input, "LIB")) != 0)
1149 ++cnt;
1150
1151- name = strchr (name + len, '$');
1152+ /* There may be more than one DST in the input. */
1153+ input = strchr (input + len, '$');
1154 }
1155- while (name != NULL);
1156+ while (input != NULL);
1157
1158 return cnt;
1159 }
1160
1161-
1162+/* Process INPUT for DSTs and store in RESULT using the information
1163+ from link map L to resolve the DSTs. This function only handles one
1164+ path at a time and does not handle colon-separated path lists (see
1165+ fillin_rpath ()). Lastly the size of result in bytes should be at
1166+ least equal to the value returned by DL_DST_REQUIRED. Note that it
1167+ is possible for a DT_NEEDED, DT_AUXILIARY, and DT_FILTER entries to
1168+ have colons, but we treat those as literal colons here, not as path
1169+ list delimeters. */
1170 char *
1171-_dl_dst_substitute (struct link_map *l, const char *name, char *result)
1172+_dl_dst_substitute (struct link_map *l, const char *input, char *result)
1173 {
1174- const char *const start = name;
1175-
1176- /* Now fill the result path. While copying over the string we keep
1177- track of the start of the last path element. When we come across
1178- a DST we copy over the value or (if the value is not available)
1179- leave the entire path element out. */
1180+ /* Copy character-by-character from input into the working pointer
1181+ looking for any DSTs. We track the start of input and if we are
1182+ going to check for trusted paths, all of which are part of $ORIGIN
1183+ handling in SUID/SGID cases (see below). In some cases, like when
1184+ a DST cannot be replaced, we may set result to an empty string and
1185+ return. */
1186 char *wp = result;
1187- char *last_elem = result;
1188+ const char *start = input;
1189 bool check_for_trusted = false;
1190
1191 do
1192 {
1193- if (__glibc_unlikely (*name == '$'))
1194+ if (__glibc_unlikely (*input == '$'))
1195 {
1196 const char *repl = NULL;
1197 size_t len;
1198
1199- ++name;
1200- if ((len = is_dst (start, name, "ORIGIN", __libc_enable_secure)) != 0)
1201+ ++input;
1202+ if ((len = is_dst (input, "ORIGIN")) != 0)
1203 {
1204- repl = l->l_origin;
1205+ /* For SUID/GUID programs we normally ignore the path with
1206+ $ORIGIN in DT_RUNPATH, or DT_RPATH. However, there is
1207+ one exception to this rule, and it is:
1208+
1209+ * $ORIGIN appears as the first path element, and is
1210+ the only string in the path or is immediately
1211+ followed by a path separator and the rest of the
1212+ path.
1213+
1214+ * The path is rooted in a trusted directory.
1215+
1216+ This exception allows such programs to reference
1217+ shared libraries in subdirectories of trusted
1218+ directories. The use case is one of general
1219+ organization and deployment flexibility.
1220+ Trusted directories are usually such paths as "/lib64"
1221+ or "/usr/lib64", and the usual RPATHs take the form of
1222+ [$ORIGIN/../$LIB/somedir]. */
1223+ if (__glibc_unlikely (__libc_enable_secure)
1224+ && !(input == start + 1
1225+ && (input[len] == '\0' || input[len] == '/')))
1226+ repl = (const char *) -1;
1227+ else
1228+ repl = l->l_origin;
1229+
1230 check_for_trusted = (__libc_enable_secure
1231 && l->l_type == lt_executable);
1232 }
1233- else if ((len = is_dst (start, name, "PLATFORM", 0)) != 0)
1234+ else if ((len = is_dst (input, "PLATFORM")) != 0)
1235 repl = GLRO(dl_platform);
1236- else if ((len = is_dst (start, name, "LIB", 0)) != 0)
1237+ else if ((len = is_dst (input, "LIB")) != 0)
1238 repl = DL_DST_LIB;
1239
1240 if (repl != NULL && repl != (const char *) -1)
1241 {
1242 wp = __stpcpy (wp, repl);
1243- name += len;
1244+ input += len;
1245 }
1246- else if (len > 1)
1247+ else if (len != 0)
1248 {
1249- /* We cannot use this path element, the value of the
1250- replacement is unknown. */
1251- wp = last_elem;
1252- break;
1253+ /* We found a valid DST that we know about, but we could
1254+ not find a replacement value for it, therefore we
1255+ cannot use this path and discard it. */
1256+ *result = '\0';
1257+ return result;
1258 }
1259 else
1260 /* No DST we recognize. */
1261@@ -293,16 +338,26 @@ _dl_dst_substitute (struct link_map *l, const char *name, char *result)
1262 }
1263 else
1264 {
1265- *wp++ = *name++;
1266+ *wp++ = *input++;
1267 }
1268 }
1269- while (*name != '\0');
1270+ while (*input != '\0');
1271
1272 /* In SUID/SGID programs, after $ORIGIN expansion the normalized
1273- path must be rooted in one of the trusted directories. */
1274+ path must be rooted in one of the trusted directories. The $LIB
1275+ and $PLATFORM DST cannot in any way be manipulated by the caller
1276+ because they are fixed values that are set by the dynamic loader
1277+ and therefore any paths using just $LIB or $PLATFORM need not be
1278+ checked for trust, the authors of the binaries themselves are
1279+ trusted to have designed this correctly. Only $ORIGIN is tested in
1280+ this way because it may be manipulated in some ways with hard
1281+ links. */
1282 if (__glibc_unlikely (check_for_trusted)
1283- && !is_trusted_path_normalize (last_elem, wp - last_elem))
1284- wp = last_elem;
1285+ && !is_trusted_path_normalize (result, wp - result))
1286+ {
1287+ *result = '\0';
1288+ return result;
1289+ }
1290
1291 *wp = '\0';
1292
1293@@ -310,13 +365,13 @@ _dl_dst_substitute (struct link_map *l, const char *name, char *result)
1294 }
1295
1296
1297-/* Return copy of argument with all recognized dynamic string tokens
1298- ($ORIGIN and $PLATFORM for now) replaced. On some platforms it
1299- might not be possible to determine the path from which the object
1300- belonging to the map is loaded. In this case the path element
1301- containing $ORIGIN is left out. */
1302+/* Return a malloc allocated copy of INPUT with all recognized DSTs
1303+ replaced. On some platforms it might not be possible to determine the
1304+ path from which the object belonging to the map is loaded. In this
1305+ case the path containing the DST is left out. On error NULL
1306+ is returned. */
1307 static char *
1308-expand_dynamic_string_token (struct link_map *l, const char *s)
1309+expand_dynamic_string_token (struct link_map *l, const char *input)
1310 {
1311 /* We make two runs over the string. First we determine how large the
1312 resulting string is and then we copy it over. Since this is no
1313@@ -326,22 +381,22 @@ expand_dynamic_string_token (struct link_map *l, const char *s)
1314 size_t total;
1315 char *result;
1316
1317- /* Determine the number of DST elements. */
1318- cnt = DL_DST_COUNT (s);
1319+ /* Determine the number of DSTs. */
1320+ cnt = _dl_dst_count (input);
1321
1322 /* If we do not have to replace anything simply copy the string. */
1323 if (__glibc_likely (cnt == 0))
1324- return __strdup (s);
1325+ return __strdup (input);
1326
1327 /* Determine the length of the substituted string. */
1328- total = DL_DST_REQUIRED (l, s, strlen (s), cnt);
1329+ total = DL_DST_REQUIRED (l, input, strlen (input), cnt);
1330
1331 /* Allocate the necessary memory. */
1332 result = (char *) malloc (total + 1);
1333 if (result == NULL)
1334 return NULL;
1335
1336- return _dl_dst_substitute (l, s, result);
1337+ return _dl_dst_substitute (l, input, result);
1338 }
1339
1340
1341@@ -1469,6 +1524,7 @@ open_verify (const char *name, int fd,
1342 ElfW(Ehdr) *ehdr;
1343 ElfW(Phdr) *phdr, *ph;
1344 ElfW(Word) *abi_note;
1345+ ElfW(Word) *abi_note_malloced = NULL;
1346 unsigned int osversion;
1347 size_t maplength;
1348
1349@@ -1640,10 +1696,25 @@ open_verify (const char *name, int fd,
1350 abi_note = (void *) (fbp->buf + ph->p_offset);
1351 else
1352 {
1353- abi_note = alloca (size);
1354+ /* Note: __libc_use_alloca is not usable here, because
1355+ thread info may not have been set up yet. */
1356+ if (size < __MAX_ALLOCA_CUTOFF)
1357+ abi_note = alloca (size);
1358+ else
1359+ {
1360+ /* There could be multiple PT_NOTEs. */
1361+ abi_note_malloced = realloc (abi_note_malloced, size);
1362+ if (abi_note_malloced == NULL)
1363+ goto read_error;
1364+
1365+ abi_note = abi_note_malloced;
1366+ }
1367 __lseek (fd, ph->p_offset, SEEK_SET);
1368 if (__libc_read (fd, (void *) abi_note, size) != size)
1369- goto read_error;
1370+ {
1371+ free (abi_note_malloced);
1372+ goto read_error;
1373+ }
1374 }
1375
1376 while (memcmp (abi_note, &expected_note, sizeof (expected_note)))
1377@@ -1678,6 +1749,7 @@ open_verify (const char *name, int fd,
1378
1379 break;
1380 }
1381+ free (abi_note_malloced);
1382 }
1383
1384 return fd;
1385diff --git a/elf/tst-big-note-lib.S b/elf/tst-big-note-lib.S
1386new file mode 100644
1387index 0000000000..6b514a03cc
1388--- /dev/null
1389+++ b/elf/tst-big-note-lib.S
1390@@ -0,0 +1,26 @@
1391+/* Bug 20419: test for stack overflow in elf/dl-load.c open_verify()
1392+ Copyright (C) 2018 Free Software Foundation, Inc.
1393+ This file is part of the GNU C Library.
1394+
1395+ The GNU C Library is free software; you can redistribute it and/or
1396+ modify it under the terms of the GNU Lesser General Public
1397+ License as published by the Free Software Foundation; either
1398+ version 2.1 of the License, or (at your option) any later version.
1399+
1400+ The GNU C Library is distributed in the hope that it will be useful,
1401+ but WITHOUT ANY WARRANTY; without even the implied warranty of
1402+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1403+ Lesser General Public License for more details.
1404+
1405+ You should have received a copy of the GNU Lesser General Public
1406+ License along with the GNU C Library; if not, see
1407+ <http://www.gnu.org/licenses/>. */
1408+
1409+/* This creates a .so with 8MiB PT_NOTE segment.
1410+ On a typical Linux system with 8MiB "ulimit -s", that was enough
1411+ to trigger stack overflow in open_verify. */
1412+
1413+.pushsection .note.big,"a"
1414+.balign 4
1415+.fill 8*1024*1024, 1, 0
1416+.popsection
1417diff --git a/elf/tst-big-note.c b/elf/tst-big-note.c
1418new file mode 100644
1419index 0000000000..fcd2b0ed82
1420--- /dev/null
1421+++ b/elf/tst-big-note.c
1422@@ -0,0 +1,26 @@
1423+/* Bug 20419: test for stack overflow in elf/dl-load.c open_verify()
1424+ Copyright (C) 2018 Free Software Foundation, Inc.
1425+ This file is part of the GNU C Library.
1426+
1427+ The GNU C Library is free software; you can redistribute it and/or
1428+ modify it under the terms of the GNU Lesser General Public
1429+ License as published by the Free Software Foundation; either
1430+ version 2.1 of the License, or (at your option) any later version.
1431+
1432+ The GNU C Library is distributed in the hope that it will be useful,
1433+ but WITHOUT ANY WARRANTY; without even the implied warranty of
1434+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1435+ Lesser General Public License for more details.
1436+
1437+ You should have received a copy of the GNU Lesser General Public
1438+ License along with the GNU C Library; if not, see
1439+ <http://www.gnu.org/licenses/>. */
1440+
1441+/* This file must be run from within a directory called "elf". */
1442+
1443+int main (int argc, char *argv[])
1444+{
1445+ /* Nothing to do here: merely linking against tst-big-note-lib.so triggers
1446+ the bug. */
1447+ return 0;
1448+}
1449diff --git a/include/rpc/clnt.h b/include/rpc/clnt.h
1450index a397023a93..80be0a9cec 100644
1451--- a/include/rpc/clnt.h
1452+++ b/include/rpc/clnt.h
1453@@ -28,6 +28,7 @@ libc_hidden_proto (clntudp_create)
1454 libc_hidden_proto (get_myaddress)
1455 libc_hidden_proto (clntunix_create)
1456 libc_hidden_proto (__libc_clntudp_bufcreate)
1457+libc_hidden_proto (rpc_createerr)
1458
1459 # endif /* !_ISOMAC */
1460 #endif
1461diff --git a/include/rpc/svc.h b/include/rpc/svc.h
1462index 465bf4427d..40ba2546a9 100644
1463--- a/include/rpc/svc.h
1464+++ b/include/rpc/svc.h
1465@@ -3,6 +3,10 @@
1466
1467 # ifndef _ISOMAC
1468
1469+libc_hidden_proto (svc_pollfd)
1470+libc_hidden_proto (svc_max_pollfd)
1471+libc_hidden_proto (svc_fdset)
1472+
1473 libc_hidden_proto (xprt_register)
1474 libc_hidden_proto (xprt_unregister)
1475 libc_hidden_proto (svc_register)
1476diff --git a/include/unistd.h b/include/unistd.h
1477index 0f91b8babc..a171b00326 100644
1478--- a/include/unistd.h
1479+++ b/include/unistd.h
1480@@ -77,6 +77,8 @@ extern char *__getcwd (char *__buf, size_t __size) attribute_hidden;
1481 extern int __rmdir (const char *__path) attribute_hidden;
1482 extern int __execvpe (const char *file, char *const argv[],
1483 char *const envp[]) attribute_hidden;
1484+extern int __execvpex (const char *file, char *const argv[],
1485+ char *const envp[]) attribute_hidden;
1486
1487 /* Get the canonical absolute name of the named directory, and put it in SIZE
1488 bytes of BUF. Returns NULL if the directory couldn't be determined or
1489diff --git a/io/fcntl.h b/io/fcntl.h
1490index 3d239e8f09..69a4394191 100644
1491--- a/io/fcntl.h
1492+++ b/io/fcntl.h
1493@@ -139,7 +139,7 @@ typedef __pid_t pid_t;
1494 # define SEEK_END 2 /* Seek from end of file. */
1495 #endif /* XPG */
1496
1497-/* The constants AT_REMOVEDIR and AT_EACCESS have the same value. AT_EASSESS
1498+/* The constants AT_REMOVEDIR and AT_EACCESS have the same value. AT_EACCESS
1499 is meaningful only to faccessat, while AT_REMOVEDIR is meaningful only to
1500 unlinkat. The two functions do completely different things and therefore,
1501 the flags can be allowed to overlap. For example, passing AT_REMOVEDIR to
da524a4e
VM
1502diff --git a/libio/Makefile b/libio/Makefile
1503index 918a86bb74..81bd1792a5 100644
1504--- a/libio/Makefile
1505+++ b/libio/Makefile
1506@@ -64,6 +64,9 @@ tests = tst_swprintf tst_wprintf tst_swscanf tst_wscanf tst_getwc tst_putwc \
1507 tst-setvbuf1 tst-popen1 tst-fgetwc bug-wsetpos tst-fseek \
1508 tst-fwrite-error tst-ftell-partial-wide tst-ftell-active-handler \
1509 tst-ftell-append tst-fputws tst-bz22415
1510+
1511+tests-internal = tst-vtables tst-vtables-interposed
1512+
1513 ifeq (yes,$(build-shared))
1514 # Add test-fopenloc only if shared library is enabled since it depends on
1515 # shared localedata objects.
79da3d52
VM
1516diff --git a/libio/memstream.c b/libio/memstream.c
1517index d86befcc02..c5c7c2f6db 100644
1518--- a/libio/memstream.c
1519+++ b/libio/memstream.c
1520@@ -90,8 +90,8 @@ __open_memstream (char **bufloc, _IO_size_t *sizeloc)
1521 _IO_JUMPS_FILE_plus (&new_f->fp._sf._sbf) = &_IO_mem_jumps;
1522 _IO_str_init_static_internal (&new_f->fp._sf, buf, _IO_BUFSIZ, buf);
1523 new_f->fp._sf._sbf._f._flags &= ~_IO_USER_BUF;
1524- new_f->fp._sf._s._allocate_buffer = (_IO_alloc_type) malloc;
1525- new_f->fp._sf._s._free_buffer = (_IO_free_type) free;
1526+ new_f->fp._sf._s._allocate_buffer_unused = (_IO_alloc_type) malloc;
1527+ new_f->fp._sf._s._free_buffer_unused = (_IO_free_type) free;
1528
1529 new_f->fp.bufloc = bufloc;
1530 new_f->fp.sizeloc = sizeloc;
1531diff --git a/libio/strfile.h b/libio/strfile.h
1532index 68dfcbfe83..52a085e580 100644
1533--- a/libio/strfile.h
1534+++ b/libio/strfile.h
1535@@ -31,8 +31,11 @@ typedef void (*_IO_free_type) (void*);
1536
1537 struct _IO_str_fields
1538 {
1539- _IO_alloc_type _allocate_buffer;
1540- _IO_free_type _free_buffer;
1541+ /* These members are preserved for ABI compatibility. The glibc
1542+ implementation always calls malloc/free for user buffers if
1543+ _IO_USER_BUF or _IO_FLAGS2_USER_WBUF are not set. */
1544+ _IO_alloc_type _allocate_buffer_unused;
1545+ _IO_free_type _free_buffer_unused;
1546 };
1547
1548 /* This is needed for the Irix6 N32 ABI, which has a 64 bit off_t type,
1549@@ -52,10 +55,6 @@ typedef struct _IO_strfile_
1550 struct _IO_str_fields _s;
1551 } _IO_strfile;
1552
1553-/* dynamic: set when the array object is allocated (or reallocated) as
1554- necessary to hold a character sequence that can change in length. */
1555-#define _IO_STR_DYNAMIC(FP) ((FP)->_s._allocate_buffer != (_IO_alloc_type)0)
1556-
1557 /* frozen: set when the program has requested that the array object not
1558 be altered, reallocated, or freed. */
1559 #define _IO_STR_FROZEN(FP) ((FP)->_f._IO_file_flags & _IO_USER_BUF)
1560diff --git a/libio/strops.c b/libio/strops.c
1561index ac995c830e..5fb38976e3 100644
1562--- a/libio/strops.c
1563+++ b/libio/strops.c
1564@@ -61,7 +61,7 @@ _IO_str_init_static_internal (_IO_strfile *sf, char *ptr, _IO_size_t size,
1565 fp->_IO_read_end = end;
1566 }
1567 /* A null _allocate_buffer function flags the strfile as being static. */
1568- sf->_s._allocate_buffer = (_IO_alloc_type) 0;
1569+ sf->_s._allocate_buffer_unused = (_IO_alloc_type) 0;
1570 }
1571
1572 void
1573@@ -103,8 +103,7 @@ _IO_str_overflow (_IO_FILE *fp, int c)
1574 _IO_size_t new_size = 2 * old_blen + 100;
1575 if (new_size < old_blen)
1576 return EOF;
1577- new_buf
1578- = (char *) (*((_IO_strfile *) fp)->_s._allocate_buffer) (new_size);
1579+ new_buf = malloc (new_size);
1580 if (new_buf == NULL)
1581 {
1582 /* __ferror(fp) = 1; */
1583@@ -113,7 +112,7 @@ _IO_str_overflow (_IO_FILE *fp, int c)
1584 if (old_buf)
1585 {
1586 memcpy (new_buf, old_buf, old_blen);
1587- (*((_IO_strfile *) fp)->_s._free_buffer) (old_buf);
1588+ free (old_buf);
1589 /* Make sure _IO_setb won't try to delete _IO_buf_base. */
1590 fp->_IO_buf_base = NULL;
1591 }
1592@@ -182,15 +181,14 @@ enlarge_userbuf (_IO_FILE *fp, _IO_off64_t offset, int reading)
1593
1594 _IO_size_t newsize = offset + 100;
1595 char *oldbuf = fp->_IO_buf_base;
1596- char *newbuf
1597- = (char *) (*((_IO_strfile *) fp)->_s._allocate_buffer) (newsize);
1598+ char *newbuf = malloc (newsize);
1599 if (newbuf == NULL)
1600 return 1;
1601
1602 if (oldbuf != NULL)
1603 {
1604 memcpy (newbuf, oldbuf, _IO_blen (fp));
1605- (*((_IO_strfile *) fp)->_s._free_buffer) (oldbuf);
1606+ free (oldbuf);
1607 /* Make sure _IO_setb won't try to delete
1608 _IO_buf_base. */
1609 fp->_IO_buf_base = NULL;
1610@@ -346,7 +344,7 @@ void
1611 _IO_str_finish (_IO_FILE *fp, int dummy)
1612 {
1613 if (fp->_IO_buf_base && !(fp->_flags & _IO_USER_BUF))
1614- (((_IO_strfile *) fp)->_s._free_buffer) (fp->_IO_buf_base);
1615+ free (fp->_IO_buf_base);
1616 fp->_IO_buf_base = NULL;
1617
1618 _IO_default_finish (fp, 0);
da524a4e
VM
1619diff --git a/libio/tst-vtables-common.c b/libio/tst-vtables-common.c
1620new file mode 100644
1621index 0000000000..dc8d89c195
1622--- /dev/null
1623+++ b/libio/tst-vtables-common.c
1624@@ -0,0 +1,511 @@
1625+/* Test for libio vtables and their validation. Common code.
1626+ Copyright (C) 2018 Free Software Foundation, Inc.
1627+ This file is part of the GNU C Library.
1628+
1629+ The GNU C Library is free software; you can redistribute it and/or
1630+ modify it under the terms of the GNU Lesser General Public
1631+ License as published by the Free Software Foundation; either
1632+ version 2.1 of the License, or (at your option) any later version.
1633+
1634+ The GNU C Library is distributed in the hope that it will be useful,
1635+ but WITHOUT ANY WARRANTY; without even the implied warranty of
1636+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1637+ Lesser General Public License for more details.
1638+
1639+ You should have received a copy of the GNU Lesser General Public
1640+ License along with the GNU C Library; if not, see
1641+ <http://www.gnu.org/licenses/>. */
1642+
1643+/* This test provides some coverage for how various stdio functions
1644+ use the vtables in FILE * objects. The focus is mostly on which
1645+ functions call which methods, not so much on validating data
1646+ processing. An initial series of tests check that custom vtables
1647+ do not work without activation through _IO_init.
1648+
1649+ Note: libio vtables are deprecated feature. Do not use this test
1650+ as a documentation source for writing custom vtables. See
1651+ fopencookie for a different way of creating custom stdio
1652+ streams. */
1653+
1654+#include <stdbool.h>
1655+#include <string.h>
1656+#include <support/capture_subprocess.h>
1657+#include <support/check.h>
1658+#include <support/namespace.h>
1659+#include <support/support.h>
1660+#include <support/test-driver.h>
1661+#include <support/xunistd.h>
1662+
1663+/* Data shared between the test subprocess and the test driver in the
1664+ parent. Note that *shared is reset at the start of the check_call
1665+ function. */
1666+struct shared
1667+{
1668+ /* Expected file pointer for method calls. */
1669+ FILE *fp;
1670+
1671+ /* If true, assume that a call to _IO_init is needed to enable
1672+ custom vtables. */
1673+ bool initially_disabled;
1674+
1675+ /* Requested return value for the methods which have one. */
1676+ int return_value;
1677+
1678+ /* A value (usually a character) recorded by some of the methods
1679+ below. */
1680+ int value;
1681+
1682+ /* Likewise, for some data. */
1683+ char buffer[16];
1684+ size_t buffer_length;
1685+
1686+ /* Total number of method calls. */
1687+ unsigned int calls;
1688+
1689+ /* Individual method call counts. */
1690+ unsigned int calls_finish;
1691+ unsigned int calls_overflow;
1692+ unsigned int calls_underflow;
1693+ unsigned int calls_uflow;
1694+ unsigned int calls_pbackfail;
1695+ unsigned int calls_xsputn;
1696+ unsigned int calls_xsgetn;
1697+ unsigned int calls_seekoff;
1698+ unsigned int calls_seekpos;
1699+ unsigned int calls_setbuf;
1700+ unsigned int calls_sync;
1701+ unsigned int calls_doallocate;
1702+ unsigned int calls_read;
1703+ unsigned int calls_write;
1704+ unsigned int calls_seek;
1705+ unsigned int calls_close;
1706+ unsigned int calls_stat;
1707+ unsigned int calls_showmanyc;
1708+ unsigned int calls_imbue;
1709+} *shared;
1710+
1711+/* Method implementations which increment the counters in *shared. */
1712+
1713+static void
1714+log_method (FILE *fp, const char *name)
1715+{
1716+ if (test_verbose > 0)
1717+ printf ("info: %s (%p) called\n", name, fp);
1718+}
1719+
1720+static void
1721+method_finish (FILE *fp, int dummy)
1722+{
1723+ log_method (fp, __func__);
1724+ TEST_VERIFY (fp == shared->fp);
1725+ ++shared->calls;
1726+ ++shared->calls_finish;
1727+}
1728+
1729+static int
1730+method_overflow (FILE *fp, int ch)
1731+{
1732+ log_method (fp, __func__);
1733+ TEST_VERIFY (fp == shared->fp);
1734+ ++shared->calls;
1735+ ++shared->calls_overflow;
1736+ shared->value = ch;
1737+ return shared->return_value;
1738+}
1739+
1740+static int
1741+method_underflow (FILE *fp)
1742+{
1743+ log_method (fp, __func__);
1744+ TEST_VERIFY (fp == shared->fp);
1745+ ++shared->calls;
1746+ ++shared->calls_underflow;
1747+ return shared->return_value;
1748+}
1749+
1750+static int
1751+method_uflow (FILE *fp)
1752+{
1753+ log_method (fp, __func__);
1754+ TEST_VERIFY (fp == shared->fp);
1755+ ++shared->calls;
1756+ ++shared->calls_uflow;
1757+ return shared->return_value;
1758+}
1759+
1760+static int
1761+method_pbackfail (FILE *fp, int ch)
1762+{
1763+ log_method (fp, __func__);
1764+ TEST_VERIFY (fp == shared->fp);
1765+ ++shared->calls;
1766+ ++shared->calls_pbackfail;
1767+ shared->value = ch;
1768+ return shared->return_value;
1769+}
1770+
1771+static size_t
1772+method_xsputn (FILE *fp, const void *data, size_t n)
1773+{
1774+ log_method (fp, __func__);
1775+ TEST_VERIFY (fp == shared->fp);
1776+ ++shared->calls;
1777+ ++shared->calls_xsputn;
1778+
1779+ size_t to_copy = n;
1780+ if (n > sizeof (shared->buffer))
1781+ to_copy = sizeof (shared->buffer);
1782+ memcpy (shared->buffer, data, to_copy);
1783+ shared->buffer_length = to_copy;
1784+ return to_copy;
1785+}
1786+
1787+static size_t
1788+method_xsgetn (FILE *fp, void *data, size_t n)
1789+{
1790+ log_method (fp, __func__);
1791+ TEST_VERIFY (fp == shared->fp);
1792+ ++shared->calls;
1793+ ++shared->calls_xsgetn;
1794+ return 0;
1795+}
1796+
1797+static off64_t
1798+method_seekoff (FILE *fp, off64_t offset, int dir, int mode)
1799+{
1800+ log_method (fp, __func__);
1801+ TEST_VERIFY (fp == shared->fp);
1802+ ++shared->calls;
1803+ ++shared->calls_seekoff;
1804+ return shared->return_value;
1805+}
1806+
1807+static off64_t
1808+method_seekpos (FILE *fp, off64_t offset, int mode)
1809+{
1810+ log_method (fp, __func__);
1811+ TEST_VERIFY (fp == shared->fp);
1812+ ++shared->calls;
1813+ ++shared->calls_seekpos;
1814+ return shared->return_value;
1815+}
1816+
1817+static FILE *
1818+method_setbuf (FILE *fp, char *buffer, ssize_t length)
1819+{
1820+ log_method (fp, __func__);
1821+ TEST_VERIFY (fp == shared->fp);
1822+ ++shared->calls;
1823+ ++shared->calls_setbuf;
1824+ return fp;
1825+}
1826+
1827+static int
1828+method_sync (FILE *fp)
1829+{
1830+ log_method (fp, __func__);
1831+ TEST_VERIFY (fp == shared->fp);
1832+ ++shared->calls;
1833+ ++shared->calls_sync;
1834+ return shared->return_value;
1835+}
1836+
1837+static int
1838+method_doallocate (FILE *fp)
1839+{
1840+ log_method (fp, __func__);
1841+ TEST_VERIFY (fp == shared->fp);
1842+ ++shared->calls;
1843+ ++shared->calls_doallocate;
1844+ return shared->return_value;
1845+}
1846+
1847+static ssize_t
1848+method_read (FILE *fp, void *data, ssize_t length)
1849+{
1850+ log_method (fp, __func__);
1851+ TEST_VERIFY (fp == shared->fp);
1852+ ++shared->calls;
1853+ ++shared->calls_read;
1854+ return shared->return_value;
1855+}
1856+
1857+static ssize_t
1858+method_write (FILE *fp, const void *data, ssize_t length)
1859+{
1860+ log_method (fp, __func__);
1861+ TEST_VERIFY (fp == shared->fp);
1862+ ++shared->calls;
1863+ ++shared->calls_write;
1864+ return shared->return_value;
1865+}
1866+
1867+static off64_t
1868+method_seek (FILE *fp, off64_t offset, int mode)
1869+{
1870+ log_method (fp, __func__);
1871+ TEST_VERIFY (fp == shared->fp);
1872+ ++shared->calls;
1873+ ++shared->calls_seek;
1874+ return shared->return_value;
1875+}
1876+
1877+static int
1878+method_close (FILE *fp)
1879+{
1880+ log_method (fp, __func__);
1881+ TEST_VERIFY (fp == shared->fp);
1882+ ++shared->calls;
1883+ ++shared->calls_close;
1884+ return shared->return_value;
1885+}
1886+
1887+static int
1888+method_stat (FILE *fp, void *buffer)
1889+{
1890+ log_method (fp, __func__);
1891+ TEST_VERIFY (fp == shared->fp);
1892+ ++shared->calls;
1893+ ++shared->calls_stat;
1894+ return shared->return_value;
1895+}
1896+
1897+static int
1898+method_showmanyc (FILE *fp)
1899+{
1900+ log_method (fp, __func__);
1901+ TEST_VERIFY (fp == shared->fp);
1902+ ++shared->calls;
1903+ ++shared->calls_showmanyc;
1904+ return shared->return_value;
1905+}
1906+
1907+static void
1908+method_imbue (FILE *fp, void *locale)
1909+{
1910+ log_method (fp, __func__);
1911+ TEST_VERIFY (fp == shared->fp);
1912+ ++shared->calls;
1913+ ++shared->calls_imbue;
1914+}
1915+
1916+/* Our custom vtable. */
1917+
1918+static const struct _IO_jump_t jumps =
1919+{
1920+ JUMP_INIT_DUMMY,
1921+ JUMP_INIT (finish, method_finish),
1922+ JUMP_INIT (overflow, method_overflow),
1923+ JUMP_INIT (underflow, method_underflow),
1924+ JUMP_INIT (uflow, method_uflow),
1925+ JUMP_INIT (pbackfail, method_pbackfail),
1926+ JUMP_INIT (xsputn, method_xsputn),
1927+ JUMP_INIT (xsgetn, method_xsgetn),
1928+ JUMP_INIT (seekoff, method_seekoff),
1929+ JUMP_INIT (seekpos, method_seekpos),
1930+ JUMP_INIT (setbuf, method_setbuf),
1931+ JUMP_INIT (sync, method_sync),
1932+ JUMP_INIT (doallocate, method_doallocate),
1933+ JUMP_INIT (read, method_read),
1934+ JUMP_INIT (write, method_write),
1935+ JUMP_INIT (seek, method_seek),
1936+ JUMP_INIT (close, method_close),
1937+ JUMP_INIT (stat, method_stat),
1938+ JUMP_INIT (showmanyc, method_showmanyc),
1939+ JUMP_INIT (imbue, method_imbue)
1940+};
1941+
1942+/* Our file implementation. */
1943+
1944+struct my_file
1945+{
1946+ FILE f;
1947+ const struct _IO_jump_t *vtable;
1948+};
1949+
1950+struct my_file
1951+my_file_create (void)
1952+{
1953+ return (struct my_file)
1954+ {
1955+ /* Disable locking, so that we do not have to set up a lock
1956+ pointer. */
1957+ .f._flags = _IO_USER_LOCK,
1958+
1959+ /* Copy the offset from the an initialized handle, instead of
1960+ figuring it out from scratch. */
1961+ .f._vtable_offset = stdin->_vtable_offset,
1962+
1963+ .vtable = &jumps,
1964+ };
1965+}
1966+
1967+/* Initial tests which do not enable vtable compatibility. */
1968+
1969+/* Inhibit GCC optimization of fprintf. */
1970+typedef int (*fprintf_type) (FILE *, const char *, ...);
1971+static const volatile fprintf_type fprintf_ptr = &fprintf;
1972+
1973+static void
1974+without_compatibility_fprintf (void *closure)
1975+{
1976+ /* This call should abort. */
1977+ fprintf_ptr (shared->fp, " ");
1978+ _exit (1);
1979+}
1980+
1981+static void
1982+without_compatibility_fputc (void *closure)
1983+{
1984+ /* This call should abort. */
1985+ fputc (' ', shared->fp);
1986+ _exit (1);
1987+}
1988+
1989+static void
1990+without_compatibility_fgetc (void *closure)
1991+{
1992+ /* This call should abort. */
1993+ fgetc (shared->fp);
1994+ _exit (1);
1995+}
1996+
1997+static void
1998+without_compatibility_fflush (void *closure)
1999+{
2000+ /* This call should abort. */
2001+ fflush (shared->fp);
2002+ _exit (1);
2003+}
2004+
2005+/* Exit status after abnormal termination. */
2006+static int termination_status;
2007+
2008+static void
2009+init_termination_status (void)
2010+{
2011+ pid_t pid = xfork ();
2012+ if (pid == 0)
2013+ abort ();
2014+ xwaitpid (pid, &termination_status, 0);
2015+
2016+ TEST_VERIFY (WIFSIGNALED (termination_status));
2017+ TEST_COMPARE (WTERMSIG (termination_status), SIGABRT);
2018+}
2019+
2020+static void
2021+check_for_termination (const char *name, void (*callback) (void *))
2022+{
2023+ struct my_file file = my_file_create ();
2024+ shared->fp = &file.f;
2025+ shared->return_value = -1;
2026+ shared->calls = 0;
2027+ struct support_capture_subprocess proc
2028+ = support_capture_subprocess (callback, NULL);
2029+ support_capture_subprocess_check (&proc, name, termination_status,
2030+ sc_allow_stderr);
2031+ const char *message
2032+ = "Fatal error: glibc detected an invalid stdio handle\n";
2033+ TEST_COMPARE_BLOB (proc.err.buffer, proc.err.length,
2034+ message, strlen (message));
2035+ TEST_COMPARE (shared->calls, 0);
2036+ support_capture_subprocess_free (&proc);
2037+}
2038+
2039+/* The test with vtable validation disabled. */
2040+
2041+/* This function does not have a prototype in libioP.h to prevent
2042+ accidental use from within the library (which would disable vtable
2043+ verification). */
2044+void _IO_init (FILE *fp, int flags);
2045+
2046+static void
2047+with_compatibility_fprintf (void *closure)
2048+{
2049+ TEST_COMPARE (fprintf_ptr (shared->fp, "A%sCD", "B"), 4);
2050+ TEST_COMPARE (shared->calls, 3);
2051+ TEST_COMPARE (shared->calls_xsputn, 3);
2052+ TEST_COMPARE_BLOB (shared->buffer, shared->buffer_length,
2053+ "CD", 2);
2054+}
2055+
2056+static void
2057+with_compatibility_fputc (void *closure)
2058+{
2059+ shared->return_value = '@';
2060+ TEST_COMPARE (fputc ('@', shared->fp), '@');
2061+ TEST_COMPARE (shared->calls, 1);
2062+ TEST_COMPARE (shared->calls_overflow, 1);
2063+ TEST_COMPARE (shared->value, '@');
2064+}
2065+
2066+static void
2067+with_compatibility_fgetc (void *closure)
2068+{
2069+ shared->return_value = 'X';
2070+ TEST_COMPARE (fgetc (shared->fp), 'X');
2071+ TEST_COMPARE (shared->calls, 1);
2072+ TEST_COMPARE (shared->calls_uflow, 1);
2073+}
2074+
2075+static void
2076+with_compatibility_fflush (void *closure)
2077+{
2078+ TEST_COMPARE (fflush (shared->fp), 0);
2079+ TEST_COMPARE (shared->calls, 1);
2080+ TEST_COMPARE (shared->calls_sync, 1);
2081+}
2082+
2083+/* Call CALLBACK in a subprocess, after setting up a custom file
2084+ object and updating shared->fp. */
2085+static void
2086+check_call (const char *name, void (*callback) (void *),
2087+ bool initially_disabled)
2088+{
2089+ *shared = (struct shared)
2090+ {
2091+ .initially_disabled = initially_disabled,
2092+ };
2093+
2094+ /* Set up a custom file object. */
2095+ struct my_file file = my_file_create ();
2096+ shared->fp = &file.f;
2097+ if (shared->initially_disabled)
2098+ _IO_init (shared->fp, file.f._flags);
2099+
2100+ if (test_verbose > 0)
2101+ printf ("info: calling test %s\n", name);
2102+ support_isolate_in_subprocess (callback, NULL);
2103+}
2104+
2105+/* Run the tests. INITIALLY_DISABLED indicates whether custom vtables
2106+ are disabled when the test starts. */
2107+static int
2108+run_tests (bool initially_disabled)
2109+{
2110+ /* The test relies on fatal error messages being printed to standard
2111+ error. */
2112+ setenv ("LIBC_FATAL_STDERR_", "1", 1);
2113+
2114+ shared = support_shared_allocate (sizeof (*shared));
2115+ shared->initially_disabled = initially_disabled;
2116+ init_termination_status ();
2117+
2118+ if (initially_disabled)
2119+ {
2120+ check_for_termination ("fprintf", without_compatibility_fprintf);
2121+ check_for_termination ("fputc", without_compatibility_fputc);
2122+ check_for_termination ("fgetc", without_compatibility_fgetc);
2123+ check_for_termination ("fflush", without_compatibility_fflush);
2124+ }
2125+
2126+ check_call ("fprintf", with_compatibility_fprintf, initially_disabled);
2127+ check_call ("fputc", with_compatibility_fputc, initially_disabled);
2128+ check_call ("fgetc", with_compatibility_fgetc, initially_disabled);
2129+ check_call ("fflush", with_compatibility_fflush, initially_disabled);
2130+
2131+ support_shared_free (shared);
2132+ shared = NULL;
2133+
2134+ return 0;
2135+}
2136diff --git a/libio/tst-vtables-interposed.c b/libio/tst-vtables-interposed.c
2137new file mode 100644
2138index 0000000000..c8f4e8c7c3
2139--- /dev/null
2140+++ b/libio/tst-vtables-interposed.c
2141@@ -0,0 +1,37 @@
2142+/* Test for libio vtables and their validation. Enabled through interposition.
2143+ Copyright (C) 2018 Free Software Foundation, Inc.
2144+ This file is part of the GNU C Library.
2145+
2146+ The GNU C Library is free software; you can redistribute it and/or
2147+ modify it under the terms of the GNU Lesser General Public
2148+ License as published by the Free Software Foundation; either
2149+ version 2.1 of the License, or (at your option) any later version.
2150+
2151+ The GNU C Library is distributed in the hope that it will be useful,
2152+ but WITHOUT ANY WARRANTY; without even the implied warranty of
2153+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2154+ Lesser General Public License for more details.
2155+
2156+ You should have received a copy of the GNU Lesser General Public
2157+ License along with the GNU C Library; if not, see
2158+ <http://www.gnu.org/licenses/>. */
2159+
2160+/* Provide an interposed definition of the standard file handles with
2161+ our own vtable. stdout/stdin/stderr will not work as a result, but
2162+ a succesful test does not print anything, so this is fine. */
2163+static const struct _IO_jump_t jumps;
2164+#define _IO_file_jumps jumps
2165+#include "stdfiles.c"
2166+
2167+#include "tst-vtables-common.c"
2168+
2169+static int
2170+do_test (void)
2171+{
2172+ return run_tests (false);
2173+}
2174+
2175+/* Calling setvbuf in the test driver is not supported with our
2176+ interposed file handles. */
2177+#define TEST_NO_SETVBUF
2178+#include <support/test-driver.c>
2179diff --git a/libio/tst-vtables.c b/libio/tst-vtables.c
2180new file mode 100644
2181index 0000000000..f16acf5d23
2182--- /dev/null
2183+++ b/libio/tst-vtables.c
2184@@ -0,0 +1,29 @@
2185+/* Test for libio vtables and their validation. Initially disabled case.
2186+ Copyright (C) 2018 Free Software Foundation, Inc.
2187+ This file is part of the GNU C Library.
2188+
2189+ The GNU C Library is free software; you can redistribute it and/or
2190+ modify it under the terms of the GNU Lesser General Public
2191+ License as published by the Free Software Foundation; either
2192+ version 2.1 of the License, or (at your option) any later version.
2193+
2194+ The GNU C Library is distributed in the hope that it will be useful,
2195+ but WITHOUT ANY WARRANTY; without even the implied warranty of
2196+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2197+ Lesser General Public License for more details.
2198+
2199+ You should have received a copy of the GNU Lesser General Public
2200+ License along with the GNU C Library; if not, see
2201+ <http://www.gnu.org/licenses/>. */
2202+
2203+#include "libioP.h"
2204+
2205+#include "tst-vtables-common.c"
2206+
2207+static int
2208+do_test (void)
2209+{
2210+ return run_tests (true);
2211+}
2212+
2213+#include <support/test-driver.c>
2214diff --git a/libio/vasprintf.c b/libio/vasprintf.c
2215index 390a63d124..0bb217e46e 100644
2216--- a/libio/vasprintf.c
2217+++ b/libio/vasprintf.c
2218@@ -54,8 +54,8 @@ _IO_vasprintf (char **result_ptr, const char *format, _IO_va_list args)
2219 _IO_JUMPS (&sf._sbf) = &_IO_str_jumps;
2220 _IO_str_init_static_internal (&sf, string, init_string_size, string);
2221 sf._sbf._f._flags &= ~_IO_USER_BUF;
2222- sf._s._allocate_buffer = (_IO_alloc_type) malloc;
2223- sf._s._free_buffer = (_IO_free_type) free;
2224+ sf._s._allocate_buffer_unused = (_IO_alloc_type) malloc;
2225+ sf._s._free_buffer_unused = (_IO_free_type) free;
2226 ret = _IO_vfprintf (&sf._sbf._f, format, args);
2227 if (ret < 0)
2228 {
2229diff --git a/libio/vtables.c b/libio/vtables.c
2230index 9fd4ccf642..9df75668c8 100644
2231--- a/libio/vtables.c
2232+++ b/libio/vtables.c
2233@@ -71,3 +71,19 @@ _IO_vtable_check (void)
2234
2235 __libc_fatal ("Fatal error: glibc detected an invalid stdio handle\n");
2236 }
2237+
2238+/* Some variants of libstdc++ interpose _IO_2_1_stdin_ etc. and
2239+ install their own vtables directly, without calling _IO_init or
2240+ other functions. Detect this by looking at the vtables values
2241+ during startup, and disable vtable validation in this case. */
2242+#ifdef SHARED
2243+__attribute__ ((constructor))
2244+static void
2245+check_stdfiles_vtables (void)
2246+{
2247+ if (_IO_2_1_stdin_.vtable != &_IO_file_jumps
2248+ || _IO_2_1_stdout_.vtable != &_IO_file_jumps
2249+ || _IO_2_1_stderr_.vtable != &_IO_file_jumps)
2250+ IO_set_accept_foreign_vtables (&_IO_vtable_check);
2251+}
2252+#endif
2253diff --git a/libio/wmemstream.c b/libio/wmemstream.c
2254index c962071d26..f4c6e75246 100644
2255--- a/libio/wmemstream.c
2256+++ b/libio/wmemstream.c
2257@@ -92,8 +92,8 @@ open_wmemstream (wchar_t **bufloc, _IO_size_t *sizeloc)
2258 _IO_wstr_init_static (&new_f->fp._sf._sbf._f, buf,
2259 _IO_BUFSIZ / sizeof (wchar_t), buf);
2260 new_f->fp._sf._sbf._f._flags2 &= ~_IO_FLAGS2_USER_WBUF;
2261- new_f->fp._sf._s._allocate_buffer = (_IO_alloc_type) malloc;
2262- new_f->fp._sf._s._free_buffer = (_IO_free_type) free;
2263+ new_f->fp._sf._s._allocate_buffer_unused = (_IO_alloc_type) malloc;
2264+ new_f->fp._sf._s._free_buffer_unused = (_IO_free_type) free;
2265
2266 new_f->fp.bufloc = bufloc;
2267 new_f->fp.sizeloc = sizeloc;
2268diff --git a/libio/wstrops.c b/libio/wstrops.c
2269index a3374a7b15..0839a70bfb 100644
2270--- a/libio/wstrops.c
2271+++ b/libio/wstrops.c
2272@@ -63,7 +63,7 @@ _IO_wstr_init_static (_IO_FILE *fp, wchar_t *ptr, _IO_size_t size,
2273 fp->_wide_data->_IO_read_end = end;
2274 }
2275 /* A null _allocate_buffer function flags the strfile as being static. */
2276- (((_IO_strfile *) fp)->_s._allocate_buffer) = (_IO_alloc_type)0;
2277+ (((_IO_strfile *) fp)->_s._allocate_buffer_unused) = (_IO_alloc_type)0;
2278 }
2279
2280 _IO_wint_t
2281@@ -95,9 +95,7 @@ _IO_wstr_overflow (_IO_FILE *fp, _IO_wint_t c)
2282 || __glibc_unlikely (new_size > SIZE_MAX / sizeof (wchar_t)))
2283 return EOF;
2284
2285- new_buf
2286- = (wchar_t *) (*((_IO_strfile *) fp)->_s._allocate_buffer) (new_size
2287- * sizeof (wchar_t));
2288+ new_buf = malloc (new_size * sizeof (wchar_t));
2289 if (new_buf == NULL)
2290 {
2291 /* __ferror(fp) = 1; */
2292@@ -106,7 +104,7 @@ _IO_wstr_overflow (_IO_FILE *fp, _IO_wint_t c)
2293 if (old_buf)
2294 {
2295 __wmemcpy (new_buf, old_buf, old_wblen);
2296- (*((_IO_strfile *) fp)->_s._free_buffer) (old_buf);
2297+ free (old_buf);
2298 /* Make sure _IO_setb won't try to delete _IO_buf_base. */
2299 fp->_wide_data->_IO_buf_base = NULL;
2300 }
2301@@ -186,16 +184,14 @@ enlarge_userbuf (_IO_FILE *fp, _IO_off64_t offset, int reading)
2302 return 1;
2303
2304 wchar_t *oldbuf = wd->_IO_buf_base;
2305- wchar_t *newbuf
2306- = (wchar_t *) (*((_IO_strfile *) fp)->_s._allocate_buffer) (newsize
2307- * sizeof (wchar_t));
2308+ wchar_t *newbuf = malloc (newsize * sizeof (wchar_t));
2309 if (newbuf == NULL)
2310 return 1;
2311
2312 if (oldbuf != NULL)
2313 {
2314 __wmemcpy (newbuf, oldbuf, _IO_wblen (fp));
2315- (*((_IO_strfile *) fp)->_s._free_buffer) (oldbuf);
2316+ free (oldbuf);
2317 /* Make sure _IO_setb won't try to delete
2318 _IO_buf_base. */
2319 wd->_IO_buf_base = NULL;
2320@@ -357,7 +353,7 @@ void
2321 _IO_wstr_finish (_IO_FILE *fp, int dummy)
2322 {
2323 if (fp->_wide_data->_IO_buf_base && !(fp->_flags2 & _IO_FLAGS2_USER_WBUF))
2324- (((_IO_strfile *) fp)->_s._free_buffer) (fp->_wide_data->_IO_buf_base);
2325+ free (fp->_wide_data->_IO_buf_base);
2326 fp->_wide_data->_IO_buf_base = NULL;
2327
2328 _IO_wdefault_finish (fp, 0);
2329diff --git a/localedata/locales/ca_ES b/localedata/locales/ca_ES
2330index 914c066dab..f0d744d537 100644
2331--- a/localedata/locales/ca_ES
2332+++ b/localedata/locales/ca_ES
2333@@ -106,36 +106,67 @@ grouping 0;0
2334 END LC_NUMERIC
2335
2336 LC_TIME
2337-abday "dg";"dl";"dt";"dc";"dj";"dv";"ds"
2338-day "diumenge";/
2339- "dilluns";/
2340- "dimarts";/
2341- "dimecres";/
2342- "dijous";/
2343- "divendres";/
2344- "dissabte"
2345-abmon "gen";"feb";/
2346- "mar";"abr";/
2347- "mai";"jun";/
2348- "jul";"ago";/
2349- "set";"oct";/
2350- "nov";"des"
2351-mon "gener";/
2352- "febrer";/
2353- "mar<U00E7>";/
2354- "abril";/
2355- "maig";/
2356- "juny";/
2357- "juliol";/
2358- "agost";/
2359- "setembre";/
2360- "octubre";/
2361- "novembre";/
2362- "desembre"
2363-d_t_fmt "%a %d %b %Y %T %Z"
2364-d_fmt "%d//%m//%y"
2365-t_fmt "%T"
2366-am_pm "";""
2367+abday "dg.";"dl.";"dt.";"dc.";"dj.";"dv.";"ds."
2368+day "diumenge";/
2369+ "dilluns";/
2370+ "dimarts";/
2371+ "dimecres";/
2372+ "dijous";/
2373+ "divendres";/
2374+ "dissabte"
2375+ab_alt_mon "gen.";/
2376+ "febr.";/
2377+ "mar<U00E7>";/
2378+ "abr.";/
2379+ "maig";/
2380+ "juny";/
2381+ "jul.";/
2382+ "ag.";/
2383+ "set.";/
2384+ "oct.";/
2385+ "nov.";/
2386+ "des."
2387+abmon "de gen.";/
2388+ "de febr.";/
2389+ "de mar<U00E7>";/
2390+ "d<U2019>abr.";/
2391+ "de maig";/
2392+ "de juny";/
2393+ "de jul.";/
2394+ "d<U2019>ag.";/
2395+ "de set.";/
2396+ "d<U2019>oct.";/
2397+ "de nov.";/
2398+ "de des."
2399+alt_mon "gener";/
2400+ "febrer";/
2401+ "mar<U00E7>";/
2402+ "abril";/
2403+ "maig";/
2404+ "juny";/
2405+ "juliol";/
2406+ "agost";/
2407+ "setembre";/
2408+ "octubre";/
2409+ "novembre";/
2410+ "desembre"
2411+mon "de gener";/
2412+ "de febrer";/
2413+ "de mar<U00E7>";/
2414+ "d<U2019>abril";/
2415+ "de maig";/
2416+ "de juny";/
2417+ "de juliol";/
2418+ "d<U2019>agost";/
2419+ "de setembre";/
2420+ "d<U2019>octubre";/
2421+ "de novembre";/
2422+ "de desembre"
2423+d_t_fmt "%A, %-d %B de %Y, %T %Z"
2424+d_fmt "%-d//%-m//%y"
2425+t_fmt "%T"
2426+am_pm "a. m.";/
2427+ "p. m."
2428 t_fmt_ampm ""
2429 week 7;19971130;4
2430 first_weekday 2
2431@@ -146,9 +177,9 @@ copy "i18n"
2432 END LC_PAPER
2433
2434 LC_TELEPHONE
2435-tel_int_fmt "+%c %a %l"
2436-int_prefix "34"
2437-int_select "00"
2438+tel_int_fmt "+%c %a %l"
2439+int_prefix "34"
2440+int_select "00"
2441 END LC_TELEPHONE
2442
2443 LC_MEASUREMENT
2444@@ -156,19 +187,19 @@ copy "i18n"
2445 END LC_MEASUREMENT
2446
2447 LC_NAME
2448-name_fmt "%d%t%g%t%m%t%f"
2449+name_fmt "%d%t%g%t%m%t%f"
2450 END LC_NAME
2451
2452 LC_ADDRESS
2453-postal_fmt "%f%N%a%N%d%N%b%N%s %h %e %r%N%z %T%N%c%N"
2454+postal_fmt "%f%N%a%N%d%N%b%N%s %h %e %r%N%z %T%N%c%N"
2455 country_name "Espanya"
2456-country_ab2 "ES"
2457-country_ab3 "ESP"
2458-country_num 724
79da3d52
VM
2459-country_car "E"
2460+country_ab2 "ES"
2461+country_ab3 "ESP"
2462+country_num 724
2463+country_car "E"
2464 % català
2465 lang_name "catal<U00E0>"
2466 lang_ab "ca"
2467 lang_term "cat"
2468-lang_lib "cat"
2469+lang_lib "cat"
2470 END LC_ADDRESS
2471diff --git a/localedata/locales/cs_CZ b/localedata/locales/cs_CZ
2472index f80d3e1b37..8f4c69e493 100644
2473--- a/localedata/locales/cs_CZ
2474+++ b/localedata/locales/cs_CZ
2475@@ -272,7 +272,7 @@ day "Ned<U011B>le";/
2476 "P<U00E1>tek";/
2477 "Sobota"
2478
2479-mon "leden";/
2480+alt_mon "leden";/
2481 "<U00FA>nor";/
2482 "b<U0159>ezen";/
2483 "duben";/
2484@@ -334,6 +334,19 @@ abmon "led";/
2485 % "Nov";/
2486 % "Dec"
2487
2488+mon "ledna";/
2489+ "<U00FA>nora";/
2490+ "b<U0159>ezna";/
2491+ "dubna";/
2492+ "kv<U011B>tna";/
2493+ "<U010D>ervna";/
2494+ "<U010D>ervence";/
2495+ "srpna";/
2496+ "z<U00E1><U0159><U00ED>";/
2497+ "<U0159><U00ED>jna";/
2498+ "listopadu";/
2499+ "prosince"
2500+
2501 week 7;19971130;4
2502 first_weekday 2
2503
2504diff --git a/localedata/locales/el_CY b/localedata/locales/el_CY
2505index f27a74bb76..28055f335b 100644
2506--- a/localedata/locales/el_CY
2507+++ b/localedata/locales/el_CY
2508@@ -72,12 +72,18 @@ day "<U039A><U03C5><U03C1><U03B9><U03B1><U03BA><U03AE>";/
2509 "<U03A0><U03AD><U03BC><U03C0><U03C4><U03B7>";/
2510 "<U03A0><U03B1><U03C1><U03B1><U03C3><U03BA><U03B5><U03C5><U03AE>";/
2511 "<U03A3><U03AC><U03B2><U03B2><U03B1><U03C4><U03BF>"
2512-abmon "<U0399><U03B1><U03BD>";"<U03A6><U03B5><U03B2>";/
2513+ab_alt_mon "<U0399><U03B1><U03BD>";"<U03A6><U03B5><U03B2>";/
2514 "<U039C><U03AC><U03C1>";"<U0391><U03C0><U03C1>";/
2515 "<U039C><U03AC><U03B9>";"<U0399><U03BF><U03CD><U03BD>";/
2516 "<U0399><U03BF><U03CD><U03BB>";"<U0391><U03CD><U03B3>";/
2517 "<U03A3><U03B5><U03C0>";"<U039F><U03BA><U03C4>";/
2518 "<U039D><U03BF><U03AD>";"<U0394><U03B5><U03BA>"
2519+abmon "<U0399><U03B1><U03BD>";"<U03A6><U03B5><U03B2>";/
2520+ "<U039C><U03B1><U03C1>";"<U0391><U03C0><U03C1>";/
2521+ "<U039C><U03B1><U0390>";"<U0399><U03BF><U03C5><U03BD>";/
2522+ "<U0399><U03BF><U03C5><U03BB>";"<U0391><U03C5><U03B3>";/
2523+ "<U03A3><U03B5><U03C0>";"<U039F><U03BA><U03C4>";/
2524+ "<U039D><U03BF><U03B5>";"<U0394><U03B5><U03BA>"
2525 alt_mon "<U0399><U03B1><U03BD><U03BF><U03C5><U03AC><U03C1><U03B9><U03BF><U03C2>";/
2526 "<U03A6><U03B5><U03B2><U03C1><U03BF><U03C5><U03AC><U03C1><U03B9><U03BF><U03C2>";/
2527 "<U039C><U03AC><U03C1><U03C4><U03B9><U03BF><U03C2>";/
2528diff --git a/localedata/locales/el_GR b/localedata/locales/el_GR
2529index a82ef8c6d9..7362492fbd 100644
2530--- a/localedata/locales/el_GR
2531+++ b/localedata/locales/el_GR
2532@@ -104,12 +104,18 @@ day "<U039A><U03C5><U03C1><U03B9><U03B1><U03BA><U03AE>";/
2533 "<U03A0><U03AD><U03BC><U03C0><U03C4><U03B7>";/
2534 "<U03A0><U03B1><U03C1><U03B1><U03C3><U03BA><U03B5><U03C5><U03AE>";/
2535 "<U03A3><U03AC><U03B2><U03B2><U03B1><U03C4><U03BF>"
2536-abmon "<U0399><U03B1><U03BD>";"<U03A6><U03B5><U03B2>";/
2537+ab_alt_mon "<U0399><U03B1><U03BD>";"<U03A6><U03B5><U03B2>";/
2538 "<U039C><U03AC><U03C1>";"<U0391><U03C0><U03C1>";/
2539 "<U039C><U03AC><U03B9>";"<U0399><U03BF><U03CD><U03BD>";/
2540 "<U0399><U03BF><U03CD><U03BB>";"<U0391><U03CD><U03B3>";/
2541 "<U03A3><U03B5><U03C0>";"<U039F><U03BA><U03C4>";/
2542 "<U039D><U03BF><U03AD>";"<U0394><U03B5><U03BA>"
2543+abmon "<U0399><U03B1><U03BD>";"<U03A6><U03B5><U03B2>";/
2544+ "<U039C><U03B1><U03C1>";"<U0391><U03C0><U03C1>";/
2545+ "<U039C><U03B1><U0390>";"<U0399><U03BF><U03C5><U03BD>";/
2546+ "<U0399><U03BF><U03C5><U03BB>";"<U0391><U03C5><U03B3>";/
2547+ "<U03A3><U03B5><U03C0>";"<U039F><U03BA><U03C4>";/
2548+ "<U039D><U03BF><U03B5>";"<U0394><U03B5><U03BA>"
2549 alt_mon "<U0399><U03B1><U03BD><U03BF><U03C5><U03AC><U03C1><U03B9><U03BF><U03C2>";/
2550 "<U03A6><U03B5><U03B2><U03C1><U03BF><U03C5><U03AC><U03C1><U03B9><U03BF><U03C2>";/
2551 "<U039C><U03AC><U03C1><U03C4><U03B9><U03BF><U03C2>";/
da524a4e
VM
2552diff --git a/localedata/locales/es_BO b/localedata/locales/es_BO
2553index 4202c5a0cf..5b6c6e2312 100644
2554--- a/localedata/locales/es_BO
2555+++ b/localedata/locales/es_BO
2556@@ -124,7 +124,7 @@ first_weekday 2
2557 END LC_TIME
2558
2559 LC_PAPER
2560-copy "i18n"
2561+copy "en_US"
2562 END LC_PAPER
2563
2564 LC_TELEPHONE
79da3d52
VM
2565diff --git a/localedata/locales/et_EE b/localedata/locales/et_EE
2566index 9cb55b568f..bab7493c98 100644
2567--- a/localedata/locales/et_EE
2568+++ b/localedata/locales/et_EE
2569@@ -103,6 +103,8 @@ reorder-after <w>
2570 <U00FC> <u-diaresis>;<BAS>;<MIN>;IGNORE % ü
2571 <U00DC> <u-diaresis>;<BAS>;<CAP>;IGNORE % Ü
2572
2573+reorder-end
2574+
2575 END LC_COLLATE
2576
2577 LC_CTYPE
2578diff --git a/localedata/locales/gd_GB b/localedata/locales/gd_GB
2579index 676ee940c9..77d11e5977 100644
2580--- a/localedata/locales/gd_GB
2581+++ b/localedata/locales/gd_GB
2582@@ -66,12 +66,12 @@ mon "Am Faoilleach";/
2583 "An D<U00E0>mhair";/
2584 "An t-Samhain";/
2585 "An D<U00F9>bhlachd"
2586-% Faoi, Gearr, Màrt, Gibl, Mhàrt, Ògmh, Iuch, Lùna, Sult, Dàmh, Samh, Dùbh
2587+% Faoi, Gearr, Màrt, Gibl, Cèit, Ògmh, Iuch, Lùna, Sult, Dàmh, Samh, Dùbh
2588 abmon "Faoi";/
2589 "Gearr";/
2590 "M<U00E0>rt";/
2591 "Gibl";/
2592- "Mh<U00E0>rt";/
2593+ "C<U00E8>it";/
2594 "<U00D2>gmh";/
2595 "Iuch";/
2596 "L<U00F9>na";/
2597diff --git a/localedata/locales/lt_LT b/localedata/locales/lt_LT
2598index c935fcf75e..bec67726e9 100644
2599--- a/localedata/locales/lt_LT
2600+++ b/localedata/locales/lt_LT
2601@@ -201,12 +201,12 @@ day "Sekmadienis";/
2602 "Ketvirtadienis";/
2603 "Penktadienis";/
2604 "<U0160>e<U0161>tadienis"
2605-abmon "Sau";"Vas";/
2606- "Kov";"Bal";/
2607- "Geg";"Bir";/
2608- "Lie";"Rgp";/
2609- "Rgs";"Spa";/
2610- "Lap";"Grd"
2611+abmon "saus.";"vas.";/
2612+ "kov.";"bal.";/
2613+ "geg.";"bir<U017E>.";/
2614+ "liep.";"rugp.";/
2615+ "rugs.";"spal.";/
2616+ "lapkr.";"gruod."
2617 alt_mon "sausis";/
2618 "vasaris";/
2619 "kovas";/
2620diff --git a/manual/charset.texi b/manual/charset.texi
2621index 1867ace485..f6a980f6cb 100644
2622--- a/manual/charset.texi
2623+++ b/manual/charset.texi
2624@@ -643,8 +643,8 @@ and they also do not require it to be in the initial state.
2625 @cindex stateful
2626 The @code{mbrtowc} function (``multibyte restartable to wide
2627 character'') converts the next multibyte character in the string pointed
2628-to by @var{s} into a wide character and stores it in the wide character
2629-string pointed to by @var{pwc}. The conversion is performed according
2630+to by @var{s} into a wide character and stores it in the location
2631+pointed to by @var{pwc}. The conversion is performed according
2632 to the locale currently selected for the @code{LC_CTYPE} category. If
2633 the conversion for the character set used in the locale requires a state,
2634 the multibyte string is interpreted in the state represented by the
2635@@ -652,7 +652,7 @@ object pointed to by @var{ps}. If @var{ps} is a null pointer, a static,
2636 internal state variable used only by the @code{mbrtowc} function is
2637 used.
2638
2639-If the next multibyte character corresponds to the NUL wide character,
2640+If the next multibyte character corresponds to the null wide character,
2641 the return value of the function is @math{0} and the state object is
2642 afterwards in the initial state. If the next @var{n} or fewer bytes
2643 form a correct multibyte character, the return value is the number of
2644@@ -665,71 +665,59 @@ by @var{pwc} if @var{pwc} is not null.
2645 If the first @var{n} bytes of the multibyte string possibly form a valid
2646 multibyte character but there are more than @var{n} bytes needed to
2647 complete it, the return value of the function is @code{(size_t) -2} and
2648-no value is stored. Please note that this can happen even if @var{n}
2649-has a value greater than or equal to @code{MB_CUR_MAX} since the input
2650-might contain redundant shift sequences.
2651+no value is stored in @code{*@var{pwc}}. The conversion state is
2652+updated and all @var{n} input bytes are consumed and should not be
2653+submitted again. Please note that this can happen even if @var{n} has a
2654+value greater than or equal to @code{MB_CUR_MAX} since the input might
2655+contain redundant shift sequences.
2656
2657 If the first @code{n} bytes of the multibyte string cannot possibly form
2658 a valid multibyte character, no value is stored, the global variable
2659 @code{errno} is set to the value @code{EILSEQ}, and the function returns
2660 @code{(size_t) -1}. The conversion state is afterwards undefined.
2661
2662+As specified, the @code{mbrtowc} function could deal with multibyte
2663+sequences which contain embedded null bytes (which happens in Unicode
2664+encodings such as UTF-16), but @theglibc{} does not support such
2665+multibyte encodings. When encountering a null input byte, the function
2666+will either return zero, or return @code{(size_t) -1)} and report a
2667+@code{EILSEQ} error. The @code{iconv} function can be used for
2668+converting between arbitrary encodings. @xref{Generic Conversion
2669+Interface}.
2670+
2671 @pindex wchar.h
2672 @code{mbrtowc} was introduced in @w{Amendment 1} to @w{ISO C90} and
2673 is declared in @file{wchar.h}.
2674 @end deftypefun
2675
2676-Use of @code{mbrtowc} is straightforward. A function that copies a
2677-multibyte string into a wide character string while at the same time
2678-converting all lowercase characters into uppercase could look like this
2679-(this is not the final version, just an example; it has no error
2680-checking, and sometimes leaks memory):
2681+A function that copies a multibyte string into a wide character string
2682+while at the same time converting all lowercase characters into
2683+uppercase could look like this:
2684
2685 @smallexample
2686-wchar_t *
2687-mbstouwcs (const char *s)
2688-@{
2689- size_t len = strlen (s);
2690- wchar_t *result = malloc ((len + 1) * sizeof (wchar_t));
2691- wchar_t *wcp = result;
2692- wchar_t tmp[1];
2693- mbstate_t state;
2694- size_t nbytes;
2695-
2696- memset (&state, '\0', sizeof (state));
2697- while ((nbytes = mbrtowc (tmp, s, len, &state)) > 0)
2698- @{
2699- if (nbytes >= (size_t) -2)
2700- /* Invalid input string. */
2701- return NULL;
2702- *wcp++ = towupper (tmp[0]);
2703- len -= nbytes;
2704- s += nbytes;
2705- @}
2706- return result;
2707-@}
2708+@include mbstouwcs.c.texi
2709 @end smallexample
2710
2711-The use of @code{mbrtowc} should be clear. A single wide character is
2712-stored in @code{@var{tmp}[0]}, and the number of consumed bytes is stored
2713-in the variable @var{nbytes}. If the conversion is successful, the
2714-uppercase variant of the wide character is stored in the @var{result}
2715-array and the pointer to the input string and the number of available
2716-bytes is adjusted.
2717-
2718-The only non-obvious thing about @code{mbrtowc} might be the way memory
2719-is allocated for the result. The above code uses the fact that there
2720-can never be more wide characters in the converted result than there are
2721-bytes in the multibyte input string. This method yields a pessimistic
2722-guess about the size of the result, and if many wide character strings
2723-have to be constructed this way or if the strings are long, the extra
2724-memory required to be allocated because the input string contains
2725-multibyte characters might be significant. The allocated memory block can
2726-be resized to the correct size before returning it, but a better solution
2727-might be to allocate just the right amount of space for the result right
2728-away. Unfortunately there is no function to compute the length of the wide
2729-character string directly from the multibyte string. There is, however, a
2730-function that does part of the work.
2731+In the inner loop, a single wide character is stored in @code{wc}, and
2732+the number of consumed bytes is stored in the variable @code{nbytes}.
2733+If the conversion is successful, the uppercase variant of the wide
2734+character is stored in the @code{result} array and the pointer to the
2735+input string and the number of available bytes is adjusted. If the
2736+@code{mbrtowc} function returns zero, the null input byte has not been
2737+converted, so it must be stored explicitly in the result.
2738+
2739+The above code uses the fact that there can never be more wide
2740+characters in the converted result than there are bytes in the multibyte
2741+input string. This method yields a pessimistic guess about the size of
2742+the result, and if many wide character strings have to be constructed
2743+this way or if the strings are long, the extra memory required to be
2744+allocated because the input string contains multibyte characters might
2745+be significant. The allocated memory block can be resized to the
2746+correct size before returning it, but a better solution might be to
2747+allocate just the right amount of space for the result right away.
2748+Unfortunately there is no function to compute the length of the wide
2749+character string directly from the multibyte string. There is, however,
2750+a function that does part of the work.
2751
2752 @deftypefun size_t mbrlen (const char *restrict @var{s}, size_t @var{n}, mbstate_t *@var{ps})
2753 @standards{ISO, wchar.h}
2754diff --git a/manual/creature.texi b/manual/creature.texi
2755index 96f8ee0a0c..fe7a7790a2 100644
2756--- a/manual/creature.texi
2757+++ b/manual/creature.texi
2758@@ -8,7 +8,7 @@ is controlled by which @dfn{feature test macros} you define.
2759 If you compile your programs using @samp{gcc -ansi}, you get only the
2760 @w{ISO C} library features, unless you explicitly request additional
2761 features by defining one or more of the feature macros.
2762-@xref{Invoking GCC,, GNU CC Command Options, gcc.info, The GNU CC Manual},
2763+@xref{Invoking GCC,, GNU CC Command Options, gcc, The GNU CC Manual},
2764 for more information about GCC options.@refill
2765
2766 You should define these macros by using @samp{#define} preprocessor
2767@@ -61,13 +61,27 @@ If you define this macro to a value greater than or equal to @code{199309L},
2768 then the functionality from the 1993 edition of the POSIX.1b standard
2769 (IEEE Standard 1003.1b-1993) is made available.
2770
2771+If you define this macro to a value greater than or equal to
2772+@code{199506L}, then the functionality from the 1995 edition of the
2773+POSIX.1c standard (IEEE Standard 1003.1c-1995) is made available.
2774+
2775+If you define this macro to a value greater than or equal to
2776+@code{200112L}, then the functionality from the 2001 edition of the
2777+POSIX standard (IEEE Standard 1003.1-2001) is made available.
2778+
2779+If you define this macro to a value greater than or equal to
2780+@code{200809L}, then the functionality from the 2008 edition of the
2781+POSIX standard (IEEE Standard 1003.1-2008) is made available.
2782+
2783 Greater values for @code{_POSIX_C_SOURCE} will enable future extensions.
2784 The POSIX standards process will define these values as necessary, and
2785 @theglibc{} should support them some time after they become standardized.
2786 The 1996 edition of POSIX.1 (ISO/IEC 9945-1: 1996) states that
2787 if you define @code{_POSIX_C_SOURCE} to a value greater than
2788 or equal to @code{199506L}, then the functionality from the 1996
2789-edition is made available.
2790+edition is made available. In general, in @theglibc{}, bugfixes to
2791+the standards are included when specifying the base version; e.g.,
2792+POSIX.1-2004 will always be included with a value of @code{200112L}.
2793 @end defvr
2794
2795 @defvr Macro _XOPEN_SOURCE
2796@@ -87,7 +101,10 @@ available which are necessary for the X/Open Unix brand.
2797
2798 If the macro @code{_XOPEN_SOURCE} has the value @math{500} this includes
2799 all functionality described so far plus some new definitions from the
2800-Single Unix Specification, @w{version 2}.
2801+Single Unix Specification, @w{version 2}. The value @math{600}
2802+(corresponding to the sixth revision) includes definitions from SUSv3,
2803+and using @math{700} (the seventh revision) includes definitions from
2804+SUSv4.
2805 @end defvr
2806
2807 @defvr Macro _LARGEFILE_SOURCE
2808@@ -150,10 +167,14 @@ This macro was introduced as part of the Large File Support extension
2809
2810 @defvr Macro _ISOC99_SOURCE
2811 @standards{GNU, (none)}
2812-Until the revised @w{ISO C} standard is widely adopted the new features
2813-are not automatically enabled. @Theglibc{} nevertheless has a complete
2814-implementation of the new standard and to enable the new features the
2815-macro @code{_ISOC99_SOURCE} should be defined.
2816+If this macro is defined, features from ISO C99 are included. Since
2817+these features are included by default, this macro is mostly relevant
2818+when the compiler uses an earlier language version.
2819+@end defvr
2820+
2821+@defvr Macro _ISOC11_SOURCE
2822+@standards{C11, (none)}
2823+If this macro is defined, ISO C11 extensions to ISO C99 are included.
2824 @end defvr
2825
2826 @defvr Macro __STDC_WANT_LIB_EXT2__
2827@@ -209,6 +230,19 @@ enables those features even when the other options would otherwise
2828 cause them to be disabled.
2829 @end defvr
2830
2831+@defvr Macro _ATFILE_SOURCE
2832+@standards{GNU, (none)}
2833+If this macro is defined, additional @code{*at} interfaces are
2834+included.
2835+@end defvr
2836+
2837+@defvr Macro _FORTIFY_SOURCE
2838+@standards{GNU, (none)}
2839+If this macro is defined to @math{1}, security hardening is added to
2840+various library functions. If defined to @math{2}, even stricter
2841+checks are applied.
2842+@end defvr
2843+
2844 @defvr Macro _REENTRANT
2845 @defvrx Macro _THREAD_SAFE
2846 @standards{Obsolete, (none)}
2847diff --git a/manual/examples/mbstouwcs.c b/manual/examples/mbstouwcs.c
2848new file mode 100644
2849index 0000000000..c94e1fa790
2850--- /dev/null
2851+++ b/manual/examples/mbstouwcs.c
2852@@ -0,0 +1,53 @@
2853+#include <stdbool.h>
2854+#include <stdlib.h>
2855+#include <string.h>
2856+#include <wchar.h>
2857+
2858+/* Do not include the above headers in the example.
2859+*/
2860+wchar_t *
2861+mbstouwcs (const char *s)
2862+{
2863+ /* Include the null terminator in the conversion. */
2864+ size_t len = strlen (s) + 1;
2865+ wchar_t *result = reallocarray (NULL, len, sizeof (wchar_t));
2866+ if (result == NULL)
2867+ return NULL;
2868+
2869+ wchar_t *wcp = result;
2870+ mbstate_t state;
2871+ memset (&state, '\0', sizeof (state));
2872+
2873+ while (true)
2874+ {
2875+ wchar_t wc;
2876+ size_t nbytes = mbrtowc (&wc, s, len, &state);
2877+ if (nbytes == 0)
2878+ {
2879+ /* Terminate the result string. */
2880+ *wcp = L'\0';
2881+ break;
2882+ }
2883+ else if (nbytes == (size_t) -2)
2884+ {
2885+ /* Truncated input string. */
2886+ errno = EILSEQ;
2887+ free (result);
2888+ return NULL;
2889+ }
2890+ else if (nbytes == (size_t) -1)
2891+ {
2892+ /* Some other error (including EILSEQ). */
2893+ free (result);
2894+ return NULL;
2895+ }
2896+ else
2897+ {
2898+ /* A character was converted. */
2899+ *wcp++ = towupper (wc);
2900+ len -= nbytes;
2901+ s += nbytes;
2902+ }
2903+ }
2904+ return result;
2905+}
2906diff --git a/manual/filesys.texi b/manual/filesys.texi
2907index ca77996902..cc70a6b7ee 100644
2908--- a/manual/filesys.texi
2909+++ b/manual/filesys.texi
2910@@ -147,19 +147,20 @@ necessarily enough space to contain the directory name. That is why
2911 this function is deprecated.
2912 @end deftypefn
2913
2914+@vindex PWD
2915 @deftypefun {char *} get_current_dir_name (void)
2916 @standards{GNU, unistd.h}
2917 @safety{@prelim{}@mtsafe{@mtsenv{}}@asunsafe{@ascuheap{}}@acunsafe{@acsmem{} @acsfd{}}}
2918 @c Besides getcwd, which this function calls as a fallback, it calls
2919 @c getenv, with the potential thread-safety issues that brings about.
2920-@vindex PWD
2921-This @code{get_current_dir_name} function is basically equivalent to
2922-@w{@code{getcwd (NULL, 0)}}. The only difference is that the value of
2923-the @code{PWD} variable is returned if this value is correct. This is a
2924-subtle difference which is visible if the path described by the
2925-@code{PWD} value is using one or more symbol links in which case the
2926-value returned by @code{getcwd} can resolve the symbol links and
2927-therefore yield a different result.
2928+The @code{get_current_dir_name} function is basically equivalent to
2929+@w{@code{getcwd (NULL, 0)}}, except the value of the @env{PWD}
2930+environment variable is first examined, and if it does in fact
2931+correspond to the current directory, that value is returned. This is
2932+a subtle difference which is visible if the path described by the
2933+value in @env{PWD} is using one or more symbolic links, in which case
2934+the value returned by @code{getcwd} would resolve the symbolic links
2935+and therefore yield a different result.
2936
2937 This function is a GNU extension.
2938 @end deftypefun
2939diff --git a/manual/llio.texi b/manual/llio.texi
da524a4e 2940index 642e56e710..82f03be2be 100644
79da3d52
VM
2941--- a/manual/llio.texi
2942+++ b/manual/llio.texi
da524a4e
VM
2943@@ -1251,9 +1251,13 @@ When the source file is compiled using @code{_FILE_OFFSET_BITS == 64} on a
2944 @c This is a syscall for Linux v4.6. The sysdeps/posix fallback emulation
2945 @c is also MT-Safe since it calls preadv.
2946
2947-This function is similar to the @code{preadv} function, with the difference
2948-it adds an extra @var{flags} parameter of type @code{int}. The supported
2949-@var{flags} are dependent of the underlying system. For Linux it supports:
2950+This function is similar to the @code{preadv} function, with the
2951+difference it adds an extra @var{flags} parameter of type @code{int}.
2952+Additionally, if @var{offset} is @math{-1}, the current file position
2953+is used and updated (like the @code{readv} function).
2954+
2955+The supported @var{flags} are dependent of the underlying system. For
2956+Linux it supports:
2957
2958 @vtable @code
2959 @item RWF_HIPRI
2960@@ -1271,6 +1275,9 @@ Per-IO synchronization as if the file was opened with @code{O_SYNC} flag.
79da3d52
VM
2961 @item RWF_NOWAIT
2962 Use nonblocking mode for this operation; that is, this call to @code{preadv2}
2963 will fail and set @code{errno} to @code{EAGAIN} if the operation would block.
2964+
2965+@item RWF_APPEND
2966+Per-IO synchronization as if the file was opened with @code{O_APPEND} flag.
2967 @end vtable
2968
2969 When the source file is compiled with @code{_FILE_OFFSET_BITS == 64} the
da524a4e
VM
2970@@ -1320,10 +1327,13 @@ When the source file is compiled using @code{_FILE_OFFSET_BITS == 64} on a
2971 @c This is a syscall for Linux v4.6. The sysdeps/posix fallback emulation
2972 @c is also MT-Safe since it calls pwritev.
2973
2974-This function is similar to the @code{pwritev} function, with the difference
2975-it adds an extra @var{flags} parameter of type @code{int}. The supported
2976-@var{flags} are dependent of the underlying system and for Linux it supports
2977-the same ones as for @code{preadv2}.
2978+This function is similar to the @code{pwritev} function, with the
2979+difference it adds an extra @var{flags} parameter of type @code{int}.
2980+Additionally, if @var{offset} is @math{-1}, the current file position
2981+should is used and updated (like the @code{writev} function).
2982+
2983+The supported @var{flags} are dependent of the underlying system. For
2984+Linux, the supported flags are the same as those for @code{preadv2}.
2985
2986 When the source file is compiled with @code{_FILE_OFFSET_BITS == 64} the
2987 @code{pwritev2} function is in fact @code{pwritev64v2} and the type
79da3d52
VM
2988diff --git a/manual/platform.texi b/manual/platform.texi
2989index b8721a0712..504addc956 100644
2990--- a/manual/platform.texi
2991+++ b/manual/platform.texi
2992@@ -123,7 +123,7 @@ when it is not allowed, the priority is set to medium.
2993 Cache management facilities specific to RISC-V systems that implement the Linux
2994 ABI are declared in @file{sys/cachectl.h}.
2995
2996-@deftypefun {void} __riscv_flush_icache(void *@var{start}, void *@var{end}, unsigned long int @var{flags})
2997+@deftypefun {void} __riscv_flush_icache (void *@var{start}, void *@var{end}, unsigned long int @var{flags})
2998 @safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
2999 Enforce ordering between stores and instruction cache fetches. The range of
3000 addresses over which ordering is enforced is specified by @var{start} and
3001diff --git a/manual/stdio.texi b/manual/stdio.texi
3002index 5d7b50c442..38be236991 100644
3003--- a/manual/stdio.texi
3004+++ b/manual/stdio.texi
3005@@ -1808,7 +1808,7 @@ verifies that the correct number and types of arguments are supplied.
3006 There is also a GNU C syntax to tell the compiler that a function you
3007 write uses a @code{printf}-style format string.
3008 @xref{Function Attributes, , Declaring Attributes of Functions,
3009-gcc.info, Using GNU CC}, for more information.
3010+gcc, Using GNU CC}, for more information.
3011
3012 @node Table of Output Conversions
3013 @subsection Table of Output Conversions
3014@@ -2730,7 +2730,7 @@ This tells the compiler that @code{eprintf} uses a format string like
3015 the format string appears as the first argument;
3016 and the arguments to satisfy the format begin with the second.
3017 @xref{Function Attributes, , Declaring Attributes of Functions,
3018-gcc.info, Using GNU CC}, for more information.
3019+gcc, Using GNU CC}, for more information.
3020
3021 @node Parsing a Template String
3022 @subsection Parsing a Template String
3023@@ -3478,7 +3478,7 @@ verifies that the correct number and types of arguments are supplied.
3024 There is also a GNU C syntax to tell the compiler that a function you
3025 write uses a @code{scanf}-style format string.
3026 @xref{Function Attributes, , Declaring Attributes of Functions,
3027-gcc.info, Using GNU CC}, for more information.
3028+gcc, Using GNU CC}, for more information.
3029
3030 @node Table of Input Conversions
3031 @subsection Table of Input Conversions
3032@@ -4033,7 +4033,7 @@ know that a function uses a @code{scanf}-style format string. Then it
3033 can check the number and types of arguments in each call to the
3034 function, and warn you when they do not match the format string.
3035 For details, see @ref{Function Attributes, , Declaring Attributes of Functions,
3036-gcc.info, Using GNU CC}.
3037+gcc, Using GNU CC}.
3038
3039 @node EOF and Errors
3040 @section End-Of-File and Errors
3041diff --git a/manual/string.texi b/manual/string.texi
3042index ac02c6d85e..b07cfb4550 100644
3043--- a/manual/string.texi
3044+++ b/manual/string.texi
3045@@ -1087,7 +1087,7 @@ are often easier and safer automatic techniques that cause buffer
3046 overruns to reliably terminate a program, such as GCC's
3047 @option{-fcheck-pointer-bounds} and @option{-fsanitize=address}
3048 options. @xref{Debugging Options,, Options for Debugging Your Program
3049-or GCC, gcc.info, Using GCC}. Because truncation functions can mask
3050+or GCC, gcc, Using GCC}. Because truncation functions can mask
3051 application bugs that would otherwise be caught by the automatic
3052 techniques, these functions should be used only when the application's
3053 underlying logic requires truncation.
3054diff --git a/math/math.h b/math/math.h
3055index 3c515f817f..0fcbd91366 100644
3056--- a/math/math.h
3057+++ b/math/math.h
3058@@ -1223,7 +1223,7 @@ template<> struct __iseqsig_type<double>
3059
3060 template<> struct __iseqsig_type<long double>
3061 {
3062- static int __call (double __x, double __y) throw ()
3063+ static int __call (long double __x, long double __y) throw ()
3064 {
3065 # ifndef __NO_LONG_DOUBLE_MATH
3066 return __iseqsigl (__x, __y);
da524a4e
VM
3067diff --git a/misc/tst-preadvwritev-common.c b/misc/tst-preadvwritev-common.c
3068index 560c8f89b6..b59a3de465 100644
3069--- a/misc/tst-preadvwritev-common.c
3070+++ b/misc/tst-preadvwritev-common.c
3071@@ -16,6 +16,7 @@
3072 License along with the GNU C Library; if not, see
3073 <http://www.gnu.org/licenses/>. */
3074
3075+#include <array_length.h>
3076 #include <stdio.h>
3077 #include <stdint.h>
3078 #include <errno.h>
3079@@ -25,6 +26,7 @@
3080
3081 #include <support/check.h>
3082 #include <support/temp_file.h>
3083+#include <support/xunistd.h>
3084
3085 static char *temp_filename;
3086 static int temp_fd;
3087@@ -50,6 +52,42 @@ do_prepare (int argc, char **argv)
3088 pwritev (__fd, __iov, __iovcnt, __offset)
3089 #endif
3090
3091+static __attribute__ ((unused)) void
3092+do_test_without_offset (void)
3093+{
3094+ xftruncate (temp_fd, 0);
3095+
3096+ xwrite (temp_fd, "123", 3);
3097+ xlseek (temp_fd, 2, SEEK_SET);
3098+ {
3099+ struct iovec iov[] =
3100+ {
3101+ { (void *) "abc", 3 },
3102+ { (void *) "xyzt", 4 },
3103+ };
3104+ TEST_COMPARE (PWRITEV (temp_fd, iov, array_length (iov), -1), 7);
3105+ }
3106+ TEST_COMPARE (xlseek (temp_fd, 0, SEEK_CUR), 9);
3107+
3108+ xlseek (temp_fd, 1, SEEK_SET);
3109+ char buf1[3];
3110+ char buf2[2];
3111+ {
3112+ struct iovec iov[] =
3113+ {
3114+ { buf1, sizeof (buf1) },
3115+ { buf2, sizeof (buf2) },
3116+ };
3117+ TEST_COMPARE (PREADV (temp_fd, iov, array_length (iov), -1),
3118+ sizeof (buf1) + sizeof (buf2));
3119+ TEST_COMPARE (memcmp ("2ab", buf1, sizeof (buf1)), 0);
3120+ TEST_COMPARE (memcmp ("cx", buf2, sizeof (buf2)), 0);
3121+ TEST_COMPARE (xlseek (temp_fd, 0, SEEK_CUR), 6);
3122+ }
3123+
3124+ xftruncate (temp_fd, 0);
3125+}
3126+
3127 static int
3128 do_test_with_offset (off_t offset)
3129 {
79da3d52 3130diff --git a/misc/tst-preadvwritev2-common.c b/misc/tst-preadvwritev2-common.c
da524a4e 3131index 89fd0a3ff5..50b9da3fea 100644
79da3d52
VM
3132--- a/misc/tst-preadvwritev2-common.c
3133+++ b/misc/tst-preadvwritev2-common.c
da524a4e
VM
3134@@ -19,9 +19,6 @@
3135 #include <limits.h>
3136 #include <support/check.h>
3137
3138-static void
3139-do_test_with_invalid_flags (void)
3140-{
3141 #ifndef RWF_HIPRI
3142 # define RWF_HIPRI 0
3143 #endif
3144@@ -34,7 +31,73 @@ do_test_with_invalid_flags (void)
79da3d52
VM
3145 #ifndef RWF_NOWAIT
3146 # define RWF_NOWAIT 0
3147 #endif
3148-#define RWF_SUPPORTED (RWF_HIPRI | RWF_DSYNC | RWF_SYNC | RWF_NOWAIT)
3149+#ifndef RWF_APPEND
3150+# define RWF_APPEND 0
3151+#endif
3152+#define RWF_SUPPORTED (RWF_HIPRI | RWF_DSYNC | RWF_SYNC | RWF_NOWAIT \
3153+ | RWF_APPEND)
da524a4e
VM
3154+
3155+static void
3156+do_test_with_invalid_fd (void)
3157+{
3158+ char buf[256];
3159+ struct iovec iov = { buf, sizeof buf };
3160+
3161+ /* Check with flag being 0 to use the fallback code which calls pwritev
3162+ or writev. */
3163+ TEST_VERIFY (preadv2 (-1, &iov, 1, -1, 0) == -1);
3164+ TEST_COMPARE (errno, EBADF);
3165+ TEST_VERIFY (pwritev2 (-1, &iov, 1, -1, 0) == -1);
3166+ TEST_COMPARE (errno, EBADF);
3167+
3168+ /* Same tests as before but with flags being different than 0. Since
3169+ there is no emulation for any flag value, fallback code returns
3170+ ENOTSUP. This is different running on a kernel with preadv2/pwritev2
3171+ support, where EBADF is returned). */
3172+ TEST_VERIFY (preadv2 (-1, &iov, 1, 0, RWF_HIPRI) == -1);
3173+ TEST_VERIFY (errno == EBADF || errno == ENOTSUP);
3174+ TEST_VERIFY (pwritev2 (-1, &iov, 1, 0, RWF_HIPRI) == -1);
3175+ TEST_VERIFY (errno == EBADF || errno == ENOTSUP);
3176+}
3177+
3178+static void
3179+do_test_with_invalid_iov (void)
3180+{
3181+ {
3182+ char buf[256];
3183+ struct iovec iov;
3184+
3185+ iov.iov_base = buf;
3186+ iov.iov_len = (size_t)SSIZE_MAX + 1;
3187+
3188+ TEST_VERIFY (preadv2 (temp_fd, &iov, 1, 0, 0) == -1);
3189+ TEST_COMPARE (errno, EINVAL);
3190+ TEST_VERIFY (pwritev2 (temp_fd, &iov, 1, 0, 0) == -1);
3191+ TEST_COMPARE (errno, EINVAL);
3192+
3193+ /* Same as for invalid file descriptor tests, emulation fallback
3194+ first checks for flag value and return ENOTSUP. */
3195+ TEST_VERIFY (preadv2 (temp_fd, &iov, 1, 0, RWF_HIPRI) == -1);
3196+ TEST_VERIFY (errno == EINVAL || errno == ENOTSUP);
3197+ TEST_VERIFY (pwritev2 (temp_fd, &iov, 1, 0, RWF_HIPRI) == -1);
3198+ TEST_VERIFY (errno == EINVAL || errno == ENOTSUP);
3199+ }
3200+
3201+ {
3202+ /* An invalid iovec buffer should trigger an invalid memory access
3203+ or an error (Linux for instance returns EFAULT). */
3204+ struct iovec iov[IOV_MAX+1] = { 0 };
3205+
3206+ TEST_VERIFY (preadv2 (temp_fd, iov, IOV_MAX + 1, 0, RWF_HIPRI) == -1);
3207+ TEST_VERIFY (errno == EINVAL || errno == ENOTSUP);
3208+ TEST_VERIFY (pwritev2 (temp_fd, iov, IOV_MAX + 1, 0, RWF_HIPRI) == -1);
3209+ TEST_VERIFY (errno == EINVAL || errno == ENOTSUP);
3210+ }
3211+}
3212+
3213+static void
3214+do_test_with_invalid_flags (void)
3215+{
79da3d52
VM
3216 /* Set the next bit from the mask of all supported flags. */
3217 int invalid_flag = RWF_SUPPORTED != 0 ? __builtin_clz (RWF_SUPPORTED) : 2;
3218 invalid_flag = 0x1 << ((sizeof (int) * CHAR_BIT) - invalid_flag);
da524a4e
VM
3219diff --git a/misc/tst-preadvwritev2.c b/misc/tst-preadvwritev2.c
3220index d8a9daf66a..cb58cbe41e 100644
3221--- a/misc/tst-preadvwritev2.c
3222+++ b/misc/tst-preadvwritev2.c
3223@@ -29,6 +29,9 @@ static int
3224 do_test (void)
3225 {
3226 do_test_with_invalid_flags ();
3227+ do_test_without_offset ();
3228+ do_test_with_invalid_fd ();
3229+ do_test_with_invalid_iov ();
3230
3231 return do_test_with_offset (0);
3232 }
3233diff --git a/misc/tst-preadvwritev64v2.c b/misc/tst-preadvwritev64v2.c
3234index 2c656ae3d7..6a9de54c78 100644
3235--- a/misc/tst-preadvwritev64v2.c
3236+++ b/misc/tst-preadvwritev64v2.c
3237@@ -31,6 +31,9 @@ static int
3238 do_test (void)
3239 {
3240 do_test_with_invalid_flags ();
3241+ do_test_without_offset ();
3242+ do_test_with_invalid_fd ();
3243+ do_test_with_invalid_iov ();
3244
3245 return do_test_with_offset (0);
3246 }
3247diff --git a/nptl/Makefile b/nptl/Makefile
3248index 6fc2c8bb6a..a3447addea 100644
3249--- a/nptl/Makefile
3250+++ b/nptl/Makefile
3251@@ -235,9 +235,9 @@ LDLIBS-tst-minstack-throw = -lstdc++
3252
3253 tests = tst-attr1 tst-attr2 tst-attr3 tst-default-attr \
3254 tst-mutex1 tst-mutex2 tst-mutex3 tst-mutex4 tst-mutex5 tst-mutex6 \
3255- tst-mutex7 tst-mutex9 tst-mutex5a tst-mutex7a tst-mutex7robust \
3256- tst-mutexpi1 tst-mutexpi2 tst-mutexpi3 tst-mutexpi4 tst-mutexpi5 \
3257- tst-mutexpi5a tst-mutexpi6 tst-mutexpi7 tst-mutexpi7a \
3258+ tst-mutex7 tst-mutex9 tst-mutex10 tst-mutex5a tst-mutex7a \
3259+ tst-mutex7robust tst-mutexpi1 tst-mutexpi2 tst-mutexpi3 tst-mutexpi4 \
3260+ tst-mutexpi5 tst-mutexpi5a tst-mutexpi6 tst-mutexpi7 tst-mutexpi7a \
3261 tst-mutexpi9 \
3262 tst-spin1 tst-spin2 tst-spin3 tst-spin4 \
3263 tst-cond1 tst-cond2 tst-cond3 tst-cond4 tst-cond5 tst-cond6 tst-cond7 \
3264@@ -730,6 +730,8 @@ $(objpfx)tst-compat-forwarder: $(objpfx)tst-compat-forwarder-mod.so
3265 # destroying a mutex.
3266 tst-mutex8-ENV = GLIBC_TUNABLES=glibc.elision.enable=0
3267
3268+tst-mutex10-ENV = GLIBC_TUNABLES=glibc.elision.enable=1
3269+
3270 # The tests here better do not run in parallel
3271 ifneq ($(filter %tests,$(MAKECMDGOALS)),)
3272 .NOTPARALLEL:
3273diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
3274index 583515ff48..ff51f452c6 100644
3275--- a/nptl/pthreadP.h
3276+++ b/nptl/pthreadP.h
3277@@ -110,19 +110,23 @@ enum
3278 };
3279 #define PTHREAD_MUTEX_PSHARED_BIT 128
3280
3281+/* See concurrency notes regarding __kind in struct __pthread_mutex_s
3282+ in sysdeps/nptl/bits/thread-shared-types.h. */
3283 #define PTHREAD_MUTEX_TYPE(m) \
3284- ((m)->__data.__kind & 127)
3285+ (atomic_load_relaxed (&((m)->__data.__kind)) & 127)
3286 /* Don't include NO_ELISION, as that type is always the same
3287 as the underlying lock type. */
3288 #define PTHREAD_MUTEX_TYPE_ELISION(m) \
3289- ((m)->__data.__kind & (127|PTHREAD_MUTEX_ELISION_NP))
3290+ (atomic_load_relaxed (&((m)->__data.__kind)) \
3291+ & (127 | PTHREAD_MUTEX_ELISION_NP))
3292
3293 #if LLL_PRIVATE == 0 && LLL_SHARED == 128
3294 # define PTHREAD_MUTEX_PSHARED(m) \
3295- ((m)->__data.__kind & 128)
3296+ (atomic_load_relaxed (&((m)->__data.__kind)) & 128)
3297 #else
3298 # define PTHREAD_MUTEX_PSHARED(m) \
3299- (((m)->__data.__kind & 128) ? LLL_SHARED : LLL_PRIVATE)
3300+ ((atomic_load_relaxed (&((m)->__data.__kind)) & 128) \
3301+ ? LLL_SHARED : LLL_PRIVATE)
3302 #endif
3303
3304 /* The kernel when waking robust mutexes on exit never uses
3305diff --git a/nptl/pthread_cond_common.c b/nptl/pthread_cond_common.c
3306index 8e425eb01e..479e54febb 100644
3307--- a/nptl/pthread_cond_common.c
3308+++ b/nptl/pthread_cond_common.c
3309@@ -405,8 +405,12 @@ __condvar_quiesce_and_switch_g1 (pthread_cond_t *cond, uint64_t wseq,
3310 {
3311 /* There is still a waiter after spinning. Set the wake-request
3312 flag and block. Relaxed MO is fine because this is just about
3313- this futex word. */
3314- r = atomic_fetch_or_relaxed (cond->__data.__g_refs + g1, 1);
3315+ this futex word.
3316+
3317+ Update r to include the set wake-request flag so that the upcoming
3318+ futex_wait only blocks if the flag is still set (otherwise, we'd
3319+ violate the basic client-side futex protocol). */
3320+ r = atomic_fetch_or_relaxed (cond->__data.__g_refs + g1, 1) | 1;
3321
3322 if ((r >> 1) > 0)
3323 futex_wait_simple (cond->__data.__g_refs + g1, r, private);
3324diff --git a/nptl/pthread_mutex_consistent.c b/nptl/pthread_mutex_consistent.c
3325index 85b8e1a6cb..4fbd875430 100644
3326--- a/nptl/pthread_mutex_consistent.c
3327+++ b/nptl/pthread_mutex_consistent.c
3328@@ -23,8 +23,11 @@
3329 int
3330 pthread_mutex_consistent (pthread_mutex_t *mutex)
3331 {
3332- /* Test whether this is a robust mutex with a dead owner. */
3333- if ((mutex->__data.__kind & PTHREAD_MUTEX_ROBUST_NORMAL_NP) == 0
3334+ /* Test whether this is a robust mutex with a dead owner.
3335+ See concurrency notes regarding __kind in struct __pthread_mutex_s
3336+ in sysdeps/nptl/bits/thread-shared-types.h. */
3337+ if ((atomic_load_relaxed (&(mutex->__data.__kind))
3338+ & PTHREAD_MUTEX_ROBUST_NORMAL_NP) == 0
3339 || mutex->__data.__owner != PTHREAD_MUTEX_INCONSISTENT)
3340 return EINVAL;
3341
3342diff --git a/nptl/pthread_mutex_destroy.c b/nptl/pthread_mutex_destroy.c
3343index 5a22611541..713ea68496 100644
3344--- a/nptl/pthread_mutex_destroy.c
3345+++ b/nptl/pthread_mutex_destroy.c
3346@@ -27,12 +27,17 @@ __pthread_mutex_destroy (pthread_mutex_t *mutex)
3347 {
3348 LIBC_PROBE (mutex_destroy, 1, mutex);
3349
3350- if ((mutex->__data.__kind & PTHREAD_MUTEX_ROBUST_NORMAL_NP) == 0
3351+ /* See concurrency notes regarding __kind in struct __pthread_mutex_s
3352+ in sysdeps/nptl/bits/thread-shared-types.h. */
3353+ if ((atomic_load_relaxed (&(mutex->__data.__kind))
3354+ & PTHREAD_MUTEX_ROBUST_NORMAL_NP) == 0
3355 && mutex->__data.__nusers != 0)
3356 return EBUSY;
3357
3358- /* Set to an invalid value. */
3359- mutex->__data.__kind = -1;
3360+ /* Set to an invalid value. Relaxed MO is enough as it is undefined behavior
3361+ if the mutex is used after it has been destroyed. But you can reinitialize
3362+ it with pthread_mutex_init. */
3363+ atomic_store_relaxed (&(mutex->__data.__kind), -1);
3364
3365 return 0;
3366 }
3367diff --git a/nptl/pthread_mutex_getprioceiling.c b/nptl/pthread_mutex_getprioceiling.c
3368index efa37b0d99..ee85949578 100644
3369--- a/nptl/pthread_mutex_getprioceiling.c
3370+++ b/nptl/pthread_mutex_getprioceiling.c
3371@@ -24,7 +24,9 @@
3372 int
3373 pthread_mutex_getprioceiling (const pthread_mutex_t *mutex, int *prioceiling)
3374 {
3375- if (__builtin_expect ((mutex->__data.__kind
3376+ /* See concurrency notes regarding __kind in struct __pthread_mutex_s
3377+ in sysdeps/nptl/bits/thread-shared-types.h. */
3378+ if (__builtin_expect ((atomic_load_relaxed (&(mutex->__data.__kind))
3379 & PTHREAD_MUTEX_PRIO_PROTECT_NP) == 0, 0))
3380 return EINVAL;
3381
3382diff --git a/nptl/pthread_mutex_init.c b/nptl/pthread_mutex_init.c
3383index d8fe473728..5cf290c272 100644
3384--- a/nptl/pthread_mutex_init.c
3385+++ b/nptl/pthread_mutex_init.c
3386@@ -101,7 +101,7 @@ __pthread_mutex_init (pthread_mutex_t *mutex,
3387 memset (mutex, '\0', __SIZEOF_PTHREAD_MUTEX_T);
3388
3389 /* Copy the values from the attribute. */
3390- mutex->__data.__kind = imutexattr->mutexkind & ~PTHREAD_MUTEXATTR_FLAG_BITS;
3391+ int mutex_kind = imutexattr->mutexkind & ~PTHREAD_MUTEXATTR_FLAG_BITS;
3392
3393 if ((imutexattr->mutexkind & PTHREAD_MUTEXATTR_FLAG_ROBUST) != 0)
3394 {
3395@@ -111,17 +111,17 @@ __pthread_mutex_init (pthread_mutex_t *mutex,
3396 return ENOTSUP;
3397 #endif
3398
3399- mutex->__data.__kind |= PTHREAD_MUTEX_ROBUST_NORMAL_NP;
3400+ mutex_kind |= PTHREAD_MUTEX_ROBUST_NORMAL_NP;
3401 }
3402
3403 switch (imutexattr->mutexkind & PTHREAD_MUTEXATTR_PROTOCOL_MASK)
3404 {
3405 case PTHREAD_PRIO_INHERIT << PTHREAD_MUTEXATTR_PROTOCOL_SHIFT:
3406- mutex->__data.__kind |= PTHREAD_MUTEX_PRIO_INHERIT_NP;
3407+ mutex_kind |= PTHREAD_MUTEX_PRIO_INHERIT_NP;
3408 break;
3409
3410 case PTHREAD_PRIO_PROTECT << PTHREAD_MUTEXATTR_PROTOCOL_SHIFT:
3411- mutex->__data.__kind |= PTHREAD_MUTEX_PRIO_PROTECT_NP;
3412+ mutex_kind |= PTHREAD_MUTEX_PRIO_PROTECT_NP;
3413
3414 int ceiling = (imutexattr->mutexkind
3415 & PTHREAD_MUTEXATTR_PRIO_CEILING_MASK)
3416@@ -145,7 +145,11 @@ __pthread_mutex_init (pthread_mutex_t *mutex,
3417 FUTEX_PRIVATE_FLAG FUTEX_WAKE. */
3418 if ((imutexattr->mutexkind & (PTHREAD_MUTEXATTR_FLAG_PSHARED
3419 | PTHREAD_MUTEXATTR_FLAG_ROBUST)) != 0)
3420- mutex->__data.__kind |= PTHREAD_MUTEX_PSHARED_BIT;
3421+ mutex_kind |= PTHREAD_MUTEX_PSHARED_BIT;
3422+
3423+ /* See concurrency notes regarding __kind in struct __pthread_mutex_s
3424+ in sysdeps/nptl/bits/thread-shared-types.h. */
3425+ atomic_store_relaxed (&(mutex->__data.__kind), mutex_kind);
3426
3427 /* Default values: mutex not used yet. */
3428 // mutex->__count = 0; already done by memset
3429diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c
3430index 1519c142bd..29cc143e6c 100644
3431--- a/nptl/pthread_mutex_lock.c
3432+++ b/nptl/pthread_mutex_lock.c
3433@@ -62,6 +62,8 @@ static int __pthread_mutex_lock_full (pthread_mutex_t *mutex)
3434 int
3435 __pthread_mutex_lock (pthread_mutex_t *mutex)
3436 {
3437+ /* See concurrency notes regarding mutex type which is loaded from __kind
3438+ in struct __pthread_mutex_s in sysdeps/nptl/bits/thread-shared-types.h. */
3439 unsigned int type = PTHREAD_MUTEX_TYPE_ELISION (mutex);
3440
3441 LIBC_PROBE (mutex_entry, 1, mutex);
3442@@ -350,8 +352,14 @@ __pthread_mutex_lock_full (pthread_mutex_t *mutex)
3443 case PTHREAD_MUTEX_PI_ROBUST_NORMAL_NP:
3444 case PTHREAD_MUTEX_PI_ROBUST_ADAPTIVE_NP:
3445 {
3446- int kind = mutex->__data.__kind & PTHREAD_MUTEX_KIND_MASK_NP;
3447- int robust = mutex->__data.__kind & PTHREAD_MUTEX_ROBUST_NORMAL_NP;
3448+ int kind, robust;
3449+ {
3450+ /* See concurrency notes regarding __kind in struct __pthread_mutex_s
3451+ in sysdeps/nptl/bits/thread-shared-types.h. */
3452+ int mutex_kind = atomic_load_relaxed (&(mutex->__data.__kind));
3453+ kind = mutex_kind & PTHREAD_MUTEX_KIND_MASK_NP;
3454+ robust = mutex_kind & PTHREAD_MUTEX_ROBUST_NORMAL_NP;
3455+ }
3456
3457 if (robust)
3458 {
3459@@ -502,7 +510,10 @@ __pthread_mutex_lock_full (pthread_mutex_t *mutex)
3460 case PTHREAD_MUTEX_PP_NORMAL_NP:
3461 case PTHREAD_MUTEX_PP_ADAPTIVE_NP:
3462 {
3463- int kind = mutex->__data.__kind & PTHREAD_MUTEX_KIND_MASK_NP;
3464+ /* See concurrency notes regarding __kind in struct __pthread_mutex_s
3465+ in sysdeps/nptl/bits/thread-shared-types.h. */
3466+ int kind = atomic_load_relaxed (&(mutex->__data.__kind))
3467+ & PTHREAD_MUTEX_KIND_MASK_NP;
3468
3469 oldval = mutex->__data.__lock;
3470
3471@@ -607,15 +618,18 @@ hidden_def (__pthread_mutex_lock)
3472 void
3473 __pthread_mutex_cond_lock_adjust (pthread_mutex_t *mutex)
3474 {
3475- assert ((mutex->__data.__kind & PTHREAD_MUTEX_PRIO_INHERIT_NP) != 0);
3476- assert ((mutex->__data.__kind & PTHREAD_MUTEX_ROBUST_NORMAL_NP) == 0);
3477- assert ((mutex->__data.__kind & PTHREAD_MUTEX_PSHARED_BIT) == 0);
3478+ /* See concurrency notes regarding __kind in struct __pthread_mutex_s
3479+ in sysdeps/nptl/bits/thread-shared-types.h. */
3480+ int mutex_kind = atomic_load_relaxed (&(mutex->__data.__kind));
3481+ assert ((mutex_kind & PTHREAD_MUTEX_PRIO_INHERIT_NP) != 0);
3482+ assert ((mutex_kind & PTHREAD_MUTEX_ROBUST_NORMAL_NP) == 0);
3483+ assert ((mutex_kind & PTHREAD_MUTEX_PSHARED_BIT) == 0);
3484
3485 /* Record the ownership. */
3486 pid_t id = THREAD_GETMEM (THREAD_SELF, tid);
3487 mutex->__data.__owner = id;
3488
3489- if (mutex->__data.__kind == PTHREAD_MUTEX_PI_RECURSIVE_NP)
3490+ if (mutex_kind == PTHREAD_MUTEX_PI_RECURSIVE_NP)
3491 ++mutex->__data.__count;
3492 }
3493 #endif
3494diff --git a/nptl/pthread_mutex_setprioceiling.c b/nptl/pthread_mutex_setprioceiling.c
3495index 8594874f85..8306cabcf4 100644
3496--- a/nptl/pthread_mutex_setprioceiling.c
3497+++ b/nptl/pthread_mutex_setprioceiling.c
3498@@ -27,9 +27,10 @@ int
3499 pthread_mutex_setprioceiling (pthread_mutex_t *mutex, int prioceiling,
3500 int *old_ceiling)
3501 {
3502- /* The low bits of __kind aren't ever changed after pthread_mutex_init,
3503- so we don't need a lock yet. */
3504- if ((mutex->__data.__kind & PTHREAD_MUTEX_PRIO_PROTECT_NP) == 0)
3505+ /* See concurrency notes regarding __kind in struct __pthread_mutex_s
3506+ in sysdeps/nptl/bits/thread-shared-types.h. */
3507+ if ((atomic_load_relaxed (&(mutex->__data.__kind))
3508+ & PTHREAD_MUTEX_PRIO_PROTECT_NP) == 0)
3509 return EINVAL;
3510
3511 /* See __init_sched_fifo_prio. */
3512diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c
3513index 66efd3989f..40b559f517 100644
3514--- a/nptl/pthread_mutex_timedlock.c
3515+++ b/nptl/pthread_mutex_timedlock.c
3516@@ -53,6 +53,8 @@ __pthread_mutex_timedlock (pthread_mutex_t *mutex,
3517 /* We must not check ABSTIME here. If the thread does not block
3518 abstime must not be checked for a valid value. */
3519
3520+ /* See concurrency notes regarding mutex type which is loaded from __kind
3521+ in struct __pthread_mutex_s in sysdeps/nptl/bits/thread-shared-types.h. */
3522 switch (__builtin_expect (PTHREAD_MUTEX_TYPE_ELISION (mutex),
3523 PTHREAD_MUTEX_TIMED_NP))
3524 {
3525@@ -338,8 +340,14 @@ __pthread_mutex_timedlock (pthread_mutex_t *mutex,
3526 case PTHREAD_MUTEX_PI_ROBUST_NORMAL_NP:
3527 case PTHREAD_MUTEX_PI_ROBUST_ADAPTIVE_NP:
3528 {
3529- int kind = mutex->__data.__kind & PTHREAD_MUTEX_KIND_MASK_NP;
3530- int robust = mutex->__data.__kind & PTHREAD_MUTEX_ROBUST_NORMAL_NP;
3531+ int kind, robust;
3532+ {
3533+ /* See concurrency notes regarding __kind in struct __pthread_mutex_s
3534+ in sysdeps/nptl/bits/thread-shared-types.h. */
3535+ int mutex_kind = atomic_load_relaxed (&(mutex->__data.__kind));
3536+ kind = mutex_kind & PTHREAD_MUTEX_KIND_MASK_NP;
3537+ robust = mutex_kind & PTHREAD_MUTEX_ROBUST_NORMAL_NP;
3538+ }
3539
3540 if (robust)
3541 {
3542@@ -509,7 +517,10 @@ __pthread_mutex_timedlock (pthread_mutex_t *mutex,
3543 case PTHREAD_MUTEX_PP_NORMAL_NP:
3544 case PTHREAD_MUTEX_PP_ADAPTIVE_NP:
3545 {
3546- int kind = mutex->__data.__kind & PTHREAD_MUTEX_KIND_MASK_NP;
3547+ /* See concurrency notes regarding __kind in struct __pthread_mutex_s
3548+ in sysdeps/nptl/bits/thread-shared-types.h. */
3549+ int kind = atomic_load_relaxed (&(mutex->__data.__kind))
3550+ & PTHREAD_MUTEX_KIND_MASK_NP;
3551
3552 oldval = mutex->__data.__lock;
3553
3554diff --git a/nptl/pthread_mutex_trylock.c b/nptl/pthread_mutex_trylock.c
3555index 7de61f4f68..fa90c1d1e6 100644
3556--- a/nptl/pthread_mutex_trylock.c
3557+++ b/nptl/pthread_mutex_trylock.c
3558@@ -36,6 +36,8 @@ __pthread_mutex_trylock (pthread_mutex_t *mutex)
3559 int oldval;
3560 pid_t id = THREAD_GETMEM (THREAD_SELF, tid);
3561
3562+ /* See concurrency notes regarding mutex type which is loaded from __kind
3563+ in struct __pthread_mutex_s in sysdeps/nptl/bits/thread-shared-types.h. */
3564 switch (__builtin_expect (PTHREAD_MUTEX_TYPE_ELISION (mutex),
3565 PTHREAD_MUTEX_TIMED_NP))
3566 {
3567@@ -199,8 +201,14 @@ __pthread_mutex_trylock (pthread_mutex_t *mutex)
3568 case PTHREAD_MUTEX_PI_ROBUST_NORMAL_NP:
3569 case PTHREAD_MUTEX_PI_ROBUST_ADAPTIVE_NP:
3570 {
3571- int kind = mutex->__data.__kind & PTHREAD_MUTEX_KIND_MASK_NP;
3572- int robust = mutex->__data.__kind & PTHREAD_MUTEX_ROBUST_NORMAL_NP;
3573+ int kind, robust;
3574+ {
3575+ /* See concurrency notes regarding __kind in struct __pthread_mutex_s
3576+ in sysdeps/nptl/bits/thread-shared-types.h. */
3577+ int mutex_kind = atomic_load_relaxed (&(mutex->__data.__kind));
3578+ kind = mutex_kind & PTHREAD_MUTEX_KIND_MASK_NP;
3579+ robust = mutex_kind & PTHREAD_MUTEX_ROBUST_NORMAL_NP;
3580+ }
3581
3582 if (robust)
3583 /* Note: robust PI futexes are signaled by setting bit 0. */
3584@@ -325,7 +333,10 @@ __pthread_mutex_trylock (pthread_mutex_t *mutex)
3585 case PTHREAD_MUTEX_PP_NORMAL_NP:
3586 case PTHREAD_MUTEX_PP_ADAPTIVE_NP:
3587 {
3588- int kind = mutex->__data.__kind & PTHREAD_MUTEX_KIND_MASK_NP;
3589+ /* See concurrency notes regarding __kind in struct __pthread_mutex_s
3590+ in sysdeps/nptl/bits/thread-shared-types.h. */
3591+ int kind = atomic_load_relaxed (&(mutex->__data.__kind))
3592+ & PTHREAD_MUTEX_KIND_MASK_NP;
3593
3594 oldval = mutex->__data.__lock;
3595
3596diff --git a/nptl/pthread_mutex_unlock.c b/nptl/pthread_mutex_unlock.c
3597index 9ea62943b7..68d04d5395 100644
3598--- a/nptl/pthread_mutex_unlock.c
3599+++ b/nptl/pthread_mutex_unlock.c
3600@@ -35,6 +35,8 @@ int
3601 attribute_hidden
3602 __pthread_mutex_unlock_usercnt (pthread_mutex_t *mutex, int decr)
3603 {
3604+ /* See concurrency notes regarding mutex type which is loaded from __kind
3605+ in struct __pthread_mutex_s in sysdeps/nptl/bits/thread-shared-types.h. */
3606 int type = PTHREAD_MUTEX_TYPE_ELISION (mutex);
3607 if (__builtin_expect (type &
3608 ~(PTHREAD_MUTEX_KIND_MASK_NP|PTHREAD_MUTEX_ELISION_FLAGS_NP), 0))
3609@@ -222,13 +224,19 @@ __pthread_mutex_unlock_full (pthread_mutex_t *mutex, int decr)
3610 /* If the previous owner died and the caller did not succeed in
3611 making the state consistent, mark the mutex as unrecoverable
3612 and make all waiters. */
3613- if ((mutex->__data.__kind & PTHREAD_MUTEX_ROBUST_NORMAL_NP) != 0
3614+ /* See concurrency notes regarding __kind in struct __pthread_mutex_s
3615+ in sysdeps/nptl/bits/thread-shared-types.h. */
3616+ if ((atomic_load_relaxed (&(mutex->__data.__kind))
3617+ & PTHREAD_MUTEX_ROBUST_NORMAL_NP) != 0
3618 && __builtin_expect (mutex->__data.__owner
3619 == PTHREAD_MUTEX_INCONSISTENT, 0))
3620 pi_notrecoverable:
3621 newowner = PTHREAD_MUTEX_NOTRECOVERABLE;
3622
3623- if ((mutex->__data.__kind & PTHREAD_MUTEX_ROBUST_NORMAL_NP) != 0)
3624+ /* See concurrency notes regarding __kind in struct __pthread_mutex_s
3625+ in sysdeps/nptl/bits/thread-shared-types.h. */
3626+ if ((atomic_load_relaxed (&(mutex->__data.__kind))
3627+ & PTHREAD_MUTEX_ROBUST_NORMAL_NP) != 0)
3628 {
3629 continue_pi_robust:
3630 /* Remove mutex from the list.
3631@@ -251,7 +259,10 @@ __pthread_mutex_unlock_full (pthread_mutex_t *mutex, int decr)
3632 /* Unlock. Load all necessary mutex data before releasing the mutex
3633 to not violate the mutex destruction requirements (see
3634 lll_unlock). */
3635- int robust = mutex->__data.__kind & PTHREAD_MUTEX_ROBUST_NORMAL_NP;
3636+ /* See concurrency notes regarding __kind in struct __pthread_mutex_s
3637+ in sysdeps/nptl/bits/thread-shared-types.h. */
3638+ int robust = atomic_load_relaxed (&(mutex->__data.__kind))
3639+ & PTHREAD_MUTEX_ROBUST_NORMAL_NP;
3640 private = (robust
3641 ? PTHREAD_ROBUST_MUTEX_PSHARED (mutex)
3642 : PTHREAD_MUTEX_PSHARED (mutex));
3643diff --git a/nptl/tst-mutex10.c b/nptl/tst-mutex10.c
3644new file mode 100644
3645index 0000000000..e1113ca60a
3646--- /dev/null
3647+++ b/nptl/tst-mutex10.c
3648@@ -0,0 +1,109 @@
3649+/* Testing race while enabling lock elision.
3650+ Copyright (C) 2018 Free Software Foundation, Inc.
3651+ This file is part of the GNU C Library.
3652+
3653+ The GNU C Library is free software; you can redistribute it and/or
3654+ modify it under the terms of the GNU Lesser General Public
3655+ License as published by the Free Software Foundation; either
3656+ version 2.1 of the License, or (at your option) any later version.
3657+
3658+ The GNU C Library is distributed in the hope that it will be useful,
3659+ but WITHOUT ANY WARRANTY; without even the implied warranty of
3660+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3661+ Lesser General Public License for more details.
3662+
3663+ You should have received a copy of the GNU Lesser General Public
3664+ License along with the GNU C Library; if not, see
3665+ <http://www.gnu.org/licenses/>. */
3666+#include <stdio.h>
3667+#include <stdlib.h>
3668+#include <stdint.h>
3669+#include <pthread.h>
3670+#include <unistd.h>
3671+#include <getopt.h>
3672+#include <support/support.h>
3673+#include <support/xthread.h>
3674+
3675+static pthread_barrier_t barrier;
3676+static pthread_mutex_t mutex;
3677+static long long int iteration_count = 1000000;
3678+static unsigned int thread_count = 3;
3679+
3680+static void *
3681+thr_func (void *arg)
3682+{
3683+ long long int i;
3684+ for (i = 0; i < iteration_count; i++)
3685+ {
3686+ if ((uintptr_t) arg == 0)
3687+ {
3688+ xpthread_mutex_destroy (&mutex);
3689+ xpthread_mutex_init (&mutex, NULL);
3690+ }
3691+
3692+ xpthread_barrier_wait (&barrier);
3693+
3694+ /* Test if enabling lock elision works if it is enabled concurrently.
3695+ There was a race in FORCE_ELISION macro which leads to either
3696+ pthread_mutex_destroy returning EBUSY as the owner was recorded
3697+ by pthread_mutex_lock - in "normal mutex" code path - but was not
3698+ resetted in pthread_mutex_unlock - in "elision" code path.
3699+ Or it leads to the assertion in nptl/pthread_mutex_lock.c:
3700+ assert (mutex->__data.__owner == 0);
3701+ Please ensure that the test is run with lock elision:
3702+ export GLIBC_TUNABLES=glibc.elision.enable=1 */
3703+ xpthread_mutex_lock (&mutex);
3704+ xpthread_mutex_unlock (&mutex);
3705+
3706+ xpthread_barrier_wait (&barrier);
3707+ }
3708+ return NULL;
3709+}
3710+
3711+static int
3712+do_test (void)
3713+{
3714+ unsigned int i;
3715+ printf ("Starting %d threads to run %lld iterations.\n",
3716+ thread_count, iteration_count);
3717+
3718+ pthread_t *threads = xmalloc (thread_count * sizeof (pthread_t));
3719+ xpthread_barrier_init (&barrier, NULL, thread_count);
3720+ xpthread_mutex_init (&mutex, NULL);
3721+
3722+ for (i = 0; i < thread_count; i++)
3723+ threads[i] = xpthread_create (NULL, thr_func, (void *) (uintptr_t) i);
3724+
3725+ for (i = 0; i < thread_count; i++)
3726+ xpthread_join (threads[i]);
3727+
3728+ xpthread_barrier_destroy (&barrier);
3729+ free (threads);
3730+
3731+ return EXIT_SUCCESS;
3732+}
3733+
3734+#define OPT_ITERATIONS 10000
3735+#define OPT_THREADS 10001
3736+#define CMDLINE_OPTIONS \
3737+ { "iterations", required_argument, NULL, OPT_ITERATIONS }, \
3738+ { "threads", required_argument, NULL, OPT_THREADS },
3739+static void
3740+cmdline_process (int c)
3741+{
3742+ long long int arg = strtoll (optarg, NULL, 0);
3743+ switch (c)
3744+ {
3745+ case OPT_ITERATIONS:
3746+ if (arg > 0)
3747+ iteration_count = arg;
3748+ break;
3749+ case OPT_THREADS:
3750+ if (arg > 0 && arg < 100)
3751+ thread_count = arg;
3752+ break;
3753+ }
3754+}
3755+#define CMDLINE_PROCESS cmdline_process
3756+#define TIMEOUT 50
3757+#include <support/test-driver.c>
79da3d52
VM
3758diff --git a/nscd/gai.c b/nscd/gai.c
3759index d081747797..576fd0045b 100644
3760--- a/nscd/gai.c
3761+++ b/nscd/gai.c
3762@@ -45,3 +45,6 @@
3763 #ifdef HAVE_LIBIDN
3764 # include <libidn/idn-stub.c>
3765 #endif
3766+
3767+/* Some variables normally defined in libc. */
3768+service_user *__nss_hosts_database attribute_hidden;
3769diff --git a/nscd/netgroupcache.c b/nscd/netgroupcache.c
3770index b832c9315f..2f187b208c 100644
3771--- a/nscd/netgroupcache.c
3772+++ b/nscd/netgroupcache.c
3773@@ -480,7 +480,7 @@ addinnetgrX (struct database_dyn *db, int fd, request_header *req,
3774 {
3775 const char *group = key;
3776 key = (char *) rawmemchr (key, '\0') + 1;
3777- size_t group_len = key - group - 1;
3778+ size_t group_len = key - group;
3779 const char *host = *key++ ? key : NULL;
3780 if (host != NULL)
3781 key = (char *) rawmemchr (key, '\0') + 1;
3782diff --git a/nss/nsswitch.c b/nss/nsswitch.c
3783index d5e655974f..b0f0c11a3e 100644
3784--- a/nss/nsswitch.c
3785+++ b/nss/nsswitch.c
3786@@ -62,7 +62,7 @@ static service_library *nss_new_service (name_database *database,
3787
3788 /* Declare external database variables. */
3789 #define DEFINE_DATABASE(name) \
3790- extern service_user *__nss_##name##_database attribute_hidden; \
3791+ service_user *__nss_##name##_database attribute_hidden; \
3792 weak_extern (__nss_##name##_database)
3793 #include "databases.def"
3794 #undef DEFINE_DATABASE
3795diff --git a/nss/nsswitch.h b/nss/nsswitch.h
3796index eccb535ef5..63573b9ebc 100644
3797--- a/nss/nsswitch.h
3798+++ b/nss/nsswitch.h
3799@@ -226,10 +226,10 @@ libc_hidden_proto (__nss_hostname_digits_dots)
3800 #define MAX_NR_ADDRS 48
3801
3802 /* Prototypes for __nss_*_lookup2 functions. */
3803-#define DEFINE_DATABASE(arg) \
3804- service_user *__nss_##arg##_database attribute_hidden; \
3805- int __nss_##arg##_lookup2 (service_user **, const char *, \
3806- const char *, void **); \
3807+#define DEFINE_DATABASE(arg) \
3808+ extern service_user *__nss_##arg##_database attribute_hidden; \
3809+ int __nss_##arg##_lookup2 (service_user **, const char *, \
3810+ const char *, void **); \
3811 libc_hidden_proto (__nss_##arg##_lookup2)
3812 #include "databases.def"
3813 #undef DEFINE_DATABASE
3814diff --git a/po/pt_BR.po b/po/pt_BR.po
3815index b7c1650957..d49d6ec279 100644
3816--- a/po/pt_BR.po
3817+++ b/po/pt_BR.po
3818@@ -1,4283 +1,7213 @@
3819-# Brazilian portuguese messages for glibc.
3820