summaryrefslogtreecommitdiff
path: root/src
AgeCommit message (Collapse)AuthorLines
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.
2014-01-23fix an overflow in wcsxfrm when n==0Szabolcs Nagy-2/+4
posix allows zero length destination
2014-01-21fix crash in dynamic linker when certain copy relocations are unsatisfiedRich Felker-1/+2
STB_WEAK is only a weak reference for undefined symbols (those with a section of SHN_UNDEF). otherwise, it's a weak definition. normally this distinction would not matter, since a relocation referencing a symbol that also provides a definition (not SHN_UNDEF) will always succeed in finding the referenced symbol itself. however, in the case of copy relocations, the referenced symbol itself is ignored in order to search for another symbol to copy from, and thus it's possible that no definition is found. in this case, if the symbol being resolved happened to be a weak definition, it was misinterpreted as a weak reference, suppressing the error path and causing a crash when the copy relocation was performed with a null source pointer passed to memcpy. there are almost certainly still situations in which invalid combinations of symbol and relocation types can cause the dynamic linker to crash (this is pretty much inevitable), but the intent is that crashes not be possible for symbol/relocation tables produced by a valid linker.
2014-01-21fix initstate to make the state buffer usable in setstateSzabolcs Nagy-12/+2
setstate could use the results of previous initstate or setstate calls (they return the old state buffer), but the documentation requires that an initialized state buffer should be possible to use in setstate immediately, which means that initstate should save the generator parameters in it. I also removed the copyright notice since it is present in the copyright file.
2014-01-08fix inadvertent use of struct in place of union for semunRich Felker-3/+3
2014-01-08add __isoc99_vfscanf weak alias to vfscanfSzabolcs Nagy-0/+2
this glibc abi compatibility function was missed when the scanf aliases were added.
2014-01-08math: add drem and dremf weak aliases to i386 remainder asmSzabolcs Nagy-0/+6
weak_alias was only in the c code, so drem was missing on platforms where remainder is implemented in asm.
2014-01-08fix type of semctl variadic argumentRich Felker-4/+10
per POSIX, the variadic argument has type union semun, which may contain a pointer or int; the type read depends on the command being issued. this allows the userspace part of the implementation to be type-correct without requiring special-casing for different commands. the kernel always expects to receive the argument interpreted as unsigned long (or equivalently, a pointer), and does its own handling of extracting the int portion from the representation, as needed. this change fixes two possible issues: most immediately, reading the argument as a (signed) long and passing it to the syscall would perform incorrect sign-extension of pointers on the upcoming x32 target. the other possible issue is that some archs may use different (user-space) argument-passing convention for unions, preventing va_arg from correctly obtaining the argument when the type long (or even unsigned long or void *) is passed to it.
2014-01-08in fcntl, avoid passing pointer arguments to syscalls as longsRich Felker-3/+12
really, fcntl should be changed to use the correct type corresponding to cmd when calling va_arg, and to carry the correct type through until making the syscall. however, this greatly increases binary size and does not seem to offer any benefits except formal correctness, so I'm holding off on that change for now. the minimal changes made in this patch are in preparation for addition of the x32 port, where the syscall macros need to know whether their arguments are pointers or integers in order to properly pass them to the 64-bit kernel.
2014-01-07fix const-correctness of argument to stimeRich Felker-1/+1
it's unclear what the historical signature for this function was, but semantically, the argument should be a pointer to const, and this is what glibc uses. correct programs should not be using this function anyway, so it's unlikely to matter.
2014-01-07fix signedness of pgoff argument to remap_file_pagesRich Felker-1/+1
both the kernel and glibc agree that this argument is unsigned; the incorrect type ssize_t came from erroneous man pages.
2014-01-07fix const-correctness in sigandset/sigorset argumentsRich Felker-2/+2
this change is consistent with the corresponding glibc functions and is semantically const-correct. the incorrect argument types without const seem to have been taken from erroneous man pages.
2014-01-07fix incorrect type for wd argument of inotify_rm_watchRich Felker-1/+1
this was wrong since the original commit adding inotify, and I don't see any explanation for it. not even the man pages have it wrong. it was most likely a copy-and-paste error.
2014-01-06fix argument types for legacy function inet_makeaddrRich Felker-2/+1
the type int was taken from seemingly erroneous man pages. glibc uses in_addr_t (uint32_t), and semantically, the arguments should be unsigned.
2014-01-06eliminate explicit (long) casts when making syscallsRich Felker-5/+5
this practice came from very early, before internal/syscall.h defined macros that could accept pointer arguments directly and handle them correctly. aside from being ugly and unnecessary, it looks like it will be problematic when we add support for 32-bit ABIs on archs where registers (and syscall arguments) are 64-bit, e.g. x32 and mips n32.
2014-01-06const-qualify the address argument to dladdrRich Felker-4/+4
this agrees with implementation practice on glibc and BSD systems, and is the const-correct way to do things; it eliminates warnings from passing pointers to const. the prototype without const came from seemingly erroneous man pages.
2014-01-06add some missing LFS64 aliases for fadvise/fallocate functionsRich Felker-0/+10
2014-01-03fanotify.c: fix typo in header inclusionrofl0r-1/+1
the header is included only as a guard to check that the declaration and definition match, so the typo didn't cause any breakage aside from omitting this check.
2014-01-02disable the brk functionRich Felker-1/+2
the reasons are the same as for sbrk. unlike sbrk, there is no safe usage because brk does not return any useful information, so it should just fail unconditionally.
2014-01-02disable sbrk for all values of increment except 0Rich Felker-3/+3
use of sbrk is never safe; it conflicts with malloc, and malloc may be used internally by the implementation basically anywhere. prior to this change, applications attempting to use sbrk to do their own heap management simply caused untrackable memory corruption; now, they will fail with ENOMEM allowing the errors to be fixed. sbrk(0) is still permitted as a way to get the current brk; some misguided applications use this as a measurement of their memory usage or for other related purposes, and such usage is harmless. eventually sbrk may be re-added if/when malloc is changed to avoid using the brk by using mmap for all allocations.
2014-01-02add fanotify syscall wrapper and headerrofl0r-0/+14
2013-12-20implement legacy function herrorRich Felker-0/+8
based on patch by Timo Teräs; greatly simplified to use fprintf.