Szabolcs Nagy [Wed, 25 Mar 2015 18:25:09 +0000 (18:25 +0000)]
regex: fix character class repetitions
Internally regcomp needs to copy some iteration nodes before
translating the AST into TNFA representation.
Literal nodes were not copied correctly: the class type and list
of negated class types were not copied so classes were ignored
(in the non-negated case an ignored char class caused the literal
to match everything).
This affects iterations when the upper bound is finite, larger
than one or the lower bound is larger than one. So eg. the EREs
[[:digit:]]{2}
[^[:space:]ab]{1,4}
were treated as
.{2}
[^ab]{1,4}
The fix is done with minimal source modification to copy the
necessary fields, but the AST preparation and node handling
code of tre will need to be cleaned up for clarity.
(cherry picked from commit
c498efe117539a9d40d90b588c033316701c4b3e)
Rich Felker [Mon, 23 Mar 2015 13:44:18 +0000 (09:44 -0400)]
fix internal buffer overrun in inet_pton
one stop condition for parsing abbreviated ipv6 addressed was missed,
allowing the internal ip[] buffer to overflow. this patch adds the
missing stop condition and masks the array index so that, in case
there are any remaining stop conditions missing, overflowing the
buffer is not possible.
(cherry picked from commit
fc13acc3dcb5b1f215c007f583a63551f6a71363)
Rich Felker [Mon, 30 Mar 2015 06:13:59 +0000 (02:13 -0400)]
fix regcomp handling of backslash followed by high byte
the regex parser handles the (undefined) case of an unexpected byte
following a backslash as a literal. however, instead of correctly
decoding a character, it was treating the byte value itself as a
character. this was not only semantically unjustified, but turned out
to be dangerous on archs where plain char is signed: bytes in the
range 252-255 alias the internal codes -4 through -1 used for special
types of literal nodes in the AST.
analogous to commit
39dfd58417ef642307d90306e1c7e50aaec5a35c in
mainline. it's unclear whether the same crash that affected mainline
is possible in the older regcomp code in 1.0.x, but conceptually the
bug is the same.
Rich Felker [Thu, 5 Mar 2015 02:46:08 +0000 (21:46 -0500)]
fix signed left-shift overflow in pthread_condattr_setpshared
(cherry picked from commit
380857bf21bcffbbee2fe8ab52feadf39366d7ec)
Rich Felker [Wed, 4 Mar 2015 19:15:44 +0000 (14:15 -0500)]
fix preprocessor error introduced in poll.h in last commit
(cherry picked from commit
91a3bd743e91604bde83e9ce1ad3a2e2d4ff0f0f)
Trutz Behn [Fri, 13 Feb 2015 17:10:52 +0000 (18:10 +0100)]
fix POLLWRNORM and POLLWRBAND on mips
these macros have the same distinct definition on blackfin, frv, m68k,
mips, sparc and xtensa kernels. POLLMSG and POLLRDHUP additionally
differ on sparc.
(cherry picked from commit
f5011c62c3329f15652a60b6b2300d7e3f570977)
Rich Felker [Wed, 4 Mar 2015 14:29:39 +0000 (09:29 -0500)]
fix init race that could lead to deadlock in malloc init code
the malloc init code provided its own version of pthread_once type
logic, including the exact same bug that was fixed in pthread_once in
commit
0d0c2f40344640a2a6942dda156509593f51db5d.
since this code is called adjacent to expand_heap, which takes a lock,
there is no reason to have pthread_once-type initialization. simply
moving the init code into the interval where expand_heap already holds
its lock on the brk achieves the same result with much less
synchronization logic, and allows the buggy code to be eliminated
rather than just fixed.
(cherry picked from commit
7a81fe3710be0128d29071e76c5acbea3d84277b)
Rich Felker [Wed, 2 Apr 2014 21:57:15 +0000 (17:57 -0400)]
avoid malloc failure for small requests when brk can't be extended
this issue mainly affects PIE binaries and execution of programs via
direct invocation of the dynamic linker binary: depending on kernel
behavior, in these cases the initial brk may be placed at at location
where it cannot be extended, due to conflicting adjacent maps.
when brk fails, mmap is used instead to expand the heap. in order to
avoid expensive bookkeeping for managing fragmentation by merging
these new heap regions, the minimum size for new heap regions
increases exponentially in the number of regions. this limits the
number of regions, and thereby the number of fixed fragmentation
points, to a quantity which is logarithmic with respect to the size of
virtual address space and thus negligible. the exponential growth is
tuned so as to avoid expanding the heap by more than approximately 50%
of its current total size.
(cherry picked from commit
5446303328adf4b4e36d9fba21848e6feb55fab4)
Rich Felker [Wed, 11 Feb 2015 06:37:01 +0000 (01:37 -0500)]
fix bad character checking in wordexp
the character sequence '$((' was incorrectly interpreted as the
opening of arithmetic even within single-quoted contexts, thereby
suppressing the checks for bad characters after the closing quote.
presently bad character checking is only performed when the WRDE_NOCMD
is used; this patch only corrects checking in that case.
(cherry picked from commit
594ffed82f4e6ee7da85e9c5da35e32946ae32c9)
Szabolcs Nagy [Sun, 8 Feb 2015 17:56:52 +0000 (18:56 +0100)]
fix fesetenv(FE_DFL_ENV) on mips
mips fesetenv did not handle FE_DFL_ENV, now fcsr is cleared in that
case.
(cherry picked from commit
5fc1487832e16aa2119e735a388d5f36c8c139e2)
Rich Felker [Fri, 6 Feb 2015 04:34:27 +0000 (23:34 -0500)]
fix failure of fchmodat to report EOPNOTSUPP in the race path
in the case where a non-symlink file was replaced by a symlink during
the fchmodat operation with AT_SYMLINK_NOFOLLOW, mode change on the
new symlink target was successfully suppressed, but the error was not
reported. instead, fchmodat simply returned 0.
(cherry picked from commit
61b1d102129990f6e903c6ddcf46c7d79d1a1e99)
(conflicts from commit
dd5f50da6f6c3df5647e922e47f8568a8896a752)
Rich Felker [Thu, 5 Feb 2015 03:50:40 +0000 (22:50 -0500)]
fix fd leak race (missing O_CLOEXEC) in fchmodat
(cherry picked from commit
2736eb6caa70bb6e909d7d8ebbe145c2071435e0)
Felix Janda [Sun, 1 Feb 2015 09:43:37 +0000 (10:43 +0100)]
fix typo in x86_64/x32 user_fpregs_struct
mxcs_mask should be mxcr_mask
(cherry picked from commit
4758f0565df83beb8f9b24857ec40ca3a40d2281)
Rich Felker [Wed, 21 Jan 2015 19:26:05 +0000 (14:26 -0500)]
fix erroneous return of partial username matches by getspnam[_r]
when using /etc/shadow (rather than tcb) as its backend, getspnam_r
matched any username starting with the caller-provided string rather
than requiring an exact match. in practice this seems to have affected
only systems where one valid username is a prefix for another valid
username, and where the longer username appears first in the shadow
file.
(cherry picked from commit
ecb608192a48d3688e1a0a21027bfd968d3301a1)
Rich Felker [Fri, 9 Jan 2015 05:09:54 +0000 (00:09 -0500)]
check for connect failure in syslog log opening
based on patch by Dima Krasner, with minor improvements for code size.
connect can fail if there is no listening syslogd, in which case a
useless socket was kept open, preventing subsequent syslog call from
attempting to connect again.
(cherry picked from commit
c574321d75f035ff6d2c18dfb7e3f70db60ba7bd)
Rich Felker [Wed, 17 Dec 2014 21:52:37 +0000 (16:52 -0500)]
fix signedness of WINT_MIN expression
since wint_t is unsigned, WINT_MIN needs to expand to an unsigned zero.
(cherry picked from commit
aee9b1526247f74e9b755b50e102b3b4ce2aac1d)
Rich Felker [Wed, 17 Dec 2014 08:08:53 +0000 (03:08 -0500)]
correctly handle write errors encountered by printf-family functions
previously, write errors neither stopped further output attempts nor
caused the function to return an error to the caller. this could
result in silent loss of output, possibly in the middle of output in
the event of a non-permanent error.
the simplest solution is temporarily clearing the error flag for the
target stream, then suppressing further output when the error flag is
set and checking/restoring it at the end of the operation to determine
the correct return value.
since the wide version of the code internally calls the narrow fprintf
to perform some of its underlying operations, initial clearing of the
error flag is suppressed when performing a narrow vfprintf on a
wide-oriented stream. this is not a problem since the behavior of
narrow operations on wide-oriented streams is undefined.
(cherry picked from commit
d42269d7c85308abdbf8cee38b1a1097249eb38b)
Rich Felker [Wed, 3 Dec 2014 03:17:52 +0000 (22:17 -0500)]
fix return value of pthread_getaffinity_np and pthread_setaffinity_np
these functions are expected to return an error code rather than
setting errno and returning -1.
(cherry picked from commit
66140b0c926ed097f2cb7474863523e4af351f5b)
Rich Felker [Wed, 3 Dec 2014 02:54:36 +0000 (21:54 -0500)]
fix uninitialized output from sched_getaffinity
the sched_getaffinity syscall only fills a cpu set up to the set size
used/supported by the kernel. the rest is left untouched and userspace
is responsible for zero-filling it based on the return value of the
syscall.
(cherry picked from commit
a56e339419c1a90f8a85f86621f3c73945e07b23)
Rich Felker [Sun, 23 Nov 2014 21:17:57 +0000 (16:17 -0500)]
adapt dynamic linker for new binutils versions that omit DT_RPATH
the new DT_RUNPATH semantics for search order are always used, and
since binutils had always set both DT_RPATH and DT_RUNPATH when the
latter was used, processing only DT_RPATH worked fine. however, recent
binutils has stopped generating DT_RPATH when DT_RUNPATH is used,
which broke support for this feature completely.
(cherry picked from commit
d8dc2b7c0289b12eeef4feff65e3c918111b0f55)
Rich Felker [Sat, 15 Nov 2014 17:16:19 +0000 (12:16 -0500)]
fix behavior of printf with alt-form octal, zero precision, zero value
in this case there are two conflicting rules in play: that an explicit
precision of zero with the value zero produces no output, and that the
'#' modifier for octal increases the precision sufficiently to yield a
leading zero. ISO C (7.19.6.1 paragraph 6 in C99+TC3) includes a
parenthetical remark to clarify that the precision-increasing behavior
takes precedence, but the corresponding text in POSIX off of which I
based the implementation is missing this remark.
this issue was covered in WG14 DR#151.
(cherry picked from commit
b91cdbe2bc8b626aa04dc6e3e84345accf34e4b1)
Szabolcs Nagy [Wed, 5 Nov 2014 20:40:29 +0000 (21:40 +0100)]
math: fix x86_64 and x32 asm not to use sahf instruction
Some early x86_64 cpus (released before 2006) did not support sahf/lahf
instructions so they should be avoided (intel manual says they are only
supported if CPUID.80000001H:ECX.LAHF-SAHF[bit 0] = 1).
The workaround simplifies exp2l and expm1l because fucomip can be
used instead of the fucomp;fnstsw;sahf sequence copied from i386.
In fmodl and remainderl sahf is replaced by a simple bit test.
(cherry picked from commit
a732e80d33b4fd6f510f7cec4f5573ef5d89bc4e)
Rich Felker [Fri, 31 Oct 2014 19:35:24 +0000 (15:35 -0400)]
fix uninitialized mode variable in openat function
this was introduced in commit
2da3ab1382ca8e39eb1e4428103764a81fba73d3
as an oversight while making the variadic argument access conditional.
(cherry picked from commit
e146e6035fecea080fb17450db3c8bb44d36e07d)
Rich Felker [Fri, 31 Oct 2014 00:08:40 +0000 (20:08 -0400)]
fix invalid access by openat to possibly-missing variadic mode argument
the mode argument is only required to be present when the O_CREAT or
O_TMPFILE flag is used.
(cherry picked from commit
2da3ab1382ca8e39eb1e4428103764a81fba73d3)
Rich Felker [Fri, 10 Oct 2014 22:20:33 +0000 (18:20 -0400)]
fix missing barrier in pthread_once/call_once shortcut path
these functions need to be fast when the init routine has already run,
since they may be called very often from code which depends on global
initialization having taken place. as such, a fast path bypassing
atomic cas on the once control object was used to avoid heavy memory
contention. however, on archs with weakly ordered memory, the fast
path failed to ensure that the caller actually observes the side
effects of the init routine.
preliminary performance testing showed that simply removing the fast
path was not practical; a performance drop of roughly 85x was observed
with 20 threads hammering the same once control on a 24-core machine.
so the new explicit barrier operation from atomic.h is used to retain
the fast path while ensuring memory visibility.
performance may be reduced on some archs where the barrier actually
makes a difference, but the previous behavior was unsafe and incorrect
on these archs. future improvements to the implementation of a_barrier
should reduce the impact.
(cherry picked from commit
df37d3960abec482e17fad2274a99b790f6cc08b)
(edited not to depend on a_barrier, which is not available in 1.0.x)
Rich Felker [Fri, 10 Oct 2014 03:44:02 +0000 (23:44 -0400)]
fix handling of negative offsets in timezone spec strings
previously, the hours were considered as a signed quantity while
minutes and seconds were always treated as positive offsets. however,
semantically the '-' sign should negate the whole hh:mm:ss offset.
this bug only affected timezones east of GMT with non-whole-hours
offsets, such as those used in India and Nepal.
(cherry picked from commit
08b996d180323775d5457944eefbb8a51ea72539)
Rich Felker [Sat, 4 Oct 2014 15:14:01 +0000 (11:14 -0400)]
fix handling of odd lengths in swab function
this function is specified to leave the last byte with "unspecified
disposition" when the length is odd, so for the most part correct
programs should not be calling swab with odd lengths. however, doing
so is permitted, and should not write past the end of the destination
buffer.
(cherry picked from commit
dccbf4c809efc311aa37da71de70d04dfd8b0db3)
Rich Felker [Mon, 22 Sep 2014 21:55:08 +0000 (17:55 -0400)]
fix incorrect sequence generation in *rand48 prng functions
patch by Jens Gustedt. this fixes a bug reported by Nadav Har'El. the
underlying issue was that a left-shift by 16 bits after promotion of
unsigned short to int caused integer overflow. while some compilers
define this overflow case as "shifting into the sign bit", doing so
doesn't help; the sign bit then gets extended through the upper bits
in subsequent arithmetic as unsigned long long. this patch imposes a
promotion to unsigned prior to the shift, so that the result is
well-defined and matches the specified behavior.
(cherry picked from commit
05cef96d9e63a00b319f88343cf9869c8e612843)
Rich Felker [Tue, 16 Sep 2014 20:08:53 +0000 (16:08 -0400)]
fix overflow corner case in strtoul-family functions
incorrect behavior occurred only in cases where the input overflows
unsigned long long, not just the (possibly lower) range limit for the
result type. in this case, processing of the '-' sign character was
not suppressed, and the function returned a value of 1 despite setting
errno to ERANGE.
(cherry picked from commit
e2e1bb81485a37321d928a8d8b63f40b9d8fa228)
Szabolcs Nagy [Fri, 5 Sep 2014 19:12:34 +0000 (15:12 -0400)]
fix memory leak in regexec when input contains illegal sequence
(cherry picked from commit
546f6b322bcafa2452925c19f9607d9689c75f95)
Rich Felker [Fri, 5 Sep 2014 18:01:13 +0000 (14:01 -0400)]
fix off-by-one in bounds check in fpathconf
this error resulted in an out-of-bounds read, as opposed to a reported
error, when calling the function with an argument one greater than the
max valid index.
(cherry picked from commit
3bed89aa7456d9fe30e550cb5e21f8911036695b)
Rich Felker [Fri, 5 Sep 2014 02:21:17 +0000 (22:21 -0400)]
fix multiple stdio functions' behavior on zero-length operations
previously, fgets, fputs, fread, and fwrite completely omitted locking
and access to the FILE object when their arguments yielded a zero
length read or write operation independent of the FILE state. this
optimization was invalid; it wrongly skipped marking the stream as
byte-oriented (a C conformance bug) and exposed observably missing
synchronization (a POSIX conformance bug) where one of these functions
could wrongly complete despite another thread provably holding the
lock.
(cherry picked from commit
6e2bb7acf42589fb7130b039d0623e2ca42503dd)
Rich Felker [Fri, 5 Sep 2014 01:37:13 +0000 (21:37 -0400)]
suppress null termination when fgets reads EOF with no data
the C standard requires that "the contents of the array remain
unchanged" in this case.
this patch also changes the behavior on read errors, but in that case
"the array contents are indeterminate", so the application cannot
inspect them anyway.
(cherry picked from commit
402611c3ba3be5b3b0486835d98e22ac7ced2722)
Szabolcs Nagy [Thu, 4 Sep 2014 16:29:16 +0000 (18:29 +0200)]
fix dn_expand empty name handling and offsets to 0
Empty name was rejected in dn_expand since commit
56b57f37a46dab432247bf29d96fcb11fbd02a6d
which is a regression as reported by Natanael Copa.
Furthermore if an offset pointer in a compressed name
pointed to a terminating 0 byte (instead of a label)
the returned name was not null terminated.
(cherry picked from commit
49d2c8c6bcf8c926e52c7f510033b6adc31355f5)
Rich Felker [Fri, 22 Aug 2014 18:05:10 +0000 (14:05 -0400)]
fix use of uninitialized memory with application-provided thread stacks
the subsequent code in pthread_create and the code which copies TLS
initialization images to the new thread's TLS space assume that the
memory provided to them is zero-initialized, which is true when it's
obtained by pthread_create using mmap. however, when the caller
provides a stack using pthread_attr_setstack, pthread_create cannot
make any assumptions about the contents. simply zero-filling the
relevant memory in this case is the simplest and safest fix.
(cherry picked from commit
a6293285e930dbdb0eff47e29b513ca22537b1a2)
Szabolcs Nagy [Wed, 13 Aug 2014 14:55:56 +0000 (16:55 +0200)]
fix CPU_EQUAL macro in sched.h
(cherry picked from commit
d146d4dc1104aa3472daf81d2581aca65df54d13)
Rich Felker [Fri, 1 Aug 2014 05:30:56 +0000 (01:30 -0400)]
release 1.0.4
Rich Felker [Sat, 26 Jul 2014 08:43:50 +0000 (04:43 -0400)]
add missing yes/no strings to nl_langinfo
these were removed from the standard but still offered as an extension
in langinfo.h, so nl_langinfo should support them.
(cherry picked from commit
0206f596d5156af560e8af10e950d3cb2f29b73d)
Rich Felker [Sat, 26 Jul 2014 06:42:33 +0000 (02:42 -0400)]
fix nl_langinfo table for LC_TIME era-related items
due to a skipped slot and missing null terminator, the last few
strings were off by one or two slots from their item codes.
(cherry picked from commit
a19cd2b64aabee4ae3c80bcf4ba8da26fba560e4)
Rich Felker [Sun, 20 Jul 2014 16:38:26 +0000 (12:38 -0400)]
fix regression that negated some mips syscall error returns
due to what was essentially a copy and paste error, the changes made
in commit
f61be1f875a2758509d6e9e2cf6f1d9603b28b65 caused syscalls
with 5 or 6 arguments (and syscalls with 2, 3, or 4 arguments when
compiled with clang compatibility) to negate the returned error code a
second time, breaking errno reporting.
(cherry picked from commit
1312930f9bdea47006a8a8c8509c0bed5cf69e85)
Rich Felker [Sun, 20 Jul 2014 03:37:21 +0000 (23:37 -0400)]
fix mips struct stat dev_t members for big endian
the mips version of this structure on the kernel side wrongly has
32-bit type rather than 64-bit type. fortunately there is adjacent
padding to bring it up to 64 bits, and on little-endian, this allows
us to treat the adjacent kernel st_dev and st_pad0[0] as as single
64-bit dev_t. however, on big endian, such treatment results in the
upper and lower 32-bit parts of the dev_t value being swapped. for the
purpose of just comparing st_dev values this did not break anything,
but it precluded actually processing the device numbers as major/minor
values.
since the broken kernel behavior that needs to be worked around is
isolated to one arch, I put the workarounds in syscall_arch.h rather
than adding a stat fixup path in the common code. on little endian
mips, the added code optimizes out completely.
the changes necessary were incompatible with the way the __asm_syscall
macro was factored so I just removed it and flattened the individual
__syscallN functions. this arguably makes the code easier to read and
understand, anyway.
(cherry picked from commit
f61be1f875a2758509d6e9e2cf6f1d9603b28b65)
Rich Felker [Sat, 19 Jul 2014 22:34:10 +0000 (18:34 -0400)]
fix missing barriers in powerpc atomic store
(cherry picked from commit
522a0de2101abd12b19a4d2ba5c09abbb7c5fc79)
Rich Felker [Sat, 19 Jul 2014 22:23:24 +0000 (18:23 -0400)]
fix microblaze atomic store
as far as I can tell, microblaze is strongly ordered, but this does
not seem to be well-documented and the assumption may need revisiting.
even with strong ordering, however, a volatile C assignment is not
sufficient to implement atomic store, since it does not preclude
reordering by the compiler with respect to non-volatile stores and
loads.
simply flanking a C store with empty volatile asm blocks with memory
clobbers would achieve the desired result, but is likely to result in
worse code generation, since the address and value for the store may
need to be spilled. actually writing the store in asm, so that there's
only one asm block, should give optimal code generation while
satisfying the requirement for having a compiler barrier.
(cherry picked from commit
884cc0c7e253601b96902120ed689f34d12f8aa0)
Rich Felker [Sat, 19 Jul 2014 19:57:48 +0000 (15:57 -0400)]
fix missing barrier instructions in powerpc atomic asm
(cherry picked from commit
1456b7ae6b72a4f2c446243acdde7c951268d4ab)
Rich Felker [Sat, 19 Jul 2014 19:51:12 +0000 (15:51 -0400)]
fix missing barrier instructions in mips atomic asm
previously I had wrongly assumed the ll/sc instructions also provided
memory synchronization; apparently they do not. this commit adds sync
instructions before and after each atomic operation and changes the
atomic store to simply use sync before and after a plain store, rather
than a useless compare-and-swap.
(cherry picked from commit
bcad48439494820989f5867c3f8ccfa6aae2909f)
Rich Felker [Sat, 19 Jul 2014 17:51:35 +0000 (13:51 -0400)]
use memory constraints for mips atomic asm
despite lacking the semantic content that the asm accesses the
pointed-to object rather than just using its address as a value, the
mips asm was not actually broken. the asm blocks were declared
volatile, meaning that the compiler must treat them as having unknown
side effects.
however changing the asm to use memory constraints is desirable not
just from a semantic correctness and consistency standpoint, but also
produces better code. the compiler is able to use base/offset
addressing expressions for the atomic object's address rather than
having to load the address into a single register. this improves
access to global locks in static libc, and access to non-zero-offset
atomic fields in synchronization primitives, etc.
(cherry picked from commit
a294f539c78c6ba0a2786ef3c5b2a1210a33864e)
Rich Felker [Sat, 19 Jul 2014 17:43:46 +0000 (13:43 -0400)]
fix build breakage from ppc asm constraints change
due to a mistake in my testing procedure, the changes in the previous
commit were not correctly tested and wrongly assumed to be valid. the
lwarx and stwcx. instructions do not accept general ppc memory address
expressions and thus the argument associated with the memory
constraint cannot be used directly.
instead, the memory constraint can be left as an argument that the asm
does not actually use, and the address can be provided in a separate
register constraint.
(cherry picked from commit
bb3a3befeaa01531c273ef9130f3fbcaaf8a25e2)
Rich Felker [Sat, 19 Jul 2014 17:03:30 +0000 (13:03 -0400)]
remove cruft from microblaze atomic.h
(cherry picked from commit
94252dd341a7c72b31db2614abdc74142ad80562)
Rich Felker [Sat, 19 Jul 2014 16:19:20 +0000 (12:19 -0400)]
fix broken constraints for powerpc atomic cas asm
the register constraint for the address to be accessed did not convey
that the asm can access the pointed-to object. as far as the compiler
could tell, the result of the asm was just a pure function of the
address and the values passed in, and thus the asm could be hoisted
out of loops or omitted entirely if the result was not used.
(cherry picked from commit
7fdae458bd421046a300a69dcb32953ac9450136)
Rich Felker [Fri, 18 Jul 2014 18:55:30 +0000 (14:55 -0400)]
fix microblaze definition of struct stat
the erroneous definition was missed because with works with qemu
user-level emulation, which also has the wrong definition. the actual
kernel uses the asm-generic generic definition.
(cherry picked from commit
d69ab5b3686acf75fdf5db6fad19c2c6a510bb4f)
Rich Felker [Thu, 17 Jul 2014 23:56:27 +0000 (19:56 -0400)]
fix crash in regexec for nonzero nmatch argument with REG_NOSUB
per POSIX, the nmatch and pmatch arguments are ignored when the regex
was compiled with REG_NOSUB.
(cherry picked from commit
72ed3d47e567b1635a35d3c1d174c8a8b2787e30)
Rich Felker [Thu, 17 Jul 2014 01:32:06 +0000 (21:32 -0400)]
work around constant folding bug 61144 in gcc 4.9.0 and 4.9.1
previously we detected this bug in configure and issued advice for a
workaround, but this turned out not to work. since then gcc 4.9.0 has
appeared in several distributions, and now 4.9.1 has been released
without a fix despite this being a wrong code generation bug which is
supposed to be a release-blocker, per gcc policy.
since the scope of the bug seems to affect only data objects (rather
than functions) whose definitions are overridable, and there are only
a very small number of these in musl, I am just changing them from
const to volatile for the time being. simply removing the const would
be sufficient to make gcc 4.9.1 work (the non-const case was
inadvertently fixed as part of another change in gcc), and this would
also be sufficient with 4.9.0 if we forced -O0 on the affected files
or on the whole build. however it's cleaner to just remove all the
broken compiler detection and use volatile, which will ensure that
they are never constant-folded. the quality of a non-broken compiler's
output should not be affected except for the fact that these objects
are no longer const and thus possibly add a few bytes to data/bss.
this change can be reconsidered and possibly reverted at some point in
the future when the broken gcc versions are no longer relevant.
(cherry picked from commit
a6adb2bcd8145353943377d6119c1d7a4242bae1)
Rich Felker [Thu, 17 Jul 2014 00:44:22 +0000 (20:44 -0400)]
simplify __stdio_exit static linking logic
the purpose of this logic is to avoid linking __stdio_exit unless any
stdio reads (which might require repositioning the file offset at exit
time) or writes (which might require flushing at exit time) could have
been performed.
previously, exit called two wrapper functions for __stdio_exit named
__flush_on_exit and __seek_on_exit. both of these functions actually
performed both tasks (seek and flushing) by calling the underlying
__stdio_exit. in order to avoid doing this twice, an overridable data
object __towrite_used was used to cause __seek_on_exit to act as a nop
when __towrite was linked.
now, exit only makes one call, directly to __stdio_exit. this is
satisfiable by a weak dummy definition in exit.c, but the real
definition is pulled in by either __toread.c or __towrite.c through
their referencing a symbol which is defined only in __stdio_exit.c.
(cherry picked from commit
c463e11eda8326aacee2ac1d516954a9574a2dcd)
Clément Vasseur [Wed, 9 Jul 2014 12:34:18 +0000 (14:34 +0200)]
fix the %m specifier in syslog
errno must be saved upon vsyslog entry, otherwise its value could be
changed by some libc function before reaching the %m handler in
vsnprintf.
(cherry picked from commit
da27118157c2942d7652138b8d8b0056fc8f872f)
Rich Felker [Fri, 11 Jul 2014 04:26:12 +0000 (00:26 -0400)]
make dynamic linker accept colon as a separator for LD_PRELOAD
(cherry picked from commit
349381aa8c0fc385e54e1068dd5f2b27af55cd12)
Rich Felker [Tue, 8 Jul 2014 23:40:44 +0000 (19:40 -0400)]
fix typo in microblaze setjmp asm
r24 was wrongly being saved at a misaligned offset of 30 rather than
the correct offset of 40 in the jmp_buf. the exact effects of this
error have not been studied, but it's clear that the value of r24 was
lost across setjmp/longjmp and the saved values of r21 and/or r22 may
also have been corrupted.
(cherry picked from commit
729673689c3e78803ddfdac2ca6be5a5b80e124a)
Rich Felker [Sun, 6 Jul 2014 05:34:13 +0000 (01:34 -0400)]
fix multiple issues in legacy function getpass
1. failure to output a newline after the password is read
2. fd leaks via missing FD_CLOEXEC
3. fd leaks via failure-to-close when any of the standard streams are
closed at the time of the call
4. wrongful fallback to use of stdin when opening /dev/tty fails
5. wrongful use of stderr rather than /dev/tty for prompt
6. failure to report error reading password
(cherry picked from commit
ea496d6c63ecbb5ea475111808e5c0f799354450)
Rich Felker [Wed, 2 Jul 2014 16:09:48 +0000 (12:09 -0400)]
fix failure of wide printf/scanf functions to set wide orientation
in some cases, these functions internally call a byte-based input or
output function before calling getwc/putwc, so they cannot rely on the
latter to set the orientation.
(cherry picked from commit
984c25b74da085c6ae6b44a87bbd5f8afc9be331)
Rich Felker [Tue, 1 Jul 2014 22:49:54 +0000 (18:49 -0400)]
fix incorrect return value for fwide function
when the orientation of the stream was already set, fwide was
incorrectly returning its argument (the requested orientation) rather
than the actual orientation of the stream.
(cherry picked from commit
ebd8142a6ae19db1a5440d11c01afc7529eae0cd)
Rich Felker [Tue, 1 Jul 2014 22:27:19 +0000 (18:27 -0400)]
fix aliasing violations in mbtowc and mbrtowc
these functions were setting wc to point to wchar_t aliasing itself as
a "cheap" way to support null wc arguments. doing so was anything but
cheap, since even without the aliasing violation, it would limit the
compiler's ability to optimize.
making wc point to a dummy object is equally easy and does not suffer
from the above problems.
(cherry picked from commit
e89cfe51d2001af08fc2a13e5133ba8157f90beb)
Rich Felker [Sat, 21 Jun 2014 11:44:46 +0000 (07:44 -0400)]
remove hack in syslog.h that resulted in aliasing violations
this issue affected the prioritynames and facilitynames arrays which
are only provided when requested (usually by syslogd implementations)
and which are presently defined as compound literals. the aliasing
violation seems to have been introduced as a workaround for bad
behavior by gcc's -Wwrite-strings option, but it caused compilers to
completely optimize out the contents of prioritynames and
facilitynames since, under many usage cases, the aliasing rules prove
that the contents are never accessed.
(cherry picked from commit
70d9c303b3115ab0fe6060ba0f7b0e4c0a2320b7)
Rich Felker [Thu, 19 Jun 2014 04:42:28 +0000 (00:42 -0400)]
fix incorrect comparison loop condition in memmem
the logic for this loop was copied from null-terminated-string logic
in strstr without properly adapting it to work with explicit lengths.
presumably this error could result in false negatives (wrongly
comparing past the end of the needle/haystack), false positives
(stopping comparison early when the needle contains null bytes), and
crashes (from runaway reads past the end of mapped memory).
(cherry picked from commit
cef0f289f666b6c963bfd11537a6d80916ff889e)
Rich Felker [Tue, 17 Jun 2014 18:32:43 +0000 (14:32 -0400)]
fix powerpc dynamic linker thread-pointer-relative relocations
processing of R_PPC_TPREL32 was ignoring the addend provided by the
RELA-style relocation and instead using the inline value as the
addend. this presumably broke dynamic-linked access to initial TLS in
cases where the addend was nonzero.
(cherry picked from commit
94cf991bf4b18bb87a15a96e7b5e7d92fab787ba)
Clément Vasseur [Fri, 13 Jun 2014 16:27:56 +0000 (18:27 +0200)]
fix missing argument to syscall in fanotify_mark
(cherry picked from commit
4e5c7a2176773c9a1564c6603240337b3ad6b496)
Rich Felker [Mon, 28 Jul 2014 04:25:24 +0000 (00:25 -0400)]
prepare pthread_create.c for cherry-picking from master
this change is harmless and allows commit
a6adb2bcd8145353943377d6119c1d7a4242bae1 to apply without conflicts.
Rich Felker [Mon, 28 Jul 2014 04:07:37 +0000 (00:07 -0400)]
fix gethostby*_r result pointer value on error
according to the documentation in the man pages, the GNU extension
functions gethostbyaddr_r, gethostbyname_r and gethostbyname2_r are
guaranteed to set the result pointer to NULL in case of error or no
result.
corresponds to commit
fe82bb9b921be34370e6b71a1c6f062c20999ae0 in
master branch.
Rich Felker [Fri, 6 Jun 2014 22:45:24 +0000 (18:45 -0400)]
release 1.0.3
Szabolcs Nagy [Thu, 5 Jun 2014 20:32:42 +0000 (22:32 +0200)]
fix multiple validation issues in dns response label parsing
Due to an error introduced in commit
fcc522c92335783293ac19df318415cd97fbf66b,
checking of the remaining output buffer space was not performed correctly,
allowing malformed input to write past the end of the buffer.
In addition, the loop detection logic failed to account for the possibility
of infinite loops with no output, which would hang the function.
The output size is now limited more strictly so only names with valid length
are accepted.
(cherry picked from commit
b3d9e0b94ea73c68ef4169ec82c898ce59a4e30a)
Rich Felker [Wed, 4 Jun 2014 08:39:34 +0000 (04:39 -0400)]
remove some dummy "ent" function aliases that duplicated real ones
the service and protocol functions are defined also in other files,
and the protocol ones are actually non-nops elsewhere, so the weak
definitions in ent.c could have prevented the strong definitions from
getting pulled in and used in some static programs.
(cherry picked from commit
934aa1350b96461f205ad69c95e8f6f035f6b62c)
Rich Felker [Tue, 3 Jun 2014 21:53:11 +0000 (17:53 -0400)]
fix if_nametoindex return value when interface does not exist
the return value is unsigned, so negative results for "errors" do not
make sense; 0 is the value reserved for when the interface name does
not exist.
(cherry picked from commit
8041af59881219c32267c3491bee43591d3c3fe6)
Rich Felker [Mon, 2 Jun 2014 20:21:47 +0000 (16:21 -0400)]
fix incorrect end pointer in some cases when wcsrtombs stops early
when wcsrtombs stopped due to hitting zero remaining space in the
output buffer, it was wrongly clearing the position pointer as if it
had completed the conversion successfully.
this commit rearranges the code somewhat to make a clear separation
between the cases of ending due to running out of output buffer space,
and ending due to reaching the end of input or an illegal sequence in
the input. the new branches have been arranged with the hope of
optimizing more common cases, too.
(cherry picked from commit
8fba4458afb7304b32ca887e4a3990c6029131f9)
Szabolcs Nagy [Fri, 30 May 2014 06:47:35 +0000 (08:47 +0200)]
fix for broken kernel side RLIM_INFINITY on mips
On 32 bit mips the kernel uses -1UL/2 to mark RLIM_INFINITY (and
this is the definition in the userspace api), but since it is in
the middle of the valid range of limits and limits are often
compared with relational operators, various kernel side logic is
broken if larger than -1UL/2 limits are used. So we truncate the
limits to -1UL/2 in get/setrlimit and prlimit.
Even if the kernel side logic consistently treated -1UL/2 as greater
than any other limit value, there wouldn't be any clean workaround
that allowed using large limits:
* using -1UL/2 as RLIM_INFINITY in userspace would mean different
infinity value for get/setrlimt and prlimit (where infinity is always
-1ULL) and userspace logic could break easily (just like the kernel
is broken now) and more special case code would be needed for mips.
* translating -1UL/2 kernel side value to -1ULL in userspace would
mean that -1UL/2 limit cannot be set (eg. -1UL/2+1 had to be passed
to the kernel instead).
(cherry picked from commit
8258014fd1e34e942a549c88c7e022a00445c352)
Rich Felker [Fri, 6 Jun 2014 21:56:36 +0000 (17:56 -0400)]
fix sendfile syscall to use 64-bit off_t
somehow the remapping of this syscall to the 64-bit version was
overlooked. the issue was found, and patch provided, by Stefan
Kristiansson. presumably the reason this bug was not caught earlier is
that the syscall takes a pointer to off_t rather than a value, so on
little-endian systems, everything appears to work as long as the
offset value fits in the low 31 bits. on big-endian systems, though,
sendfile was presumably completely non-functional.
corresponds to commit
55f45bc7222ec50b72aa8411c61e30184d0ade23 in
master branch.
Rich Felker [Tue, 20 May 2014 21:58:42 +0000 (17:58 -0400)]
release 1.0.2
Rich Felker [Tue, 20 May 2014 19:49:21 +0000 (15:49 -0400)]
trivial formatting fix for the config.mak generated by configure
(cherry picked from commit
7c6db373a55a348b3ecc7b124dd4ea541eff63cd)
Rich Felker [Tue, 20 May 2014 02:14:09 +0000 (22:14 -0400)]
fix unhandled cases in strptime
%C, %U, %W, and %y handling were completely missing; %C wrongly
fell-through to unrelated cases, and the rest returned failure. for
now, they all parse numbers in the proper forms and range-check the
values, but they do not store the value anywhere.
it's not clear to me whether, as "derived" fields, %U and %W should
produce any result. they certainly cannot produce a result unless the
year and weekday are also converted, but in this case it might be
desirable for them to do so. clarification is needed on the intended
behavior of strptime in cases like this.
%C and %y have well-defined behavior as long as they are used together
(and %y is defined by itself but may change in the future).
implementing them (including their correct interaction) is left as a
later change to be made.
finally, strptime now rejects unknown/invalid format characters
instead of ignoring them.
(cherry picked from commit
dec66750b8ed4493d5bb40042f7a473e60fe934e)
Rich Felker [Mon, 19 May 2014 14:33:28 +0000 (10:33 -0400)]
add configure check for broken gcc 4.9.0 and possibly other versions
this is gcc bug #61144. the broken compiler is detected, but the user
must manually work around it. this is partly to avoid complex logic
for adding workaround CFLAGS and attempting to recheck with them, and
partly for the sake of letting the user know the compiler is broken
(since the workaround will result in less-efficient code production).
some refactoring was also needed to move the check for gcc outside of
the check for whether to build the compiler wrapper.
(cherry picked from commit
9ca4dae5d895cf816eb1815511aba77a90f6acd7)
Rich Felker [Mon, 12 May 2014 18:22:57 +0000 (14:22 -0400)]
add configure check for working compiler
without this, broken choices of CC/CPPFLAGS/CFLAGS don't show up until
late in the configure process where they are confusingly reported as a
different failure such as incorrect long double type.
(cherry picked from commit
8945667fadc2eb71b7924bb4c5a69507fd362f4a)
Szabolcs Nagy [Thu, 8 May 2014 17:04:48 +0000 (19:04 +0200)]
fix strftime %s not to zero pad with default width=2
(cherry picked from commit
ac0acd569e01735fc6052d43fdf57f3a07c93f3d)
Rich Felker [Sun, 4 May 2014 17:15:27 +0000 (13:15 -0400)]
remove useless __yield alias for sched_yield
this is no longer used for anything, and reportedly clashed with a
builtin on certain compilers.
(cherry picked from commit
adbf0258be4eea5f012e173de7e55a87f3093669)
Rich Felker [Wed, 30 Apr 2014 18:47:06 +0000 (14:47 -0400)]
fix missing SO_RCVBUFFORCE and SO_SNDBUFFORCE in mips socket.h
(cherry picked from commit
468bc11ed059c475f974920ac3d499e6071a6b2c)
Bobby Bingham [Mon, 28 Apr 2014 02:13:59 +0000 (21:13 -0500)]
fix superh nofpu check on old gcc versions
As far as gcc3 knows, sh4 is the only processor version that can have an
FPU, so it indicates the FPU's presence by defining __SH4__. This is not
defined if there is no FPU, even if the processor really is an SH4.
Starting with gcc4, there is support for the sh2a processor, which has an
FPU but is not an SH4. gcc4 therefore additionally defines __SH_FPU_ANY__
when there is an FPU, but still doesn't define __SH4__ for an FPU-less sh4.
Therefore, to support all gcc versions, we must look at both preprocessor
symbols.
(cherry picked from commit
23d64182d8328c300b368446aad20da9cec91aa3)
Rich Felker [Wed, 23 Apr 2014 00:09:56 +0000 (20:09 -0400)]
perform minimal sanity checks on zoneinfo files loaded via TZ variable
previously, setting TZ to the pathname of a file which was not a valid
zoneinfo file would usually cause programs using local time zone based
operations to crash. the new code checks the file size and magic at
the beginning of the file, which seems sufficient to prevent
accidental misconfiguration from causing crashes. attempting to make
fully-robust validation would be futile unless we wanted to drop use
of mmap (shared zoneinfo) and instead read it into a local buffer,
since such validation would be subject to race conditions with
modification of the file.
(cherry picked from commit
c3d9d172b1fcd56c4d356798f4e3b4653076bcc3)
Rich Felker [Fri, 18 Apr 2014 21:38:35 +0000 (17:38 -0400)]
fix false negatives with periodic needles in strstr, wcsstr, and memmem
in cases where the memorized match range from the right factor
exceeded the length of the left factor, it was wrongly treated as a
mismatch rather than a match.
issue reported by Yves Bastide.
(cherry picked from commit
476cd1d96560aaf7f210319597556e7fbcd60469)
Rich Felker [Wed, 16 Apr 2014 08:23:31 +0000 (04:23 -0400)]
release 1.0.1
Rich Felker [Wed, 16 Apr 2014 00:42:39 +0000 (20:42 -0400)]
fix deadlock race in pthread_once
at the end of successful pthread_once, there was a race window during
which another thread calling pthread_once would momentarily change the
state back from 2 (finished) to 1 (in-progress). in this case, the
status was immediately changed back, but with no wake call, meaning
that waiters which arrived during this short window could block
forever. there are two possible fixes. one would be adding the wake to
the code path where it was missing. but it's better just to avoid
reverting the status at all, by using compare-and-swap instead of
swap.
(cherry picked from commit
0d0c2f40344640a2a6942dda156509593f51db5d)
Szabolcs Nagy [Mon, 14 Apr 2014 15:42:49 +0000 (17:42 +0200)]
fix RLIMIT_ constants for mips
The mips arch is special in that it uses different RLIMIT_
numbers than other archs, so allow bits/resource.h to override
the default RLIMIT_ numbers (empty on all archs except mips).
Reported by orc.
(cherry picked from commit
fcea534e579077e10456f6ed06c033dfaa013a24)
Rich Felker [Tue, 15 Apr 2014 03:48:40 +0000 (23:48 -0400)]
fix fallback code for old kernels in clock_gettime
(cherry picked from commit
805698401dbac7ce3079fa97eaad5ba0508377f4)
Rich Felker [Sat, 12 Apr 2014 04:16:19 +0000 (00:16 -0400)]
use hidden visibility rather than protected for syscall internals
the use of visibility at all is purely an optimization to avoid the
need for the caller to load the GOT register or similar to prepare for
a call via the PLT. there is no reason for these symbols to be
externally visible, so hidden works just as well as protected, and
using protected visibility is undesirable due to toolchain bugs and
the lack of testing it receives.
in particular, GCC's microblaze target is known to generate symbolic
relocations in the GOT for functions with protected visibility. this
in turn results in a dynamic linker which crashes under any nontrivial
usage that requires making a syscall before symbolic relocations are
processed.
(cherry picked from commit
83c98aac4c43f9571e8f92a1c795afe02c237d4b)
Szabolcs Nagy [Fri, 11 Apr 2014 15:57:30 +0000 (17:57 +0200)]
math: fix aliasing violation in long double wrappers
modfl and sincosl were passing long double* instead of double*
to the wrapped double precision functions (on archs where long
double and double have the same size).
This is fixed now by using temporaries (this is not optimized
to a single branch so the generated code is a bit bigger).
Found by Morten Welinder.
(cherry picked from commit
73c870ed3209b68b5c8c350534508cc9d95a6bcb)
Timo Teräs [Thu, 10 Apr 2014 01:06:17 +0000 (21:06 -0400)]
fix search past the end of haystack in memmem
to optimize the search, memchr is used to find the first occurrence of
the first character of the needle in the haystack before switching to
a search for the full needle. however, the number of characters
skipped by this first step were not subtracted from the haystack
length, causing memmem to search past the end of the haystack.
(cherry picked from commit
6fbdeff0e51f6afc38fbb1476a4db81322779da4)
Rich Felker [Mon, 7 Apr 2014 17:50:05 +0000 (13:50 -0400)]
fix printf rounding with %g for some corner case midpoints
the subsequent rounding code assumes the end pointer (z) accurately
reflects the end of significance in the decimal expansion, but for
certain large integers, spurious trailing zero slots were left behind
when applying the binary exponent.
issue reported by Morten Welinder; the analysis of the cause was
performed by nsz, who also proposed this change.
(cherry picked from commit
e94d0692864ecf9522fd6a97610a47a2f718d3de)
Rich Felker [Mon, 7 Apr 2014 06:05:20 +0000 (02:05 -0400)]
fix failure of printf %g to strip trailing zeros in some cases
the code to strip trailing zeros was only looking in the last slot for
up to 9 zeros, assuming that the rounding code had already removed
fully-zero slots from the end. however, this ignored cases where the
rounding code did not run at all, which occur when the value being
printed is exactly representable in the requested precision.
the simplest solution is to move the code that strips trailing zero
slots to run unconditionally, immediately after rounding, rather than
as the last step of rounding.
(cherry picked from commit
89740868c9f1c84b8ee528468d12df1fa72cd392)
Rich Felker [Mon, 7 Apr 2014 05:36:40 +0000 (01:36 -0400)]
fix carry into uninitialized slots during printf floating point rounding
in cases where rounding caused a carry, the slot into which the carry
was taking place was unconditionally treated as valid, despite the
possibility that it could be a new slot prior to the beginning of the
existing non-rounded number. in theory this could lead to unbounded
runaway carry, but in order for that to happen, the whole
uninitialized buffer would need to have been pre-filled with 32-bit
integer values greater than or equal to
999999999.
patch based on proposed fix by Morten Welinder, who also discovered
and reported the bug.
(cherry picked from commit
109048e031f39fbb370211fde44ababf6c04c8fb)
Rich Felker [Wed, 2 Apr 2014 18:13:20 +0000 (14:13 -0400)]
fix microblaze syscall register clobbers
the kernel entry point for syscalls on microblaze nominally saves and
restores all registers, and testing on qemu always worked since qemu
behaves this way too. however, the real kernel treats r3:r4 as a
potential 64-bit return value from the syscall function, and copies
both over top of the saved registers before returning to userspace.
thus, we need to treat r4 as always-clobbered.
(cherry picked from commit
91d5aa06572d2660122f9a06ed242fef0383f292)
Timo Teräs [Wed, 19 Feb 2014 07:40:35 +0000 (09:40 +0200)]
fix confstr return value
per the specification, the terminating null byte is counted.
(cherry picked from commit
0a8d98285f46f721dabf38485df916c02d6a4675)
Rich Felker [Mon, 24 Mar 2014 00:42:05 +0000 (20:42 -0400)]
include header that declares __syscall_ret where it's defined
in general, we aim to always include the header that's declaring a
function before defining it so that the compiler can check that
prototypes match.
additionally, the internal syscall.h declares __syscall_ret with a
visibility attribute to improve code generation for shared libc (to
prevent gratuitous GOT-register loads). this declaration should be
visible at the point where __syscall_ret is defined, too, or the
inconsistency could theoretically lead to problems at link-time.
(cherry picked from commit
30c1205acd73c8481ca34f0a41de1d41884d07b5)
Rich Felker [Thu, 20 Mar 2014 08:41:15 +0000 (04:41 -0400)]
release 1.0.0
Rich Felker [Thu, 20 Mar 2014 08:15:47 +0000 (04:15 -0400)]
remove claim of XSI coverage from README
in addition to the dbm functions (which we don't intent to implement
anyway), fmtmsg is still missing too. rather than adding exceptions I
think it's best just to avoid making the claim.
Rich Felker [Thu, 20 Mar 2014 06:24:10 +0000 (02:24 -0400)]
update README in preparation for release
reduces the amount of news-like content on progress and development
direction and focuses on the present.