summaryrefslogtreecommitdiff
path: root/src
AgeCommit message (Collapse)AuthorLines
2014-06-06fix incorrect end pointer in some cases when wcsrtombs stops earlyRich Felker-7/+15
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)
2014-06-06fix for broken kernel side RLIM_INFINITY on mipsSzabolcs Nagy-3/+38
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)
2014-06-06fix sendfile syscall to use 64-bit off_tRich Felker-0/+5
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.
2014-05-20fix unhandled cases in strptimeRich Felker-5/+16
%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)
2014-05-20fix strftime %s not to zero pad with default width=2Szabolcs Nagy-0/+1
(cherry picked from commit ac0acd569e01735fc6052d43fdf57f3a07c93f3d)
2014-05-20remove useless __yield alias for sched_yieldRich Felker-4/+1
this is no longer used for anything, and reportedly clashed with a builtin on certain compilers. (cherry picked from commit adbf0258be4eea5f012e173de7e55a87f3093669)
2014-05-20perform minimal sanity checks on zoneinfo files loaded via TZ variableRich Felker-0/+5
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)
2014-05-20fix false negatives with periodic needles in strstr, wcsstr, and memmemRich Felker-3/+3
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)
2014-04-16fix deadlock race in pthread_onceRich Felker-2/+1
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)
2014-04-16fix fallback code for old kernels in clock_gettimeRich Felker-1/+1
(cherry picked from commit 805698401dbac7ce3079fa97eaad5ba0508377f4)
2014-04-16use hidden visibility rather than protected for syscall internalsRich Felker-1/+1
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)
2014-04-16math: fix aliasing violation in long double wrappersSzabolcs Nagy-2/+10
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)
2014-04-16fix search past the end of haystack in memmemTimo Teräs-0/+1
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)
2014-04-16fix printf rounding with %g for some corner case midpointsRich Felker-1/+1
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)
2014-04-16fix failure of printf %g to strip trailing zeros in some casesRich Felker-1/+1
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)
2014-04-16fix carry into uninitialized slots during printf floating point roundingRich Felker-1/+1
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)
2014-04-16fix confstr return valueTimo Teräs-1/+1
per the specification, the terminating null byte is counted. (cherry picked from commit 0a8d98285f46f721dabf38485df916c02d6a4675)
2014-04-16include header that declares __syscall_ret where it's definedRich Felker-0/+1
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)
2014-03-18fix mips sigsetjmp asm to match fixed jmp_buf sizeRich Felker-1/+1
this was missed in the previous commit.
2014-03-18use syscall_arg_t for arguments in public syscall() functionRich Felker-7/+7
on x32, this change allows programs which use syscall() with pointers or 64-bit values as arguments to work correctly, i.e. without truncation or incorrect sign extension. on all other supported archs, syscall_arg_t is defined as long, so this change is a no-op.
2014-03-17fix negated error codes from ptsname_rRich Felker-1/+1
the incorrect error codes also made their way into errno when __ptsname_r was called by plain ptsname, which reports errors via errno rather than a return value.
2014-03-13semctl: fix UB causing crashes on powerpcrofl0r-4/+8
it's UB to fetch variadic args when none are passed, and this caused real crashes on ppc due to its calling convention, which defines that for variadic functions aggregate types be passed as pointers. the assignment caused that pointer to get dereferenced, resulting in a crash.
2014-03-09fix incorrect rounding in printf floating point corner casesRich Felker-2/+2
the printf floating point formatting code contains an optimization to avoid computing digits that will be thrown away by rounding at the specified (or default) precision. while it was correctly retaining all places up to the last decimal place to be printed, it was not retaining enough precision to see the next nonzero decimal place in all cases. this could cause incorrect rounding down in round-to-even (default) rounding mode, for example, when printing 0.5+DBL_EPSILON with "%.0f". in the fix, LDBL_MANT_DIG/3 is a lazy (non-sharp) upper bound on the number of zeros between any two nonzero decimal digits.
2014-03-09fix buffer overflow in printf formatting of denormals with low bit setRich Felker-1/+2
empirically the overflow was an off-by-one, and it did not seem to be overwriting meaningful data. rather than simply increasing the buffer size by one, however, I have attempted to make the size obviously correct in terms of bounds on the number of iterations for the loops that fill the buffer. this still results in no more than a negligible size increase of the buffer on the stack (6-7 32-bit slots) and is a "safer" fix unless/until somebody wants to do the proof that a smaller buffer would suffice.
2014-03-07in fcntl, use unsigned long instead of long for variadic argument typeRich Felker-2/+2
neither is correct; different commands take different argument types, and some take no arguments at all. I have a much larger overhaul of fcntl prepared to address this, but it's not appropriate to commit during freeze. the immediate problem being addressed affects forward-compatibility on x32: if new commands are added and they take pointers, but the libc-level fcntl function is not aware of them, using long would sign-extend the pointer to 64 bits and give the kernel an invalid pointer. on the kernel side, the argument to fcntl is always treated as unsigned long, so no harm is done by treating possibly-signed integer arguments as unsigned. for every command that takes an integer argument except for F_SETOWN, large integer arguments and negative arguments are handled identically anyway. in the case of F_SETOWN, the kernel is responsible for converting the argument which it received as unsigned long to int, so the sign of negative arguments is recovered. the other problem that will be addressed later is that the type passed to va_arg does not match the type in the caller of fcntl. an advanced compiler doing cross-translation-unit analysis could potentially see this mismatch and issue warnings or otherwise make trouble. on i386, this patch was confirmed not to alter the code generated by gcc 4.7.3. in principle the generated code should not be affected on any arch except x32.
2014-03-06x32: fix sysinfo()rofl0r-0/+5
the kernel uses long longs in the struct, but the documentation says they're long. so we need to fixup the mismatch between the userspace and kernelspace structs. since the struct offers a mem_unit member, we can avoid truncation by adjusting that value.
2014-03-05fix strerror on mips: one error code is out of the 8-bit table rangeRich Felker-1/+7
if we ever encounter other targets where error codes don't fit in the 8-bit range, the table should probably just be bumped to 16-bit, but for now I don't want to increase the table size on all archs just because of a bug in the mips abi.
2014-02-27add nofpu subarchs to the sh arch, and properly detect compiler's fpu configRich Felker-0/+49
2014-02-27rename superh port to "sh" for consistencyRich Felker-0/+0
linux, gcc, etc. all use "sh" as the name for the superh arch. there was already some inconsistency internally in musl: the dynamic linker was searching for "ld-musl-sh.path" as its path file despite its own name being "ld-musl-superh.so.1". there was some sentiment in both directions as to how to resolve the inconsistency, but overall "sh" was favored.
2014-02-25fix readdir not to set ENOENT when directory is removed while readingRich Felker-2/+7
per POSIX, ENOENT is reserved for invalid stream position; it is an optional error and would only happen if the application performs invalid seeks on the underlying file descriptor. however, linux's getdents syscall also returns ENOENT if the directory was removed between the time it was opened and the time of the read. we need to catch this case and remap it to simple end-of-file condition (null pointer return value like an error, but no change to errno). this issue reportedly affects GNU make in certain corner cases. rather than backing up and restoring errno, I've just changed the syscall to be made in a way that doesn't affect errno (via an inline syscall rather than a call to the __getdents function). the latter still exists for the purpose of providing the public getdents alias which sets errno.
2014-02-24add missing sub files for mipsel-sf to use softfloat codeRich Felker-0/+3
the build system has no automatic way to know this code applies to both big (default) and little endian variants, so explicit .sub files are needed.
2014-02-24mips: add mips-sf subarch support (soft-float)Szabolcs Nagy-0/+53
Userspace emulated floating-point (gcc -msoft-float) is not compatible with the default mips abi (assumes an FPU or in kernel emulation of it). Soft vs hard float abi should not be mixed, __mips_soft_float is checked in musl's configure script and there is no runtime check. The -sf subarch does not save/restore floating-point registers in setjmp/longjmp and only provides dummy fenv implementation.
2014-02-23superh portBobby Bingham-0/+374
2014-02-23mostly-cosmetic fixups to x32 port mergeRich Felker-11/+11
2014-02-23x32 port (diff against vanilla x86_64)rofl0r-114/+120
2014-02-23import vanilla x86_64 code as x32rofl0r-0/+675
2014-02-22use syscall_arg_t type for syscall prototypes in pthread coderofl0r-3/+8
2014-02-22internal/syscall.h: add syscall_arg_t macrorofl0r-6/+11
some 32-on-64 archs require that the actual syscall args be long long. in that case syscall_arch.h can define syscall_arg_t to whatever it needs and syscall.h picks it up. all other archs just use long as usual.
2014-02-22internal/syscall.h: use a macro for the syscall args castsrofl0r-13/+17
this allows syscall_arch.h to define the macro __scc if special casting is needed, as is the case for x32, where the actual syscall arguments are 64bit, but, in case of pointers, would get sign-extended and thus become invalid.
2014-02-21add fallback emulation for accept4 on old kernelsRich Felker-1/+12
the other atomic FD_CLOEXEC interfaces (dup3, pipe2, socket) already had such emulation in place. the justification for doing the emulation here is the same as for the other functions: it allows applications to simply use accept4 rather than having to have their own fallback code for ENOSYS/EINVAL (which one you get is arch-specific!) and there is no reasonable way an application could benefit from knowing the operation is emulated/non-atomic since there is no workaround at the application level for non-atomicity (that is the whole reason these interfaces were added).
2014-02-13add ipv6 and icmpv6 to getprotoent-family functionsRich Felker-1/+3
based on patch by orc.
2014-02-13fix typo in table for getprotoent that caused out-of-bound readsRich Felker-1/+1
this was unlikely to lead to any crash or dangerous behavior, but caused adjacent string constants to be treated as part of the protocols table, possibly returning nonsensical results for unknown protocol names/numbers or when getprotoent was called in a loop to enumerate all protocols.
2014-02-12make posix_spawn accept null pid pointer argumentsRich Felker-1/+1
this is a requirement in the specification that was overlooked.
2014-02-09clone: make clone a wrapper around __cloneBobby Bingham-18/+22
The architecture-specific assembly versions of clone did not set errno on failure, which is inconsistent with glibc. __clone still returns the error via its return value, and clone is now a wrapper that sets errno as needed. The public clone has also been moved to src/linux, as it's not directly related to the pthreads API. __clone is called by pthread_create, which does not report errors via errno. Though not strictly necessary, it's nice to avoid clobbering errno here.
2014-02-09fix fesetenv(FE_DFL_ENV) on x86_64 (see previous commit)Szabolcs Nagy-1/+1
2014-02-09fix fesetenv(FE_DFL_ENV) on i386Szabolcs Nagy-1/+1
the default fenv was not set up properly, in particular the tag word that indicates the contents of the x87 registers was set to 0 (used) instead of 0xffff (empty) this could cause random crashes after setting the default fenv because it corrupted the fpu stack and then any float computation gives NaN result breaking the program logic (usually after a float to integer conversion).
2014-02-07in fdopen, avoid setting O_APPEND flag if it's already setRich Felker-1/+2
this saves a syscall in the case where the underlying open already took place with O_APPEND, which is common because fopen with append modes sets O_APPEND at the time of open before passing the file descriptor to __fdopen.
2014-02-07fix ftello result for append streams with unflushed outputRich Felker-1/+5
when there is unflushed output, ftello (and ftell) compute the logical stream position as the underlying file descriptor's offset plus an adjustment for the amount of buffered data. however, this can give the wrong result for append-mode streams where the unflushed writes should adjust the logical position to be at the end of the file, as if a seek to end-of-file takes place before the write. the solution turns out to be a simple trick: when ftello (indirectly) calls lseek to determine the current file offset, use SEEK_END instead of SEEK_CUR if the stream is append-mode and there's unwritten buffered data. the ISO C rules regarding switching between reading and writing for a stream opened in an update mode, along with the POSIX rules regarding switching "active handles", conveniently leave undefined the hypothetical usage cases where this fix might lead to observably incorrect offsets. the bug being fixed was discovered via the test case for glibc issue
2014-02-05add legacy functions setkey() and encrypt()Timo Teräs-6/+66
2014-02-01fix nftw FTW_MOUNT flagRich Felker-2/+1
the incorrect check for crossing device boundaries was preventing nftw from traversing anything except the initially provided pathname.