Commit Graph

2521 Commits

Author SHA1 Message Date
Rich Felker
56be2e4c01 release 1.0.5 2015-03-30 18:40:39 -04:00
Szabolcs Nagy
39e65294a4 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 c498efe117)
2015-03-30 02:19:58 -04:00
Rich Felker
f0a5b139ef 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 fc13acc3dc)
2015-03-30 02:18:42 -04:00
Rich Felker
ee6f8114df 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 39dfd58417 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.
2015-03-30 02:13:59 -04:00
Rich Felker
7987653d57 fix signed left-shift overflow in pthread_condattr_setpshared
(cherry picked from commit 380857bf21)
2015-03-30 02:00:47 -04:00
Rich Felker
e060baa0c3 fix preprocessor error introduced in poll.h in last commit
(cherry picked from commit 91a3bd743e)
2015-03-30 02:00:47 -04:00
Trutz Behn
14b14fa765 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 f5011c62c3)
2015-03-30 01:57:32 -04:00
Rich Felker
99c10bf85f 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 0d0c2f4034.

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 7a81fe3710)
2015-03-30 01:55:19 -04:00
Rich Felker
fdc39fac10 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 5446303328)
2015-03-30 01:54:08 -04:00
Rich Felker
e2063ac08b 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 594ffed82f)
2015-03-30 01:45:20 -04:00
Szabolcs Nagy
f035f7d971 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 5fc1487832)
2015-03-30 01:45:20 -04:00
Rich Felker
d670873b7e 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 61b1d10212)

(conflicts from commit dd5f50da6f)
2015-03-30 01:43:48 -04:00
Rich Felker
c534aad07d fix fd leak race (missing O_CLOEXEC) in fchmodat
(cherry picked from commit 2736eb6caa)
2015-03-30 01:41:34 -04:00
Felix Janda
35c1939960 fix typo in x86_64/x32 user_fpregs_struct
mxcs_mask should be mxcr_mask

(cherry picked from commit 4758f0565d)
2015-03-30 01:41:34 -04:00
Rich Felker
2604958894 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 ecb608192a)
2015-03-30 01:41:34 -04:00
Rich Felker
5087ba67af 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 c574321d75)
2015-03-30 01:41:33 -04:00
Rich Felker
2c61720d97 fix signedness of WINT_MIN expression
since wint_t is unsigned, WINT_MIN needs to expand to an unsigned zero.

(cherry picked from commit aee9b15262)
2015-03-30 01:41:33 -04:00
Rich Felker
0d418ce688 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 d42269d7c8)
2015-03-30 01:41:33 -04:00
Rich Felker
051a8fdda8 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 66140b0c92)
2015-03-30 01:41:33 -04:00
Rich Felker
65a0ee3a52 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 a56e339419)
2015-03-30 01:41:33 -04:00
Rich Felker
5c34041293 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 d8dc2b7c02)
2015-03-30 01:41:33 -04:00
Rich Felker
395e409cc0 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 b91cdbe2bc)
2015-03-30 01:41:32 -04:00
Szabolcs Nagy
8c245bf272 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 a732e80d33)
2015-03-30 01:41:32 -04:00
Rich Felker
e48fff8d33 fix uninitialized mode variable in openat function
this was introduced in commit 2da3ab1382
as an oversight while making the variadic argument access conditional.

(cherry picked from commit e146e6035f)
2015-03-30 01:41:32 -04:00
Rich Felker
4ab6544a41 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 2da3ab1382)
2015-03-30 01:41:32 -04:00
Rich Felker
e3fa4300bf 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 df37d3960a)

(edited not to depend on a_barrier, which is not available in 1.0.x)
2015-03-30 01:34:13 -04:00
Rich Felker
02ccece698 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 08b996d180)
2015-03-30 01:15:45 -04:00
Rich Felker
9882dc933d 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 dccbf4c809)
2015-03-30 01:15:45 -04:00
Rich Felker
9f93f6d119 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 05cef96d9e)
2015-03-30 01:15:44 -04:00
Rich Felker
0a7aca63c0 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 e2e1bb8148)
2015-03-30 01:15:44 -04:00
Szabolcs Nagy
1d19a53b8c fix memory leak in regexec when input contains illegal sequence
(cherry picked from commit 546f6b322b)
2015-03-30 01:15:44 -04:00
Rich Felker
5a8c6f0932 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 3bed89aa74)
2015-03-30 01:15:44 -04:00
Rich Felker
f071365e66 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 6e2bb7acf4)
2015-03-30 01:15:44 -04:00
Rich Felker
6d14779eab 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 402611c3ba)
2015-03-30 01:15:44 -04:00
Szabolcs Nagy
83eb88d6c2 fix dn_expand empty name handling and offsets to 0
Empty name was rejected in dn_expand since commit
56b57f37a4
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 49d2c8c6bc)
2015-03-30 01:15:43 -04:00
Rich Felker
53f270f964 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 a6293285e9)
2015-03-30 01:15:43 -04:00
Szabolcs Nagy
6f5544ac2e fix CPU_EQUAL macro in sched.h
(cherry picked from commit d146d4dc11)
2015-03-30 01:15:43 -04:00
Rich Felker
8f514e76f6 release 1.0.4 2014-08-01 01:30:56 -04:00
Rich Felker
af7a02a191 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 0206f596d5)
2014-07-28 00:28:01 -04:00
Rich Felker
7de071453d 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 a19cd2b64a)
2014-07-28 00:28:01 -04:00
Rich Felker
90c9b5fc60 fix regression that negated some mips syscall error returns
due to what was essentially a copy and paste error, the changes made
in commit f61be1f875 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 1312930f9b)
2014-07-28 00:28:01 -04:00
Rich Felker
a83f0e7a6b 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 f61be1f875)
2014-07-28 00:28:01 -04:00
Rich Felker
1b61e4cab9 fix missing barriers in powerpc atomic store
(cherry picked from commit 522a0de210)
2014-07-28 00:28:01 -04:00
Rich Felker
809f1d3e82 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 884cc0c7e2)
2014-07-28 00:28:01 -04:00
Rich Felker
3c548e6eda fix missing barrier instructions in powerpc atomic asm
(cherry picked from commit 1456b7ae6b)
2014-07-28 00:28:00 -04:00
Rich Felker
e30a16314d 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 bcad484394)
2014-07-28 00:28:00 -04:00
Rich Felker
806655b225 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 a294f539c7)
2014-07-28 00:28:00 -04:00
Rich Felker
9e8f22fb3e 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 bb3a3befea)
2014-07-28 00:28:00 -04:00
Rich Felker
f5b1c23d6c remove cruft from microblaze atomic.h
(cherry picked from commit 94252dd341)
2014-07-28 00:28:00 -04:00
Rich Felker
b1d89d48aa 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 7fdae458bd)
2014-07-28 00:28:00 -04:00