aboutsummaryrefslogtreecommitdiff
path: root/lib/libc
Commit message (Collapse)AuthorAgeFilesLines
* libc/amd64/strrchr.S: rewrite and fix scalar implementationRobert Clausecker14 hours1-52/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The original scalar implementation of strrchr() had incorrect logic that failed if the character searched for was the NUL character. It was also possibly affected by the issue fixed in 3d8ef251a for strchrnul(). Rewrite the function with logic that actually works. We defer checking for the character until after we have checked for NUL. When we encounter the final NUL byte, we mask out the characters beyond the tail before checking for a match. This bug only affects users running on amd64 with ARCHLEVEL=scalar (cf. simd(7)). The default configuration is not affected. The bug was unfortunately not caught by the unit test inherited from NetBSD. An extended unit test catching the issue is proposed in D56037. PR: 293915 Reported by: safonov.paul@gmail.com Tested by: safonov.paul@gmail.com Fixes: 2ed514a220edbac6ca5ec9f40a3e0b3f2804796d See also: https://reviews.freebsd.org/D56037 MFC after: 1 week (cherry picked from commit 253f15c016ca699906f78b8e522a3f7ed675929b) (cherry picked from commit 23d6516773916d8f324bea51867b0713c476f379)
* rtld_get_var(3): provide explicit list of rtld vars that can be modifiedKonstantin Belousov20 hours1-0/+17
| | | | (cherry picked from commit f7b368d25fadbfcba5072dfab3738082393fa189)
* dup(2): document the handling of filedescriptor flagsKonstantin Belousov3 days1-0/+2
| | | | (cherry picked from commit 6cc99baea607255859ee958608e4db6e2ff24793)
* realpath: Improve manual pageDag-Erling Smørgrav9 days1-24/+12
| | | | | | | | | | | | | | | | * Try to make the RETURN VALUES section flow better. * Add basename(3), dirname(3), free(3) to the SEE ALSO section. * Drop the CAVEATS section, which was obsolete the moment realpath(3) was added to the Single Unix Specification in 1994. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55928 (cherry picked from commit 1aecb32021ce46d812db36b9037cdc6f423575f9)
* realpath: Improve prev_len logicDag-Erling Smørgrav9 days1-3/+7
| | | | | | | | | | | | | | | | | * Save prev_len after having checked for and appended a trailing slash, not before. This requires us to back up if we end up returning a partial result, but previously we would sometimes return a partial result with a trailing slash and sometimes without. * Replace strlcat() with a faster strlcpy() since we know exactly how far into the buffer we are. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55914 (cherry picked from commit 99d295e471bc362a7927047c89472e1ee2d0da6b)
* libc/riscv64: temporarily disable strnlen() implementation until a fix is ↵Strahinja Stanišić2026-03-141-1/+0
| | | | | | | | | | | | | | developed strnlen() doesn't seem to cope well with a length argument such that string pointer plus length overflows past the end of the address space. Reviewed by: fuz MFC after: 1 week PR: 293353, 293296 Differential Revision: https://reviews.freebsd.org/D55714 (cherry picked from commit 2a4e3112c811b9892e14e15cfd23538e7e47329c)
* system(3): Address test robustness issueDag-Erling Smørgrav2026-03-111-11/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | Don't assume that SIGINT and SIGQUIT are set to SIG_DFL at the start of the test. Instead, retrieve their current dispositions and verify that they are restored at the end of the test. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55709 (cherry picked from commit 48368f702423742b2a7dff7ad3191625e8bf26f0) system(3): Fix brain glitch in previous commit We were saving SIGINT twice instead of SIGINT and SIGQUIT. Also restore original order of operations (SIGINT then SIGQUIT), which matches the order in which they're discussed in the POSIX description of system(3). MFC after: 1 week Sponsored by: Klara, Inc. Fixes: 48368f702423 ("system(3): Address test robustness issue") (cherry picked from commit 863b5c137a98d29dc6964cba0e0c4fe2a8bebab8)
* system(3): Unwrap execve()Dag-Erling Smørgrav2026-03-111-1/+3
| | | | | | | | | | | | | There is no need to call execl(), which will allocate an array and copy our arguments into it, when we can use a static array and call execve() directly. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55648 (cherry picked from commit 40e52e0edd038460a2a2aca017b3ac5a513fe37b)
* Refinements to the output when the EXTERROR_VERBOSE environment is setKirk McKusick2026-03-062-9/+27
| | | | | | | | Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D55494 Sponsored-by: Netflix (cherry picked from commit 6fd98877de633f5ec6f028e78d5a2d94527d63d0)
* system(3): Fix null caseDag-Erling Smørgrav2026-03-042-1/+11
| | | | | | | | | | | | | | | | | | | | | | | Our manual page states that if given a null pointer, system() returns non-zero if the shell is available and zero if it is not. This is consistent with the C standard's description of system(), but it is not what we actually do. What we actually do is always return non-zero, as required by POSIX. As the POSIX rationale explains, implementing the logic required by the C standard does not violate POSIX, since a conforming system always has a shell, therefore the logic will always return non-zero. Since our libc is commonly used in non-conforming situations such as chroots or thin jails, we should implement the full logic required by the C standard. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: obiwac, bnovkov, kevans Differential Revision: https://reviews.freebsd.org/D55484 (cherry picked from commit 8ae3f44991948cc97b09adc248a9a46db71bf9e0)
* system(3): Clarify return valuesDag-Erling Smørgrav2026-03-041-3/+5
| | | | | | | | | | | | | | Our manual page currently states that system() will return 127 if it fails to execute the shell. The actual return value is, to quote POSIX, “as if the command language interpreter had terminated using exit(127) or _exit(127)”. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: bnovkov, kevans Differential Revision: https://reviews.freebsd.org/D55483 (cherry picked from commit 7305604b29d3db29c9bb5de6e7a25829fb541d1e)
* system(3): Write our own testsDag-Erling Smørgrav2026-03-042-1/+166
| | | | | | | | | | | Replace the somewhat perfunctory NetBSD tests with our own. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: bnovkov, kevans Differential Revision: https://reviews.freebsd.org/D55482 (cherry picked from commit 7a1ade5109ac57d1f59eaa75b5d0f13fabecf6ba)
* system(3): Improve signal handlingDag-Erling Smørgrav2026-03-041-43/+73
| | | | | | | | | | | | | | | | | | Ignore SIGINT and SIGQUIT and block SIGCHLD, as POSIX requires. To deal with the concurrency problem described in POSIX, we keep track of the count of concurrent invocations. We ignore and block signals only when the counter was zero before we incremented it, and restore them only when the counter reaches zero after we decrement it. Note that this does not address the issue of thread cancellation. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: bnovkov, sef, kevans Differential Revision: https://reviews.freebsd.org/D55471 (cherry picked from commit 6e589e6e8e64793adb437c561ec084dbb6ad1ced)
* libc: add man page for uexterr_gettext(3)Konstantin Belousov2026-02-212-0/+72
| | | | (cherry picked from commit a03f285afafae243396c9bc7892cbe717a3ac37d)
* libc: improve include usage for exterror sourcesKonstantin Belousov2026-02-211-0/+1
| | | | (cherry picked from commit 1443a455a96e587a7b49608def79495e9d74513f)
* libc: print extended errors from warn(3) and vwarn(3)Konstantin Belousov2026-02-211-2/+2
| | | | (cherry picked from commit ffbf95907039821b69dfe1607d1695b46af82e35)
* libc/arm: use __builtin_trap() instead of abort() in aeabi_unwind stubsRobert Clausecker2026-02-201-6/+6
| | | | | | | | | | | | This avoids a dependency on the abort symbol in libsys. PR: 292539 Reviewed by: mmel Approved by: markj (mentor) MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D55255 (cherry picked from commit 1782bc9a0a8da2d6aca31b7790981e1980c9e4b9)
* libc: Improve {,l,ll,imax}div(3) manpagesAymeric Wibo2026-02-176-26/+28
| | | | | | | | | | | | Mainly rename numerator parameter of div(3) and ldiv(3) from num to numer, and explicitly specify what "numer", "denom", and "rem" mean in the manpages. MFC after: 3 days Obtained from: https://github.com/apple-oss-distributions/libc (partially) Sponsored by: Klara, Inc. (cherry picked from commit 0bba277f2223a31e4453ade39be110b1b3aeb1dd)
* lib/libc/net/sockatmark.3: fix groff mdoc warningKonstantin Belousov2026-02-151-1/+1
| | | | | | PR: 293072 (cherry picked from commit 10fde719587c22085c95759a242e9c51d249d024)
* libc/aarch64: Add memset for a 64 byte dc zvaAndrew Turner2026-02-093-1/+20
| | | | | | | | | | | | | | | | | | On arm64 we can use the "dc zva" instruction to zero memory. The CPU tells software if the instruction is implemented, and if so the size and alignment it will use. When the size is 64-bytes the Arm Optimized Routines implementation of memset can use dc zva to zero memory, and has a build flag to skip checking. Use this flag to build a version of memset that will be used when this assumption is true. Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D54776 (cherry picked from commit 32d1f18865abe94d351a6f178a93b7195595ec69)
* libc/aarch64: Split out the MOPS functionsAndrew Turner2026-02-093-3/+14
| | | | | | | | | | | This allows static binaries to only include the functions they reference. Reviewed by: imp Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D54775 (cherry picked from commit f0516ed4652cfb7435f8c5a16b46dc067779a1a8)
* libc/aarch64: Add a Makefile.inc dependencyAndrew Turner2026-02-091-2/+2
| | | | | | | | | | | If we update Makefile.inc it may be to change the contents of these files. Reviewed by: imp Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D54774 (cherry picked from commit 00f68392130cf597c7c76669c63dab26b31630c1)
* libc/aarch64: Use MOPS implementations of memcpy/memmove/memset where availbleSarah Walker2026-02-096-6/+139
| | | | | | | | | Reviewed by: andrew Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D54560 (cherry picked from commit 41ccf82b29f3b16fcd1ccb4987569c851222ef8d) (cherry picked from commit fb96702a034c663adb4a1b44299af01fa71e29fd)
* libc/csu: Pass HWCAP flags to ifunc resolver functionsSarah Walker2026-02-091-3/+28
| | | | | | | | | | | | Function arguments are based on Section 9.4.1 "GNU C Library IFUNC interface" from "System V ABI for the Arm 64-bit Architecture (AArch64)", 2025Q1. (https://github.com/ARM-software/abi-aa/releases/download/2025Q1/sysvabi64.pdf) Reviewed by: andrew Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D54599 (cherry picked from commit 5eec3531204bd93426642a9c45b0c292a01447e4)
* libc/tests: Clean up *dir() testsDag-Erling Smørgrav2026-02-051-15/+13
| | | | | | | | | | | Mainly, avoid reusing the name of one of the functions we should be testing (but aren't) for local variables. Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D55054 (cherry picked from commit d70b9eb74fc4aa430bd2ff4bca37e6a9b6c8004f)
* libc: Fix missing includeDag-Erling Smørgrav2026-02-051-0/+1
| | | | | | | | Although not needed on FreeBSD due to namespace pollution, we should technically #include <stddef.h> to secure a definition of NULL. Fixes: 5074d5c9845e ("libc: Improve POSIX conformance of dirfd()") (cherry picked from commit 1c00d5a3b234ef937d848956027e9de5ea8010f9)
* libc: Improve POSIX conformance of dirfd()Dag-Erling Smørgrav2026-02-052-1/+18
| | | | | | | | | | | | | | POSIX states that dirfd() should set errno to EINVAL and return -1 if dirp does not refer to a valid directory stream. Our interpretation is that this applies if dirp is null or the file descriptor associated with it is negative. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D55025 (cherry picked from commit 5074d5c9845e142883cdbb9ad212be66e57615d0)
* libc: Clean up *dir() codeDag-Erling Smørgrav2026-02-059-49/+43
| | | | | | | | | | | Fix style nits (mostly whitespace issues) and clean up the manual page. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D55024 (cherry picked from commit 387ae6390534b6e9b48931840e7bc76eeb0b258d)
* libc/resolv: Switch default to loopback addressDag-Erling Smørgrav2026-02-051-41/+26
| | | | | | | | | | | | | | | | | | | If no resolver configuration was found, we would fall back to INADDR_ANY and IN6ADDR_ANY. This made sense when it was first written thirty or forty years ago but not today, especially since connecting to INADDR_ANY or IN6ADDR_ANY is no longer supported. Switch to the loopback address and simplify the code. Note that (as the pre-existing comment in the code states) running without a resolver configuration is not really supported. Still, if we're going to have a hardcoded fallback, it might as well work. PR: 291790 MFC after: 1 week Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55011 (cherry picked from commit 1538284a5fddfce546db678cb873b7edc6adb9ed)
* METALOG: Order keyword entriesJose Luis Duran2026-02-031-3/+3
| | | | | | | | | | | | | To facilitate comparison with mtree -C generated output, keep the keywords ordered. No functional change intended. Reviewed by: imp MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D54872 (cherry picked from commit fe962e33d86f888b496b17251c8bedebf92be8ee)
* posix_spawn: use rfork_thread on all archesKonstantin Belousov2026-02-011-21/+18
| | | | (cherry picked from commit 4daf2d3e7db53a113108f9a02ceaf5051d416184)
* libc: document posix_spawnattr_{get,set}procdescp_np(3)Konstantin Belousov2026-02-013-0/+98
| | | | (cherry picked from commit 77c5f29453ed3dbb4ba1a372329ab32ec27c998d)
* posix_spawnattr_getexecfd_np.3: add closing .FcKonstantin Belousov2026-02-011-0/+1
| | | | (cherry picked from commit 2a5b083c1f7e0a4518bd944241af1d1102997c4d)
* libc: add posix_spawnattr_{get,set}procdescp_npKonstantin Belousov2026-02-012-5/+51
| | | | (cherry picked from commit 080d8ed7dd29ba537ce4cca286ed3369aca61ef5)
* libc: document posix_spawnattr_getexecfd_np(3)Konstantin Belousov2026-02-013-0/+90
| | | | (cherry picked from commit 58580dc0c694b107ba7ba1b14dc8ee8f306e53f6)
* libc: add posix_spawnattr_{get,set}execfd_np(3)Konstantin Belousov2026-02-012-1/+26
| | | | (cherry picked from commit 3f0aea09689f6c10740de78011469355208a19a5)
* Regen for the fork and exit/wait exterror category additionKonstantin Belousov2026-02-011-0/+2
|
* lib/libsys, lib/libc: export pdwaitKonstantin Belousov2026-02-013-0/+25
| | | | (cherry picked from commit 2d555ec85a716e016be587b2a1606ca69267f870)
* libc: drop NO_FP_LIBC supportXin LI2026-01-3110-75/+0
| | | | | | | | | | | | NO_FP_LIBC was added in 2004 to save space by disabling FP support in *printf()/*scanf(). The size benefit is negligible on modern systems and conflicts with assumptions made by current base utilities. Remove the option and always build libc with floating-point support. Reported by: Oskar Holmlund <eovholmlund at gmail com> (cherry picked from commit 8e6843db9bc5af14b0ee631081ecaf1f02ce821a)
* libc: Don't use uninitialised string for getnetbyaddr[_r](0) DNS lookupJessica Clarke2026-01-301-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | If net is all-zero, the loop to extract all leading non-zero octets will iterate zero times and leave nn with the value 4, which the following switch statement to initialise qbuf does not handle. As a result, _dns_getnetbyaddr will look up the PTR record for this uninitialised string, which will leak the pre-existing contents of that stack memory to the DNS resolver and, if remote and not otherwise protected, network. Note that _dns_getnetbyaddr is only used if nsswitch.conf is configured to enable the "dns" source for the "networks" database, which is not the default configuration in FreeBSD. For glibc this same bug, in code also derived from BIND's, was issued CVE-2026-0915. This commit adopts the same behaviour as glibc's fix, which is to regard a net of 0 as being for 0.0.0.0. Apparently NetBSD will return NS_UNAVAIL instead, which may or may not make more sense, but in general glibc compatibility tends to cause less friction when there's not a good reason to avoid it. Reviewed by: markj (secteam) Fixes: 1363f04ce1b8 ("get* rework and new bind code") MFC after: 1 day Security: Same bug as glibc's CVE-2026-0915 (cherry picked from commit 331316b073505e4794754af1cd0c5ccc578a2bde)
* exterr: Regenerate exterr_cat_filenames.hMark Johnston2026-01-261-1/+1
|
* libc: report _SC_NPROCESSORS_ONLN more accurately in cpu-limited jailsKyle Evans2026-01-203-6/+156
| | | | | | | | | | | | | | | | | | | | | | We don't support CPU hotplug, but we do support cpuset(8) restrictions on jails (including prison0, which uses cpuset 1). The process cannot widen its cpuset beyond its root set, so it makes sense to instead report the number of cpus enabled there rather than the total number in the system. This change is effectively a nop for the majority of systems and jails in the wild, though it does reduce the performance of this query now that we can't take advantage of AT_NCPUS being provided in the auxinfo. The implementation here is notably different than Linux, which would not take cgroups into account. They do, however, take CPU hotplug into account, so the possibility for it to diverge from (and be lower than) the # configured count to reflect what the process can actually be scheduled on doesn't really diverge in semantics. Reviewed by: kib (cherry picked from commit d617806aac1469319970e3551656e9deabb98a35)
* libc: fix description issues in mac_text(3)/mac_free(3)Kyle Evans2026-01-202-5/+7
| | | | | | | | | | | | | mac_text(3) as-written would seem to indicate that a `mac_t` should be freed with free(3), but this isn't the case. One can derive from context from when the change was introduced and COMPATIBILITY that this was intended to talk about *text in `mac_to_text`, so move the comment there. PR: 179832 Co-authored-by: Priit Järv <priit cc ttu ee> (cherry picked from commit 081218b7a2006e5b6783e51f66fd751871ac1272)
* tdestroy(3): add testsKonstantin Belousov2026-01-051-0/+65
| | | | (cherry picked from commit 3204c097fd08436805f059c0d7f676d29ee9bb62)
* tdestroy(3) man pageKonstantin Belousov2026-01-052-3/+25
| | | | (cherry picked from commit b0d4b059cf8425cbe094f93362a61c56a26d45f3)
* libc: add glibc-compatible tdestroy(3)Konstantin Belousov2026-01-053-0/+70
| | | | (cherry picked from commit b8c99e7d912f0dad84cec80f8c4331646b87a3ec)
* libc/stdlib/Makefile: one line for each source file nameKonstantin Belousov2026-01-051-13/+69
| | | | (cherry picked from commit 04a664d87607d25d87baf56903090707cc91e2e0)
* man pages: provide some description for extended errorsKonstantin Belousov2026-01-051-0/+16
| | | | (cherry picked from commit 3088263177da2813dd09364171feadd0e31d1fc3)
* exterr: in verbose mode, print the source file nameKonstantin Belousov2026-01-051-4/+17
| | | | (cherry picked from commit 874cdf6af695c42d561647f7165c99c2d3df0faa)
* Add automatically generated file libc/gen/exterr_cat_filenames.hKonstantin Belousov2026-01-051-0/+17
| | | | (cherry picked from commit 5685c07b5a8e4ccc19140eeaa5987a38dca7c668)