summaryrefslogtreecommitdiffstats
path: root/lib/libc (follow)
Commit message (Collapse)AuthorAgeFilesLines
* swap rname and mname in debug output, and handle the USE_CD flageric2021-04-021-3/+4
| | | | from Boudewijn Dijkstra
* For the snprintf range check demo, add a (size_t) cast in the right placederaadt2021-04-011-3/+3
| | | | which will satisfy the toughest compiler options
* Type-cast getpagesize() from int to size_t for the comparison with d.claudio2021-03-181-2/+2
| | | | | | | getpagesize() will only return positive numbers (there is no negative page size system) and it can not fail. Should fix some compiler warnings seen in -portable projects. OK otto@
* Early daemons like dhcpleased(8), slaacd(8), unwind(8), resolvd(8)bluhm2021-03-091-4/+6
| | | | | | | | | | | | | are started before syslogd(8). This resulted in ugly sendsyslog(2) dropped logs and the real message was lost. Create a temporary stash for log messages within the kernel. It has a limited size of 100 messages, and each message is truncated to 8192 bytes. When the stash is exhausted, the well-known dropped message is generated with a counter. After syslogd(8) has setup everything, it sends a debug line through libc to flush the kernel stash. Then syslogd receives all messages from the kernel before the usual logs. OK deraadt@ visa@
* Change the implementation of the malloc cache to keep lists ofotto2021-03-091-152/+118
| | | | | regions of a given size. In snaps for a while, committing since no issues were reported and a wider audience is good. ok deraadt@
* document ENOTSUP wxallowed/wxneeded behaviour more clearly; ok kurtderaadt2021-03-021-4/+8
|
* - Make use of the fact that we know how the chunks are aligned, andotto2021-02-252-49/+83
| | | | | | | | | | write 8 bytes at the time by using a uint64_t pointer. For an allocation a max of 4 such uint64_t's are written spread over the allocation. For pages sized and larger, the first page is junked in such a way. - Delayed free of a small chunk checks the corresponiding way. - Pages ending up in the cache are validated upon unmapping or re-use. In snaps for a while
* Some people still argue that rand(3) and random(3) have suitable deterministicderaadt2021-02-122-4/+10
| | | | | | | | | | | use cases, so explain the situation a bit more. Since the 80's, I estimate around 5 algorithm changes, so any chosen seed is unrepeatable UB. +The deterministic sequence algorithm changed a number of times since +original development, is underspecified, and should not be relied upon to +remain consistent between platforms and over time. ok jmc kettenis
* Referece trpt(8) from the SO_DEBUG section of getsockopt(2).bluhm2021-02-041-2/+4
| | | | OK claudio@ visa@
* Adding a hard-trap instruction after the __threxit syscall instructionkurt2021-02-031-2/+1
| | | | broke pthreads on hppa. Reverting. Ok deraadt@
* article fixes; from eddie yousephjmc2021-02-022-6/+6
|
* When checking for available address family for AI_ADDRCONFIG considerflorian2021-01-261-1/+16
| | | | | | | | the routing domain we are currently in. Otherwise we might end up with address families that are not available in the current rdomain but in others since getifaddrs(3) gives us all interface addresses in the system. Clue-bat & OK claudio, input & OK eric, OK kn
* Missing return value; ok jmc@otto2021-01-201-2/+3
|
* Prevent an overflow in inet_net_pton(3) when the passed in buffer isflorian2021-01-191-11/+18
| | | | | | | | | | | | | | | | | too small in the AF_INET6 case. Spotted by Brad House (brad AT brad-house.com) with the c-ares regression test. The man page says Caution: The dst field should be zeroed before calling inet_net_pton() as the function will only fill the number of bytes necessary to encode the network number in network byte order. Which seems to suggest that the function should work if the passed in storage is big enough to hold the prefix, which might be smaller than sizeof(in6_addr). Input & OK tb
* kernel, sysctl(8): remove dead variable: tickadjcheloha2021-01-131-5/+4
| | | | | | | | | | | | | | | | | | | | The global "tickadj" variable is a remnant of the old NTP adjustment code we used in the kernel before the current timecounter subsystem was imported from FreeBSD circa 2004 or 2005. Fifteen years hence it is completely vestigial and we can remove it. We probably should have removed it long ago but I guess it slipped through the cracks. FreeBSD removed it in 2002: https://cgit.freebsd.org/src/commit/?id=e1d970f1811e5e1e9c912c032acdcec6521b2a6d NetBSD and DragonflyBSD can probably remove it, too. We export tickadj via the kern.clockrate sysctl(2), so update sysctl.2 and sysctl(8) accordingly. Hypothetically this change could break someone's sysctl(8) parsing script. I don't think that's very likely. ok mvs@
* Make fts_{alloc,safe_changed}() const correcttb2021-01-081-5/+5
| | | | | | | | | | | Previously, this code was passing string constants to functions that did not declare their parameters as const. After this patch, the functions now declare that they do not modify these arguments, making it safe to pass string constants. Fixes -Wincompatible-pointer-types-discards-qualifiers. From Adam Barth <abarth google com> ok millert
* sleep(3): don't bypass nanosleep(2) if seconds is zerocheloha2021-01-071-4/+1
| | | | | | | | | | | | | | | | | | | | | | sleep(3) does not call nanosleep(2) if seconds is zero. This is bad. As a simplified interface to nanosleep(2), sleep(3) should delegate all decisions about whether or not to yield the CPU to nanosleep(2). This patch removes the nanosleep(2) bypass from sleep(3). This means that this code: sleep(0); will block for up to 1 tick, just like the equivalent nanosleep(2) call. Neither FreeBSD nor NetBSD bypass nanosleep(2) in the zero case, so this commit brings our sleep(3) closer to theirs in behavior. As an added bonus, sleep(3) will now *always* appear in a ktrace(1) as a call to nanosleep(2). ok millert@
* Fix two issues related to thread private data in asr.otto2021-01-064-20/+49
| | | | | | | | - setting up asr in single thread mode and then starting threads using asr would lead to multiple threads sharing the same resolver. - destruction of a thread that has been using asr would leak data. Problem originally reported by Alexey Sokolov and Uli Schlachter. ok kettenis@
* Make consistent reference to pathname.rob2021-01-0310-35/+35
| | | | OK schwarze@, jmc@, deraadt@
* Make CHIN() Boolean-valued and use this to turn an expression with atb2021-01-032-5/+5
| | | | | | quintuple negation into one with a simple negation. From miod, ok millert
* Turn macros into inline functions so that there is no need to document intb2021-01-031-5/+21
| | | | | | comments that they will evaluate their arguments multiple times. From miod, ok millert
* Remove two now-unused functions; a result of the categories removal.millert2021-01-021-39/+2
| | | | From miod@, OK tb@
* More regular error handling with the REQUIRE macro.millert2020-12-311-5/+4
| | | | | | | Changing it from ((condition) || function call) to an if() wrapped in a do/while is easier to read and more stylistically consistent. The seterr() function no longer needs to return a value. From miod@, OK tb@
* Remove unused categories in re_guts; they are written to but never read.millert2020-12-312-45/+3
| | | | From miod@, OK tb@
* Strings in struct parse can be const, they are never modified.millert2020-12-311-15/+11
| | | | | Also, the temporary array in nonnewline() can be made static const. From miod@, OK tb@
* getifaddrs() can return entries where ifa_addr is NULL. Check for thisbenno2020-12-302-4/+7
| | | | | before accessing anything in ifa_addr. ok claudio@
* regcomp.c uses the "start + count < end" idiom to check that there aretb2020-12-301-13/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | "count" bytes available in an array of char "start" and "end" both point to. This is fine, unless "start + count" goes beyond the last element of the array. In this case, pedantic interpretation of the C standard makes the comparison of such a pointer against "end" undefined, and optimizers from hell will happily remove as much code as possible because of this. An example of this occurs in regcomp.c's bothcases(), which defines bracket[3], sets "next" to "bracket" and "end" to "bracket + 2". Then it invokes p_bracket(), which starts with "if (p->next + 5 < p->end)"... Because bothcases() and p_bracket() are static functions in regcomp.c, there is a real risk of miscompilation if aggressive inlining happens. The following diff rewrites the "start + count < end" constructs into "end - start > count". Assuming "end" and "start" are always pointing in the array (such as "bracket[3]" above), "end - start" is well-defined and can be compared without trouble. As a bonus, MORE2() implies MORE() therefore SEETWO() can be simplified a bit. from miod, ok millert
* Constify the strings in regerror.c and make use of the strlcpy()tb2020-12-301-14/+14
| | | | | | return value to avoid a redundant strlen() call. from miod, ok millert
* cclasses[] multis field is always an empty string. Remove it and codetb2020-12-303-88/+16
| | | | | | dealing with it. This code was incomplete anyway. from miod, ok millert
* Constify the strings in cnames[]. No functional change.tb2020-12-302-5/+5
| | | | from miod, ok millert
* Document kern.video.record.mglocker2020-12-291-2/+19
| | | | | | With help/input from jmc@ and kn@. ok jmc@
* Fix an off-by-one error in the marking of the O_CH operator followingmillert2020-12-281-2/+2
| | | | | an OOR2 operator. Also includes a regress test for the issue. From FreeBSD via miod@
* Always call endservent_r() after getservbyport_r().eric2020-12-212-13/+17
| | | | | | Fix a memory leak when no entry is matched. ok florian
* Geode CPU does not support SSE, so MXCSR does not exists there. Asbluhm2020-12-133-9/+3
| | | | | | | | our i386 compiler does not generate SSE instructions by default, it is not strictly necessary to save MXCSR content between setjmp(3) and longjmp(3). We do not want to end supporting such old processors now. Remove the stmxcsr and ldmxcsr instructions from libc. reported by Johan Huldtgren; OK jsg@ kettenis@
* On i386 setjmp(3) should store the FPU state and longjmp(3) restorebluhm2020-12-063-3/+15
| | | | | | it. There is enough space in jmp_buf to save MXCSR and CW register. Idea taken from amd64. This fixes regress/lib/libc/setjmp-fpu . OK kettenis@
* Introduce constants to access the setjmp(3) jmp_buf fields frombluhm2020-12-063-76/+79
| | | | | | | i386 libc. The assembler code is more readable than with magic numbers. This brings i386 in line with amd64. No change in object file. OK kettenis@
* grammar fixes from Varik "The Genuine Article!!!" Valefor;jmc2020-12-031-3/+3
|
* Set type to DB_RECNO in __rec_open() for consistency with other db types.millert2020-12-011-1/+2
| | | | From Boudewijn Dijkstra
* Add retguard to macppc kernel locore.S, ofwreal.S, setjmp.Sgkoehler2020-11-287-24/+24
| | | | | | | | | This changes RETGUARD_SETUP(ffs) to RETGUARD_SETUP(ffs, %r11, %r12) and RETGUARD_CHECK(ffs) to RETGUARD_CHECK(ffs, %r11, %r12) to show that r11 and r12 are in use between setup and check, and to pick registers other than r11 and r12 in some kernel functions. ok mortimer@ deraadt@
* mapalign() only handles allocations >= a page; problem found by and ok semarie@otto2020-11-231-1/+3
|
* Constify dktypenames and fstypenames in libc.guenther2020-11-141-3/+3
| | | | | | Adjust variable declaration in disklabel to match. ok millert@ deraadt@
* remove macro instances from arbitrary string width specifiers. for examplejmc2020-11-141-3/+3
| | | | | | | -width ".Dv BOB" -> -width "BOB" although they are not errors, they are misleading and probably should not get pasted around
* EVFILT_EXCEPT operates on sockets (emil engler)jmc2020-11-141-3/+4
| | | | | | or pseudo terminals (visa); ok mpi visa
* Actually m88k assembler can not handle 'nop' mnemonic, use a macro instead.aoyama2020-11-071-2/+4
| | | | ok deraadt@
* double word fixes;jmc2020-11-051-3/+3
|
* The printf format string component %n is a nearly turning-complete gadget.deraadt2020-10-272-4/+83
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Largely considered attack surface nowadays. The benefit provided by %n is completely overshadowed by the risk. New uses of %n don't seem to be entering the C ecosystem, as static tools flag them. And everyone points fingers at those people.... The list of programs (and libraries) which use %n is therefore finite and shrinking. Most of the %n use comes out of the GNU ecosystem. jca@ has convinced gnulib to fix their code (so we need to wait for software including gnulib to make new releases). A few libraries have moved ahead of us and become more strict. Some n longer permit %n (for instance, andriod bionic). Others log the occurance. Some log and abort if the output location is W|X (MacOS). Our base tree is clean. The ports tree contains a handful during build time, and unknown count (more) during runtime. We would like to abort programs on any occurance of %n. Or we could be like MacOS, aborting for W|X pages (but would need a system call which can check that condition, and that introduces addressspace knowledge we don't want attackers to know, and may be a poor tradeoff). For now, we can syslog, to increase awareness, and involve more people in the greater community to remove %n uses. [If %n is at the end, use the *printf return value. If it occurs in the middle, split the printf calls into multiples] Hopefully one day, we can just abort() when %n happens. Help us get there? ok jca, plus naddy for ports team
* Retguard asm macros for powerpc libc, ld.sogkoehler2020-10-269-64/+87
| | | | | | | | | | Add retguard to some, but not all, asm functions in libc. Edit SYS.h in libc to remove the PREFIX macros and add SYSENTRY (more like aarch64 and powerpc64), so we can insert RETGUARD_SETUP after SYSENTRY. Some .S files in this commit don't get retguard, but do stop using the old prefix macros. Tested by deraadt@, who put this diff in a macppc snap.
* clock_gettime.2: overhaul manpagecheloha2020-10-251-76/+241
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The clock_gettime.2 page is clumsy. It will be easier to use if it is reorganized to emphasize clock_gettime(2), a general and widely used interface, over clock_settime(2), a special-purpose and rarely used interface. While doing that I found a bunch of other things I wanted to tweak or improve: - Simplify the NAME summary. No need to mention "calibration" or "date". - "now", "res", and "clock" are better argument names than "tp" and "clock_id". - The CLOCK_* list is a bunch of fragments. Rewrite the list to make it easier to understand what the clocks represent and how they behave. - Mention clock_settime(2) *after* the list of clocks. Almost nobody needs to use it. It shouldn't lead the page alongside clock_gettime(2). - Drop the adjtime(2) reference. We could mention it in a CAVEATS section but it definitely doesn't belong here in the DESCRIPTION. - Drop the useless init(8) reference. - Add a bunch of EXAMPLES demonstrating how to actually use each clock. - Clean up the ERRORS. - Update the cross references. - Add a HISTORY for the interfaces and each clock. High-level structural ideas from jmc@ and schwarze@. Edited by jmc@. ok jmc@, probably ok schwarze@
* Save and restore the MXCSR register and the FPU control word such thatkettenis2020-10-213-3/+15
| | | | | | floating-point control modes are properly restored by longjmp(3). ok guenther@
* Align the basename(3) and dirname(3) prototypes with the POSIX spec:naddy2020-10-204-10/+10
| | | | | | | Both functions take a non-const parameter. Implementations may modify the passed string, even though ours do not. ok stsp@ deraadt@ millert@