musl
10 years agoadd infrastructure to record and report the version of libc.so
Rich Felker [Sun, 1 Dec 2013 22:27:25 +0000 (17:27 -0500)]
add infrastructure to record and report the version of libc.so

this is still experimental and subject to change. for git checkouts,
an attempt is made to record the exact revision to aid in bug reports
and debugging. no version information is recorded in the static libc.a
or binaries it's linked into.

10 years agofix fnmatch corner cases related to escaping
Rich Felker [Sun, 1 Dec 2013 19:36:22 +0000 (14:36 -0500)]
fix fnmatch corner cases related to escaping

the FNM_PATHNAME logic for advancing by /-delimited components was
incorrect when the / character was escaped (i.e. \/), and a final \ at
the end of pattern was not handled correctly.

10 years agofix the end of string matching in fnmatch with FNM_PATHNAME
Szabolcs Nagy [Sun, 1 Dec 2013 17:32:48 +0000 (17:32 +0000)]
fix the end of string matching in fnmatch with FNM_PATHNAME

a '/' in the pattern could be incorrectly matched against the
terminating null byte in the string causing arbitrarily long
sequence of out-of-bounds access in fnmatch("/","",FNM_PATHNAME)

10 years agosupport mix of IPv4 and v6 nameservers in resolv.conf
Rich Felker [Sat, 30 Nov 2013 18:33:29 +0000 (13:33 -0500)]
support mix of IPv4 and v6 nameservers in resolv.conf

a v6 socket will only be used if there is at least one v6 nameserver
address. if the kernel lacks v6 support, the code will fall back to
using a v4 socket and requests to v6 servers will silently fail. when
using a v6 socket, v4 addresses are converted to v4-mapped form and
setsockopt is used to ensure that the v6 socket can accept both v4 and
v6 traffic (this is on-by-default on Linux but the default is
configurable in /proc and so it needs to be set explicitly on the
socket level). this scheme avoids increasing resource usage during
lookups and allows the existing network io loop to be used without
modification.

previously, nameservers whose address family did not match the address
family of the first-listed nameserver were simply ignored. prior to
recent __ipparse fixes, they were not ignored but erroneously parsed.

10 years agoincrease TTY_NAME_MAX limit to 32
Rich Felker [Fri, 29 Nov 2013 17:45:09 +0000 (12:45 -0500)]
increase TTY_NAME_MAX limit to 32

the old value of 20 was reported by Laurent Bercot as being
insufficient for a reasonable real-world usage case. actual problem
was the internal buffer used by ttyname(), but the implementation of
ttyname uses TTY_NAME_MAX, and for consistency it's best to increase
both. the new value is aligned with glibc.

10 years agoreject invalid address families in getaddrinfo
Rich Felker [Wed, 27 Nov 2013 05:54:03 +0000 (00:54 -0500)]
reject invalid address families in getaddrinfo

subsequent code assumes the address family requested is either
unspecified or one of IPv4/IPv6, and could malfunction if this
constraint is not met, so other address families should be explicitly
rejected.

10 years agoadjust fallback INFINITY definition for FLT_EVAL_METHOD==2 case
Rich Felker [Wed, 27 Nov 2013 04:26:37 +0000 (23:26 -0500)]
adjust fallback INFINITY definition for FLT_EVAL_METHOD==2 case

on archs with excess precision, the floating point constant 1e40f may
be evaluated such that it does not actually produce an infinity.
1e5000f is sufficiently large to produce an infinity for all supported
floating point formats. note that this definition of INFINITY is only
used for old or non-GNUC compilers anyway; despite being a portable,
conforming definition, it leads to erroneous warnings on many
compilers and thus using the builtin is preferred.

10 years agofix off-by-one length failure in strftime/wcsftime and improve error behavior
Rich Felker [Wed, 27 Nov 2013 01:01:21 +0000 (20:01 -0500)]
fix off-by-one length failure in strftime/wcsftime and improve error behavior

these functions were spuriously failing in the case where the buffer
size was exactly the number of bytes/characters to be written,
including null termination. since these functions do not have defined
error conditions other than buffer size, a reasonable application may
fail to check the return value when the format string and buffer size
are known to be valid; such an application could then attempt to use a
non-terminated buffer.

in addition to fixing the bug, I have changed the error handling
behavior so that these functions always null-terminate the output
except in the case where the buffer size is zero, and so that they
always write as many characters as possible before failing, rather
than dropping whole fields that do not fit. this actually simplifies
the logic somewhat anyway.

10 years agoremove duplicate includes from dynlink.c, strfmon.c and getaddrinfo.c
Szabolcs Nagy [Mon, 25 Nov 2013 23:34:10 +0000 (23:34 +0000)]
remove duplicate includes from dynlink.c, strfmon.c and getaddrinfo.c

10 years agorestore type of NULL to void * except when used in C++ programs
Rich Felker [Mon, 25 Nov 2013 02:42:55 +0000 (21:42 -0500)]
restore type of NULL to void * except when used in C++ programs

unfortunately this eliminates the ability of the compiler to diagnose
some dangerous/incorrect usage, but POSIX requires (as an extension to
the C language, i.e. CX shaded) that NULL have type void *. plain C
allows it to be defined as any null pointer constant.

the definition 0L is preserved for C++ rather than reverting to plain
0 to avoid dangerous behavior in non-conforming programs which use
NULL as a variadic sentinel. (it's impossible to use (void *)0 for C++
since C++ lacks the proper implicit pointer conversions, and other
popular alternatives like the GCC __null extension seem non-conforming
to the standard's requirements.)

10 years agoshadow: Implement fgetspent
Michael Forney [Thu, 21 Nov 2013 03:13:41 +0000 (19:13 -0800)]
shadow: Implement fgetspent

10 years agoshadow: Move spent parsing to internal function
Michael Forney [Sun, 24 Nov 2013 06:17:42 +0000 (22:17 -0800)]
shadow: Move spent parsing to internal function

10 years agoFix dn_comp prototype and add stub
Michael Forney [Sun, 24 Nov 2013 06:33:05 +0000 (22:33 -0800)]
Fix dn_comp prototype and add stub

This function is used by ping6 from iputils.

10 years agoshadow: Implement putspent
Michael Forney [Sun, 24 Nov 2013 06:10:10 +0000 (22:10 -0800)]
shadow: Implement putspent

10 years agomath: clean up __rem_pio2
Szabolcs Nagy [Sun, 24 Nov 2013 01:06:38 +0000 (01:06 +0000)]
math: clean up __rem_pio2

- remove the HAVE_EFFICIENT_IRINT case: fn is an exact integer, so
  it can be converted to int32_t a bit more efficiently than with a
  cast (the rounding mode change can be avoided), but musl does not
  support this case on any arch.
- __rem_pio2: use double_t where possible
- __rem_pio2f: use less assignments to avoid stores on i386
- use unsigned int bit manipulation (and union instead of macros)
- use hexfloat literals instead of named constants

10 years agouse 0 instead of NULL in headers where NULL is not defined
Szabolcs Nagy [Sun, 24 Nov 2013 00:34:07 +0000 (00:34 +0000)]
use 0 instead of NULL in headers where NULL is not defined

some macros in sys/mtio.h and syslog.h used NULL without defining it

10 years agoadd O_TMPFILE flag, new in linux 3.11
Szabolcs Nagy [Sat, 23 Nov 2013 23:47:48 +0000 (23:47 +0000)]
add O_TMPFILE flag, new in linux 3.11

definition in linux:
 #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
where __O_TMPFILE and O_DIRECTORY are arch specific

10 years agoadd TCP_NOTSENT_LOWAT tcp socket option, new in linux v3.12
Szabolcs Nagy [Sat, 23 Nov 2013 23:04:55 +0000 (23:04 +0000)]
add TCP_NOTSENT_LOWAT tcp socket option, new in linux v3.12

10 years agoadd linux tcp state enums
Timo Teräs [Mon, 14 Oct 2013 05:28:19 +0000 (08:28 +0300)]
add linux tcp state enums

10 years agoadd multicast structures from RFC 3678 to netinet/in.h
Timo Teräs [Wed, 31 Jul 2013 09:05:14 +0000 (12:05 +0300)]
add multicast structures from RFC 3678 to netinet/in.h

and use _GNU_SOURCE || _BSD_SOURCE guards for all of the RFC 3678
namespace polluting things like glibc/uclibc does.

10 years agoFix dn_expand pointer following
Michael Forney [Tue, 5 Nov 2013 05:43:57 +0000 (21:43 -0800)]
Fix dn_expand pointer following

10 years agoputgrent: Add missing newline
Michael Forney [Tue, 5 Nov 2013 07:34:21 +0000 (23:34 -0800)]
putgrent: Add missing newline

10 years agoputgrent: Stop writing output on first failure
Michael Forney [Tue, 5 Nov 2013 07:34:20 +0000 (23:34 -0800)]
putgrent: Stop writing output on first failure

This way, if an fprintf fails, we get an incomplete group entry rather
than a corrupted one.

10 years agostrcmp: Remove unnecessary check for *r
Michael Forney [Tue, 5 Nov 2013 05:48:08 +0000 (21:48 -0800)]
strcmp: Remove unnecessary check for *r

If *l == *r && *l, then by transitivity, *r.

10 years agotimeradd/timersub: cast result to void to get rid of warnings
rofl0r [Sat, 23 Nov 2013 12:01:53 +0000 (13:01 +0100)]
timeradd/timersub: cast result to void to get rid of warnings

previously:
timersub(&now, t, &diff);

warning: value computed is not used [-Wunused-value]

10 years agofix and refactor child reaping logic in wordexp
Rich Felker [Fri, 22 Nov 2013 21:29:31 +0000 (16:29 -0500)]
fix and refactor child reaping logic in wordexp

loop condition was incorrect and confusing and caused an infinite loop
when (broken) applications reaped the pid from a signal handler or
another thread before wordexp's call to waitpid could do so.

10 years agofix fd leak and case where fd 1 is already closed in wordexp
Rich Felker [Fri, 22 Nov 2013 20:55:58 +0000 (15:55 -0500)]
fix fd leak and case where fd 1 is already closed in wordexp

10 years agofix resource exhaustion and zero-word cases in wordexp
Rich Felker [Fri, 22 Nov 2013 20:48:24 +0000 (15:48 -0500)]
fix resource exhaustion and zero-word cases in wordexp

when WRDE_NOSPACE is returned, the we_wordv and we_wordc members must
be valid, because the interface contract allows them to return partial
results.

in the case of zero results (due either to resource exhaustion or a
zero-word input) the we_wordv array still should contain a terminating
null pointer and the initial we_offs null pointers. this is impossible
on resource exhaustion, so a correct application must presumably check
for a null pointer in we_wordv; POSIX however seems to ignore the
issue. the previous code may have crashed under this situation.

10 years agoimprove robustness of wordexp and fix handling of 0-word case
Rich Felker [Fri, 22 Nov 2013 20:29:14 +0000 (15:29 -0500)]
improve robustness of wordexp and fix handling of 0-word case

avoid using exit status to determine if a shell error occurred, since
broken programs may install SIGCHLD handlers which reap all zombies,
including ones that don't belong to them. using clone and __WCLONE
does not seem to work for avoiding this problem since exec resets the
exit signal to SIGCHLD.

instead, the new code uses a dummy word at the beginning of the
shell's output, which is ignored, to determine whether the command was
executed successfully. this also fixes a corner case where a word
string containing zero words was interpreted as a single zero-length
word rather than no words at all. POSIX does not seem to require this
case to be supported anyway, though.

in addition, the new code uses the correct retry idiom for waitpid to
ensure that spurious STOP/CONT signals in the child and/or EINTR in
the parent do not prevent successful wait for the child, and blocks
signals in the child.

10 years agoadd legacy getloadavg api
Szabolcs Nagy [Thu, 21 Nov 2013 01:59:43 +0000 (01:59 +0000)]
add legacy getloadavg api

10 years agofix fd leak (missing close-on-exec) in getifaddrs
Rich Felker [Thu, 21 Nov 2013 01:34:33 +0000 (20:34 -0500)]
fix fd leak (missing close-on-exec) in getifaddrs

10 years agomath: add (obsolete) bsd drem and finite functions
Szabolcs Nagy [Thu, 21 Nov 2013 01:16:49 +0000 (01:16 +0000)]
math: add (obsolete) bsd drem and finite functions

10 years agomath: lgamma cleanup (simpler sin(pi*x) for the negative case)
Szabolcs Nagy [Thu, 21 Nov 2013 01:01:57 +0000 (01:01 +0000)]
math: lgamma cleanup (simpler sin(pi*x) for the negative case)

* simplify sin_pi(x) (don't care about inexact here, the result is
  inexact anyway, and x is not so small to underflow)
* in lgammal add the previously removed special case for x==1 and
  x==2 (to fix the sign of zero in downward rounding mode)
* only define lgammal on supported long double platforms
* change tgamma so the generated code is a bit smaller

10 years agofix the nominal type of LDBL_* limits on archs with ld64
Rich Felker [Wed, 20 Nov 2013 23:28:18 +0000 (18:28 -0500)]
fix the nominal type of LDBL_* limits on archs with ld64

previously these macros wrongly had type double rather than long
double. I see no way an application could detect the error in C99, but
C11's _Generic can trivially detect it.

at the same time, even though these archs do not have excess
precision, the number of decimal places used to represent these
constants has been increased to 21 to be consistent with the decimal
representations used for the DBL_* macros.

10 years agowrite floating point limit constants to 21 significant decimal places
Rich Felker [Wed, 20 Nov 2013 22:40:33 +0000 (17:40 -0500)]
write floating point limit constants to 21 significant decimal places

this is enough to produce the correct value even if the constant is
interpreted as 80-bit extended precision, which matters on archs with
excess precision (FLT_EVAL_METHOD==2) under at least some
interpretations of the C standard. the shorter representations, while
correct if converted to the nominal precision at translation time,
could produce an incorrect value at extended precision, yielding
results such as (double)DBL_MAX != DBL_MAX.

10 years agoiswspace: fix handling of 0
rofl0r [Mon, 11 Nov 2013 04:44:47 +0000 (05:44 +0100)]
iswspace: fix handling of 0

10 years agofix harmless inconsistency in semtimedop
Rich Felker [Sat, 9 Nov 2013 22:54:20 +0000 (17:54 -0500)]
fix harmless inconsistency in semtimedop

this should not matter since the reality is that either all the sysv
sem syscalls are individual syscalls, or all of them are multiplexed
on the SYS_ipc syscall (depending on arch). but best to be consistent
anyway.

10 years agoimplement semtimedop
Rich Felker [Sat, 9 Nov 2013 05:18:57 +0000 (00:18 -0500)]
implement semtimedop

this is a Linux-specific extension to the sysv semaphore api.

10 years agoadjust sys/wait.h not to produde errors in strict ISO C feature profile
Rich Felker [Sat, 9 Nov 2013 05:04:02 +0000 (00:04 -0500)]
adjust sys/wait.h not to produde errors in strict ISO C feature profile

siginfo_t is not available from signal.h when the strict ISO C feature
profile (e.g. passing -std=c99 to gcc without defining any other
feature test macros) is used, but the type is needed to declare
waitid. using sys/wait.h (or any POSIX headers) in strict ISO C mode
is an application bug, but in the interest of compatibility, it's best
to avoid producing gratuitous errors. the simplest fix I could find is
suppressing the declaration of waitid (and also signal.h inclusion,
since it's not needed for anything else) in this case, while still
exposing everything else in sys/wait.h

10 years agoremove O_NOFOLLOW from __map_file used for time zone file loading
Rich Felker [Sat, 9 Nov 2013 02:33:42 +0000 (21:33 -0500)]
remove O_NOFOLLOW from __map_file used for time zone file loading

it's not clear why I originally wrote O_NOFOLLOW into this; I suspect
the reason was with an aim of making the function more general for
mapping partially or fully untrusted files provided by the user.
however, the timezone code already precludes use of absolute or
relative pathnames in suid/sgid programs, and disallows .. in
pathnames which are relative to one of the system timezone locations,
so there is no threat of opening a symlink which is not trusted by
appropriate user. since some users may wish to put symbolic links in
the zoneinfo directories to alias timezones, it seems preferable to
allow this.

10 years agofix handling of overly-long TZ environment variable values
Rich Felker [Sat, 9 Nov 2013 01:50:59 +0000 (20:50 -0500)]
fix handling of overly-long TZ environment variable values

the rest of the code is not prepared to handle an empty TZ string, so
falling back to __gmt ("GMT"), just as if TZ had been blank or unset,
is the preferable action.

10 years agotimezone parser: fix iteration over search dir paths
rofl0r [Mon, 4 Nov 2013 17:07:28 +0000 (17:07 +0000)]
timezone parser: fix iteration over search dir paths

try+l points to \0, so only one iteration was ever tried.

10 years agotimezone parser: fix offset to transition table in 64bit code path
rofl0r [Mon, 4 Nov 2013 15:57:51 +0000 (15:57 +0000)]
timezone parser: fix offset to transition table in 64bit code path

we need to skip to the second TZif header, which starts at
skip+44, and then skip another header (20 bytes) plus the following
6 32bit values.

10 years agofix timezone parser code crashing on 64bit sys
rofl0r [Mon, 4 Nov 2013 15:13:21 +0000 (15:13 +0000)]
fix timezone parser code crashing on 64bit sys

if sizeof(time_t) == 8, this code path was missing the correct
offset into the zoneinfo file, using the header magic to do
offset calculations.
the 6 32bit fields to be read start at offset 20.

10 years agofix regression in inet_aton due to misinterpretation of __ipparse return
Rich Felker [Sat, 2 Nov 2013 08:07:12 +0000 (04:07 -0400)]
fix regression in inet_aton due to misinterpretation of __ipparse return

inet_aton returns a boolean success value, whereas __ipparse returns 0
on success and -1 on failure. also change the conditional in inet_addr
to be consistent with other uses of __ipparse where only negative
values are treated as failure.

10 years agosimplify faccessat AT_EACCESS path and eliminate resource dependence
Rich Felker [Sat, 2 Nov 2013 00:34:05 +0000 (20:34 -0400)]
simplify faccessat AT_EACCESS path and eliminate resource dependence

now that we're waiting for the exit status of the child process, the
result can be conveyed in the exit status rather than via a pipe.
since the error value might not fit in 7 bits, a table is used to
translate possible meaningful error values to small integers.

10 years agofix faccessat AT_EACCESS path not to leave zombie processes
Rich Felker [Fri, 1 Nov 2013 21:01:52 +0000 (17:01 -0400)]
fix faccessat AT_EACCESS path not to leave zombie processes

I mistakenly assumed that clone without a signal produced processes
that would not become zombies; however, waitpid with __WCLONE is
required to release their pids.

10 years agofix inttypes.h PRI and SCN macros for [u]intptr_t types
Rich Felker [Wed, 30 Oct 2013 18:52:55 +0000 (14:52 -0400)]
fix inttypes.h PRI and SCN macros for [u]intptr_t types

while using "l" unconditionally gave the right behavior due to
matching sizes/representations, it was technically UB and produced
compiler warnings with format string checking.

10 years agoPOSIX conformance fix: define struct entry in search.h
Szabolcs Nagy [Tue, 29 Oct 2013 20:25:11 +0000 (20:25 +0000)]
POSIX conformance fix: define struct entry in search.h

10 years agofenv: fix i386 fesetround for sse
Szabolcs Nagy [Mon, 28 Oct 2013 20:33:54 +0000 (20:33 +0000)]
fenv: fix i386 fesetround for sse

i386 fenv code checks __hwcap for sse support, but in fesetround the sse
code was unconditionally jumped over after the test so the sse rounding
mode was never set.

10 years agomath: extensive log*.c cleanup
Szabolcs Nagy [Mon, 28 Oct 2013 01:16:14 +0000 (01:16 +0000)]
math: extensive log*.c cleanup

The log, log2 and log10 functions share a lot of code and to a lesser
extent log1p too. A small part of the code was kept separately in
__log1p.h, but since it did not capture much of the common code and
it was inlined anyway, it did not solve the issue properly. Now the
log functions have significant code duplication, which may be resolved
later, until then they need to be modified together.

logl, log10l, log2l, log1pl:
* Fix the sign when the return value should be -inf.
* Remove the volatile hack from log10l (seems unnecessary)

log1p, log1pf:
* Change the handling of small inputs: only |x|<2^-53 is special
  (then it is enough to return x with the usual subnormal handling)
  this fixes the sign of log1p(0) in downward rounding.
* Do not handle the k==0 case specially (other than skipping the
  elaborate argument reduction)
* Do not handle 1+x close to power-of-two specially (this code was
  used rarely, did not give much speed up and the precision wasn't
  better than the general)
* Fix the correction term formula (c=1-(u-x) was used incorrectly
  when x<1 but (double)(x+1)==2, this was not a critical issue)
* Use the exact same method for calculating log(1+f) as in log
  (except in log1p the c correction term is added to the result).

log, logf, log10, log10f, log2, log2f:
* Use double_t and float_t consistently.
* Now the first part of log10 and log2 is identical to log (until the
  return statement, hopefully this makes maintainence easier).
* Most special case formulas were removed (close to power-of-two and
  k==0 cases), they increase the code size without providing precision
  or performance benefits (and obfuscate the code).
  Only x==1 is handled specially so in downward rounding mode the
  sign of zero is correct (the general formula happens to give -0).
* For x==0 instead of -1/0.0 or -two54/0.0, return -1/(x*x) to force
  raising the exception at runtime.
* Arg reduction code is changed (slightly simplified)
* The thresholds for arg reduction to [sqrt(2)/2,sqrt(2)] are now
  consistently the [0x3fe6a09e00000000,0x3ff6a09dffffffff] and the
  [0x3f3504f3,0x3fb504f2] intervals for double and float reductions
  respectively (the exact threshold values are not critical)
* Remove the obsolete comment for the FLT_EVAL_METHOD!=0 case in log2f
  (The same code is used for all eval methods now, on i386 slightly
  simpler code could be used, but we have asm there anyway)

all:
* Fix signed int arithmetics (using unsigned for bitmanipulation)
* Fix various comments

10 years agoadd legacy ftime function and sys/timeb.h
Rich Felker [Fri, 25 Oct 2013 18:15:08 +0000 (14:15 -0400)]
add legacy ftime function and sys/timeb.h

despite being marked legacy, this was specified by SUSv3 as part of
the XSI option; only the most recent version of the standard dropped
it. reportedly there's actual code using it.

10 years agofix inet_pton
Szabolcs Nagy [Wed, 23 Oct 2013 01:49:14 +0000 (01:49 +0000)]
fix inet_pton

* parse IPv4 dotted-decimal correctly (without strtoul, no leading zeros)
* disallow single leading ':' in IPv6 address
* allow at most 4 hex digits in IPv6 address (according to RFC 2373)
* have enough hex fields in IPv4 mapped IPv6 address
* disallow leading zeros in IPv4 mapped IPv6 address

10 years agofix __ipparse to parse the generic numbers-and-dots IPv4 format correctly
Szabolcs Nagy [Tue, 22 Oct 2013 12:28:17 +0000 (12:28 +0000)]
fix __ipparse to parse the generic numbers-and-dots IPv4 format correctly

* allow at most 4 parts
* bounds check the parts correctly
* disallow leading whitespace and sign
* check the address family before falling back to IPv6

10 years agofix inet_aton to accept the generic "numbers-and-dots" IPv4 address format
Szabolcs Nagy [Tue, 22 Oct 2013 12:23:17 +0000 (12:23 +0000)]
fix inet_aton to accept the generic "numbers-and-dots" IPv4 address format

10 years agosplit inet_addr and inet_ntoa back into their own files
Rich Felker [Tue, 22 Oct 2013 02:05:29 +0000 (22:05 -0400)]
split inet_addr and inet_ntoa back into their own files

despite being practically deprecated, these functions are still part
of the standard and thus cannot reside in a file that also contains
namespace pollution. this reverts some of the changes made in commit
e40f48a421a9176e3e298b5bac75f0355b219e58.

10 years agofix multiple minor namespace issues in headers
Rich Felker [Mon, 21 Oct 2013 02:01:51 +0000 (22:01 -0400)]
fix multiple minor namespace issues in headers

fcntl.h: AT_* is not a reserved namespace so extensions cannot be
exposed by default.

langinfo.h: YESSTR and NOSTR were removed from the standard.

limits.h: NL_NMAX was removed from the standard.

signal.h: the conditional for NSIG was wrongly checking _XOPEN_SOURCE
rather than _BSD_SOURCE. this was purely a mistake; it doesn't even
match the commit message from the commit that added it.

10 years agofix return value for inet_pton in ipv6 failure cases
Rich Felker [Sun, 20 Oct 2013 02:36:30 +0000 (22:36 -0400)]
fix return value for inet_pton in ipv6 failure cases

in the case of input that does not match the expected form, the
correct return value is 0, not -1.

10 years agouse consistent include guard name in arpa/ftp.h
Szabolcs Nagy [Fri, 18 Oct 2013 15:21:36 +0000 (15:21 +0000)]
use consistent include guard name in arpa/ftp.h

10 years agofix typo in socket.h (wrong macro name)
Szabolcs Nagy [Fri, 18 Oct 2013 15:19:49 +0000 (15:19 +0000)]
fix typo in socket.h (wrong macro name)

10 years agoin faccessat slow path, add close-on-exec to pipe fds
Rich Felker [Fri, 18 Oct 2013 11:12:38 +0000 (07:12 -0400)]
in faccessat slow path, add close-on-exec to pipe fds

as usual, this is needed to avoid fd leaks. as a better solution, the
use of fds could possibly be replaced with mmap and a futex.

10 years agofix uid/gid-setting error in faccessat with AT_EACCESS flag
Rich Felker [Sat, 12 Oct 2013 23:50:09 +0000 (19:50 -0400)]
fix uid/gid-setting error in faccessat with AT_EACCESS flag

this fixes an issue reported by Daniel Thau whereby faccessat with the
AT_EACCESS flag did not work in cases where the process is running
suid or sgid but without root privileges. per POSIX, when the process
does not have "appropriate privileges", setuid changes the euid, not
the real uid, and the target uid must be equal to the current real or
saved uid; if this condition is not met, EPERM results. this caused
the faccessat child process to fail.

using the setreuid syscall rather than setuid works. POSIX leaves it
unspecified whether setreuid can set the real user id to the effective
user id on processes without "appropriate privileges", but Linux
allows this; if it's not allowed, there would be no way for this
function to work.

10 years agofix errno value for getcwd when size argument is zero
Rich Felker [Tue, 8 Oct 2013 23:49:10 +0000 (19:49 -0400)]
fix errno value for getcwd when size argument is zero

based on patch by Michael Forney. at the same time, I've changed the
if branch to be more clear, avoiding the comma operator.

the underlying issue is that Linux always returns ERANGE when size is
too short, even when it's zero, rather than returning EINVAL for the
special case of zero as required by POSIX.

10 years agomath: fix rare underflow issue in fma
Szabolcs Nagy [Mon, 7 Oct 2013 18:46:43 +0000 (18:46 +0000)]
math: fix rare underflow issue in fma

the issue is described in commits 1e5eb73545ca6cfe8b918798835aaf6e07af5beb
and ffd8ac2dd50f99c3c83d7d9d845df9874ec3e7d5

10 years agomath: use sqrtl if FLT_EVAL_METHOD==2 in acosh and acoshf
Szabolcs Nagy [Mon, 7 Oct 2013 18:41:03 +0000 (18:41 +0000)]
math: use sqrtl if FLT_EVAL_METHOD==2 in acosh and acoshf

this makes acosh slightly more precise around 1.0 on i386

10 years agofix clockid macro names in time.h, reported by Paul Schutte
Szabolcs Nagy [Mon, 7 Oct 2013 13:28:03 +0000 (13:28 +0000)]
fix clockid macro names in time.h, reported by Paul Schutte

10 years agoremove errno setting from setenv, malloc sets it correctly on oom
Szabolcs Nagy [Mon, 7 Oct 2013 13:26:51 +0000 (13:26 +0000)]
remove errno setting from setenv, malloc sets it correctly on oom

10 years agofix allocation sizes in regcomp
Szabolcs Nagy [Mon, 7 Oct 2013 13:25:19 +0000 (13:25 +0000)]
fix allocation sizes in regcomp

sizeof had incorrect argument in a few places, the size was always
large enough so the issue was not critical.

10 years agoadd missing va_end in execl* for correcness and static code analyzers
Szabolcs Nagy [Mon, 7 Oct 2013 13:24:00 +0000 (13:24 +0000)]
add missing va_end in execl* for correcness and static code analyzers

10 years agominor vfprintf and vfwprintf changes to please static code analyzers
Szabolcs Nagy [Mon, 7 Oct 2013 13:22:24 +0000 (13:22 +0000)]
minor vfprintf and vfwprintf changes to please static code analyzers

add missing va_end and remove some unnecessary code.

10 years agomath: remove an unused variable from modfl
Szabolcs Nagy [Sun, 6 Oct 2013 02:09:40 +0000 (02:09 +0000)]
math: remove an unused variable from modfl

10 years agoslightly optimize __brk for size
Rich Felker [Sat, 5 Oct 2013 16:00:55 +0000 (12:00 -0400)]
slightly optimize __brk for size

there is no reason to check the return value for setting errno, since
brk never returns errors, only the new value of the brk (which may be
the same as the old, or otherwise differ from the requested brk, on
failure).

it may be beneficial to eventually just eliminate this file and make
the syscalls inline in malloc.c.

10 years agofix failure of malloc to set errno on heap (brk) exhaustion
Rich Felker [Sat, 5 Oct 2013 15:59:21 +0000 (11:59 -0400)]
fix failure of malloc to set errno on heap (brk) exhaustion

I wrongly assumed the brk syscall would set errno, but on failure it
returns the old value of the brk rather than an error code.

10 years agofix failure to check malloc result in setenv
Rich Felker [Fri, 4 Oct 2013 19:49:55 +0000 (15:49 -0400)]
fix failure to check malloc result in setenv

10 years agomath: remove code duplication in erfl found by clang analyzer
Szabolcs Nagy [Fri, 4 Oct 2013 18:10:17 +0000 (18:10 +0000)]
math: remove code duplication in erfl found by clang analyzer

erfl had some superflous code left around after the last erf cleanup.
the issue was reported by Alexander Monakov

10 years agomath: remove a useless assignment in lgammal found by clang analyzer
Szabolcs Nagy [Fri, 4 Oct 2013 18:08:16 +0000 (18:08 +0000)]
math: remove a useless assignment in lgammal found by clang analyzer

the issue was reported by Alexander Monakov

10 years agofix invalid implicit pointer conversion in pthread_key_create
Rich Felker [Fri, 4 Oct 2013 05:06:42 +0000 (01:06 -0400)]
fix invalid implicit pointer conversion in pthread_key_create

10 years agofix uninitialized variable in dladdr
Rich Felker [Fri, 4 Oct 2013 04:29:58 +0000 (00:29 -0400)]
fix uninitialized variable in dladdr

the affected branch only applies for DSOs that lack standard hash
table and only have the GNU hash table present.

10 years agoremoved unused variable in vfwprintf
Rich Felker [Fri, 4 Oct 2013 04:14:57 +0000 (00:14 -0400)]
removed unused variable in vfwprintf

10 years agofix new environment always being null with execle
Rich Felker [Thu, 3 Oct 2013 14:16:01 +0000 (10:16 -0400)]
fix new environment always being null with execle

the va_arg call for the argv[]-terminating null pointer was missing,
so this pointer was being wrongly used as the environment pointer.

issue reported by Timo Teräs. proposed patch slightly modified to
simplify the resulting code.

10 years agofix off-by-one error in getgrnam_r and getgrgid_r, clobbering gr_name
Rich Felker [Sun, 29 Sep 2013 06:52:33 +0000 (02:52 -0400)]
fix off-by-one error in getgrnam_r and getgrgid_r, clobbering gr_name

bug report and patch by Michael Forney. the terminating null pointer
at the end of the gr_mem array was overwriting the beginning of the
string data, causing the gr_name member to always be a zero-length
string.

10 years agofix buffer overflow in mbsrtowcs
Rich Felker [Fri, 27 Sep 2013 17:09:46 +0000 (13:09 -0400)]
fix buffer overflow in mbsrtowcs

issue reported by Michael Forney:

"If wn becomes 0 after processing a chunk of 4, mbsrtowcs currently
continues on, wrapping wn around to -1, causing the rest of the string
to be processed.

This resulted in buffer overruns if there was only space in ws for wn
wide characters."

the original patch submitted added an additional check for !wn after
the loop; to avoid extra branching, I instead just changed the wn>=4
check to wn>=5 to ensure that at least one slot remains after the
word-at-a-time loop runs. this should not slow down the tail
processing on real-world usage, since an extra slot that can't be
processed in the word-at-a-time loop is needed for the null
termination anyway.

10 years agomath: fix comparision macros (isless etc) when FLT_EVAL_METHOD!=0
Szabolcs Nagy [Fri, 27 Sep 2013 13:55:29 +0000 (13:55 +0000)]
math: fix comparision macros (isless etc) when FLT_EVAL_METHOD!=0

This is a change in ISO C11 annex F (F.10.11p1), comparision macros
can't round their arguments to their semantic type when the evaluation
format has wider range and precision. (ie. they must be consistent with
the builtin relational operators)

10 years agoadd missing i386 syscall numbers
Rich Felker [Thu, 26 Sep 2013 18:17:36 +0000 (14:17 -0400)]
add missing i386 syscall numbers

somehow the range 335-339 was missed when updating the file.

10 years agoremove duplicate lines from mips bits/syscall.h
Rich Felker [Thu, 26 Sep 2013 18:11:18 +0000 (14:11 -0400)]
remove duplicate lines from mips bits/syscall.h

10 years agorelease notes for 0.9.14
Rich Felker [Mon, 23 Sep 2013 21:00:53 +0000 (17:00 -0400)]
release notes for 0.9.14

10 years agofix arm atomic store and generate simpler/less-bloated/faster code
Rich Felker [Sun, 22 Sep 2013 07:06:17 +0000 (03:06 -0400)]
fix arm atomic store and generate simpler/less-bloated/faster code

atomic store was lacking a barrier, which was fine for legacy arm with
no real smp and kernel-emulated cas, but unsuitable for more modern
systems. the kernel provides another "kuser" function, at 0xffff0fa0,
which could be used for the barrier, but using that would drop support
for kernels 2.6.12 through 2.6.14 unless an extra conditional were
added to check for barrier availability. just using the barrier in the
kernel cas is easier, and, based on my reading of the assembly code in
the kernel, does not appear to be significantly slower.

at the same time, other atomic operations are adapted to call the
kernel cas function directly rather than using a_cas; due to small
differences in their interface contracts, this makes the generated
code much simpler.

10 years agofix potential deadlock bug in libc-internal locking logic
Rich Felker [Fri, 20 Sep 2013 06:00:27 +0000 (02:00 -0400)]
fix potential deadlock bug in libc-internal locking logic

if a multithreaded program became non-multithreaded (i.e. all other
threads exited) while one thread held an internal lock, the remaining
thread would fail to release the lock. the the program then became
multithreaded again at a later time, any further attempts to obtain
the lock would deadlock permanently.

the underlying cause is that the value of libc.threads_minus_1 at
unlock time might not match the value at lock time. one solution would
be returning a flag to the caller indicating whether the lock was
taken and needs to be unlocked, but there is a simpler solution: using
the lock itself as such a flag.

note that this flag is not needed anyway for correctness; if the lock
is not held, the unlock code is harmless. however, the memory
synchronization properties associated with a_store are costly on some
archs, so it's best to avoid executing the unlock code when it is
unnecessary.

10 years agocorrect the sysconf value for RTSIG_MAX
Rich Felker [Fri, 20 Sep 2013 05:49:03 +0000 (01:49 -0400)]
correct the sysconf value for RTSIG_MAX

this is the number of realtime signals available, not the maximum
signal number or total number of signals.

10 years agofix sigemptyset and sigfillset for mips
Rich Felker [Mon, 16 Sep 2013 16:58:51 +0000 (12:58 -0400)]
fix sigemptyset and sigfillset for mips

they were leaving junk in the upper bits.

10 years agofix clobbering of caller's stack in mips __clone function
Rich Felker [Mon, 16 Sep 2013 15:52:39 +0000 (11:52 -0400)]
fix clobbering of caller's stack in mips __clone function

this was resulting in crashes in posix_spawn on mips, and would have
affected applications calling clone too. since the prototype for
__clone has it as a variadic function, it may not assume that 16($sp)
is writable for use in making the syscall. instead, it needs to
allocate additional stack space, and then adjust the stack pointer
back in both of the code paths for the parent process/thread.

10 years agosys/resource.h: add PRIO_MIN and PRIO_MAX for getpriority and setpriority
Szabolcs Nagy [Sun, 15 Sep 2013 15:32:07 +0000 (15:32 +0000)]
sys/resource.h: add PRIO_MIN and PRIO_MAX for getpriority and setpriority

These constants are not specified by POSIX, but they are in the reserved
namespace, glibc and bsd systems seem to provide them as well.
(Note that POSIX specifies -NZERO and NZERO-1 to be the limits, but
PRIO_MAX equals NZERO)

10 years agoupdate include/elf.h following glibc changes
Szabolcs Nagy [Sun, 15 Sep 2013 14:53:34 +0000 (14:53 +0000)]
update include/elf.h following glibc changes

the changes were verified using various sources:
linux: include/uapi/linux/elf.h
binutils: include/elf/common.h
glibc: elf/elf.h
sysv gabi: http://www.sco.com/developers/gabi/latest/contents.html
sun linker docs: http://docs.oracle.com/cd/E18752_01/pdf/817-1984.pdf
and platform specific docs

- fixed:
EF_MIPS_* E_MIPS_* e_flags: fixed accoding to glibc and binutils

- added:
ELFOSABI_GNU for EI_OSABI entry: glibc, binutils and sysv gabi
EM_* e_machine values: updated according to linux and glibc
PN_XNUM e_phnum value: from glibc and linux, see oracle docs
NT_* note types: updated according to linux and glibc
DF_1_* flags for DT_FLAGS_1 entry: following glibc and oracle docs
AT_HWCAP2 auxv entry for more hwcap bits accoding to linux and glibc
R_386_SIZE32 relocation according to glibc and binutils
EF_ARM_ABI_FLOAT_* e_flags: added following glibc and binutils
R_AARCH64_* relocs: added following glibc and aarch64 elf specs
R_ARM_* relocs: according to glibc, binutils and arm elf specs
R_X86_64_* relocs: added missing relocs following glibc

- removed:
HWCAP_SPARC_* flags were moved to arch specific header in glibc
R_ARM_SWI24 reloc is marked as obsolete in glibc, not present in binutils
  not specified in arm elf spec, R_ARM_TLS_DESC reused its number
  see http://www.codesourcery.com/publications/RFC-TLSDESC-ARM.txt

- glibc changes not pulled in:
ELFOSABI_ARM_AEABI (bare-metal system, binutils and glibc disagrees about the name)
R_68K_* relocs for unsupported platform
R_SPARC_* ditto
EF_SH* ditto (e_flags)
EF_S390* ditto (e_flags)
R_390* ditto
R_MN10300* ditto
R_TILE* ditto

10 years agoomit CLONE_PARENT flag to clone in pthread_create
Rich Felker [Mon, 16 Sep 2013 14:56:01 +0000 (10:56 -0400)]
omit CLONE_PARENT flag to clone in pthread_create

CLONE_PARENT is not necessary (CLONE_THREAD provides all the useful
parts of it) and Linux treats CLONE_PARENT as an error in certain
situations, without noticing that it would be a no-op due to
CLONE_THREAD. this error case prevents, for example, use of a
multi-threaded init process and certain usages with containers.

10 years agouse symbolic names for clone flags in pthread_create
Rich Felker [Mon, 16 Sep 2013 14:54:31 +0000 (10:54 -0400)]
use symbolic names for clone flags in pthread_create

10 years agosys/socket.h: add new SO_BUSY_POLL socket option
Szabolcs Nagy [Sun, 15 Sep 2013 04:54:19 +0000 (04:54 +0000)]
sys/socket.h: add new SO_BUSY_POLL socket option

low latency busy poll sockets are new in linux v3.11

10 years agoptrace.h: add new ptrace requests to get/set sigmask
Szabolcs Nagy [Sun, 15 Sep 2013 02:49:26 +0000 (02:49 +0000)]
ptrace.h: add new ptrace requests to get/set sigmask

PTRACE_GETSIGMASK and PTRACE_SETSIGMASK were added in linux v3.11
and used by checkpoint/restore tools

10 years agonet/if_arp.h: add missing ARP hardware identifiers from linux uapi headers
Szabolcs Nagy [Sun, 15 Sep 2013 02:42:29 +0000 (02:42 +0000)]
net/if_arp.h: add missing ARP hardware identifiers from linux uapi headers

the removed ARPHRD_IEEE802154_PHY was only present in the kernel api
in v2.6.31 (by accident), but it got into the glibc headers (in 2009)
and remained there since this header was not updated since then.

10 years agonetinet/in.h: add missing IP protocol numbers from the linux uapi headers
Szabolcs Nagy [Sun, 15 Sep 2013 02:41:36 +0000 (02:41 +0000)]
netinet/in.h: add missing IP protocol numbers from the linux uapi headers

10 years agosupport configurable page size on mips, powerpc and microblaze
Szabolcs Nagy [Sun, 15 Sep 2013 02:00:32 +0000 (02:00 +0000)]
support configurable page size on mips, powerpc and microblaze

PAGE_SIZE was hardcoded to 4096, which is historically what most
systems use, but on several archs it is a kernel config parameter,
user space can only know it at execution time from the aux vector.

PAGE_SIZE and PAGESIZE are not defined on archs where page size is
a runtime parameter, applications should use sysconf(_SC_PAGE_SIZE)
to query it. Internally libc code defines PAGE_SIZE to libc.page_size,
which is set to aux[AT_PAGESZ] in __init_libc and early in __dynlink
as well. (Note that libc.page_size can be accessed without GOT, ie.
before relocations are done)

Some fpathconf settings are hardcoded to 4096, these should be actually
queried from the filesystem using statfs.