summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib
AgeCommit message (Collapse)Author
2021-12-02bsearch(3): support arrays with more than INT_MAX elementsScott Soule Cheloha
The "lim" variable needs to be a size_t to match nmemb, otherwise we get undefined behavior when nmemb exceeds INT_MAX. Prompted by a blog post by Joshua Bloch: https://ai.googleblog.com/2006/06/extra-extra-read-all-about-it-nearly.html Fixed by Chris Torek a long time ago: https://svnweb.freebsd.org/csrg/lib/libc/stdlib/bsearch.c?revision=51742&view=markup ok millert@
2021-10-24For open/openat, if the flags parameter does not contain O_CREAT, theTheo de Raadt
3rd (variadic) mode_t parameter is irrelevant. Many developers in the past have passed mode_t (0, 044, 0644, or such), which might lead future people to copy this broken idiom, and perhaps even believe this parameter has some meaning or implication or application. Delete them all. This comes out of a conversation where tb@ noticed that a strange (but intentional) pledge behaviour is to always knock-out high-bits from mode_t on a number of system calls as a safety factor, and his bewilderment that this appeared to be happening against valid modes (at least visually), but no sorry, they are all irrelevant junk. They could all be 0xdeafbeef. ok millert
2021-10-24ansiJonathan Gray
ok mpi@ deraadt@
2021-10-13Provide realpath(1)Klemens Nanni
A tiny realpath(3) wrapper to make a porter's life easier. Feedback kettenis deraadt cheloha sthen OK cheloha martijn deraadt
2021-09-19Switch two calls from memset() to explicit_bzero()Theo Buehler
This matches the documented behavior more obviously and ensures that these aren't optimized away, although this is unlikely. Discussed with deraadt and otto
2021-09-03* add the missing STANDARDS section as noticed by tb@Ingo Schwarze
* mention that the *optionp input string will be modified * clarify that the array of tokens is expected to be NULL-terminated OK millert@ tb@, and the first half of STANDARDS also OK jmc@
2021-07-23Make MALLOC_STATS compile again; noted by Omar Polo and Joe NelsonOtto Moerbeek
2021-04-09An extra internal consistency check and a missing stats adjustment. ok tb@Otto Moerbeek
2021-04-09Cache implementation has changed, we do not hold on to an exact numberOtto Moerbeek
of pages anymore, but also cache larger regions; ok tb@
2021-03-18Type-cast getpagesize() from int to size_t for the comparison with d.Claudio Jeker
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@
2021-03-09Change the implementation of the malloc cache to keep lists ofOtto Moerbeek
regions of a given size. In snaps for a while, committing since no issues were reported and a wider audience is good. ok deraadt@
2021-02-25- Make use of the fact that we know how the chunks are aligned, andOtto Moerbeek
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
2021-02-12Some people still argue that rand(3) and random(3) have suitable deterministicTheo de Raadt
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
2020-11-23mapalign() only handles allocations >= a page; problem found by and ok semarie@Otto Moerbeek
2020-10-12make fixed-sized fixed-value mib[] arrays be constTheo de Raadt
ok guenther tb millert
2020-10-09As noted by tb@ previous commit only removed an unused fucntion.Otto Moerbeek
So redo previous commit properly: Use random value for canary bytes; ok tb@.
2020-10-06Use random value for canary bytes; ok tb@Otto Moerbeek
2020-09-06For page-sized and larger allocations do not put the pages we'reOtto Moerbeek
shaving off into the cache but unamp them. Pages in the cache get re-used and then a future grow of the first allocation will be hampered. Also make realloc a no-op for small shrinkage. ok deraadt@
2020-05-27This patch fixes one bug and one instance of undesirable behaviour.Ingo Schwarze
The bug, present since 4.4BSD, was that a trailing dash in an option group, when the dash is not permitted as an option letter, resulted in the whole option group being returned as an argument, even though the previous option in the group was already parsed as an option: OPTS=abc ./getopt-test -a- -c arg ===>> OPT(a)ARG(-a-)ARG(-c)ARG(arg). Instead, treat the dash as an invalid option and continue parsing options: ===>> OPT(a)ERR(?-)OPT(c)ARG(arg). The undesirable behaviour was that allowing the dash as an option letter only allowed isolated dashes ("-") and trailing dashes in groups ("-a-"), but neither middle dashes in groups ("-a-b"), even though that already partially worked in 4.4BSD, nor leading dashes in groups ("--a"), even though that works on all other BSDs and on glibc. Also, while POSIX does not require that the dash can be used as an option letter at all, arguably, it encourages that letters either be fully supported or not supported at all. It is dubious whether supporting an option letter in some positions but not in others can be considered conforming. This patch makes OpenBSD behaviour identical to FreeBSD and NetBSD, improves compatibility with glibc (except that glibc does not support isolated "-"), improves compatibility with DragonFly (except that DragonFly is buggy when the dash option letter can take an optional argument but that argument is not present), improves compatibility with Illumos and Solaris 11 (except those do not support "-" and mishandle "--a"), and restores 4.4BSD behaviour for "-a-b". In no respect i'm aware of is compatibility with any other systems reduced. For the full rationale, see my mail to tech@ on 30 Mar 2020 14:26:41 +0200. Part of the problem was originally reported by an anonymous coward on tech@ on 12 Mar 2020 03:40:24 +0200, additional analysis was contributed by martijn@, and then the OP sent the final version of the patch i'm now committing on 17 Mar 2020 19:17:56 +0200. No licensing problem here because after the commit, the file does not contain a single word written by the OP. Also, the OP told me in private mail that he intends to publish the patch under the ISC license already contained in the file and that he wishes to be known by the pseudonym "0xef967c36". OK martijn@, and no objection when shown on tech@, but commit delayed to stay clear of the release.
2020-04-26Minimal maintenance to make this mess slightly less confusing:Ingo Schwarze
queue -> list; mention "intrusive"; element -> member at one place; delete a bogus remark that maybe referred to a long-gone implementation in VAX assembly code. Much more could be improved, but i don't want to waste too much time here.
2020-04-26fix the description; from andras farkasJason McIntyre
ok schwarze kill a Tn while here...
2020-03-30"eventually" came and went back in 2004.Martijn van Duren
OK schwarze@
2020-02-08correct Research Unix edition "appeared in" use in HISTORYJonathan Gray
Starting from "Combined Table of Contents" in Doug McIlroy's "A Research UNIX Reader" a table of which edition manuals appeared in. Checked against manuals from bitsavers/TUHS and source from TUHS where available. Ingo points out there are cases where something is included but not documented until a later release. bcd(6) v6 v7 printf(3) v2 v4 abort(3) v5 v6 system(3) v6 v7 fmod(3) v5 v6 ok schwarze@
2020-01-13Document how to make getopt_long(3) process arguments in order and stopStefan Sperling
at the first non-option argument. I had to read source code to figure it out.
2019-12-20drand48(3) returns values in [0.0, 1.0).Theo Buehler
From j@bitminer.ca with input from Andras Farkas, deraadt, joerg@netbsd "fix however you feel best!" jmc
2019-12-11The file passed to realpath(3) must exists, adjust man page to newAlexander Bluhm
behavior. noticed by hshoexer@; OK beck@
2019-09-14Add comment line saying S is described vaguely on purpose.Otto Moerbeek
Prompted by guenther@
2019-07-05improve verb-tense for explaining the calling convention of __Theo de Raadt
ok guenther jmc
2019-07-05The last consumer of pre-posix realpath behaviour has stoppedTheo de Raadt
requiring it (sftp-server). Remove the /exists///// behaviour from here. The /nonexistant behaviour remains in the kernel and needs to be shot next. There may be ports fallout, but we doubt it. ok beck djm
2019-06-30tweak previous; ok guentherJason McIntyre
2019-06-29Document that getcwd() and realpath() are built on system calls thatPhilip Guenther
have a different calling convention than the standard function...as seen in kdump output. ok deraadt@ schwarze@
2019-06-28When system calls indicate an error they return -1, not some arbitraryTheo de Raadt
value < 0. errno is only updated in this case. Change all (most?) callers of syscalls to follow this better, and let's see if this strictness helps us in the future.
2019-06-27The C89 standard only requires that atexit(3) returns a non-zero valueIngo Schwarze
on error, so checking for -1 only is potentially non-portable. Also mention that the C89 standard does not require errno to be set. OK deraadt@ millert@
2019-06-17Remove old realpath(3), and the userland-vs-kernel realpath verificationTheo de Raadt
code. We now user the simple userland wrapper on top of __realpath(2). The non-POSIX behaviour still remains, that is the next component to fix. From a diff by beck, but I managed to chainsaw it a bit further. Tested in snaps for a couple of days. ok beck
2019-06-15oops - missing .El in previous;Jason McIntyre
2019-06-15realpath(3) doesn't use lstat(2), readlink(2), or getcwd(3) anymore,Theo de Raadt
it is a thin wrapper over the syscall __readlink(2). Improve the list of possible errors. ok millert beck jmc
2019-06-02Complete the ld.so boot cleanup: move most libc initialization fromPhilip Guenther
_csu_finish() to _libc_preinit(), which is an .init_array function in shared libc (and mark it INITFIRST) or a .preinit_array function in static libc, grabbing the _dl_cb callback there from ld.so. Then in _csu_finish(), invoke the dl_clean_boot() callback to free ld.so's startup bits before main() gets control. Other cleanups this permits: - move various startup structures into .data.rel.ro - the dl* stubs in libc can be strong and call the callbacks provided via _dl_cb - no longer need to conditionalize dlctl() calls on presence of _DYNAMIC original concept and full diff ok kettenis@ ok deraadt@
2019-05-30__realpath(2) appears to have improved, so re-enable the code thatTheo de Raadt
checks userland-parsing vs kernel parsing, we are hoping to spot another bug..
2019-05-29There are some bugs in __realpath(2) -- it isn't quite ready so disableTheo de Raadt
calling it until those are fixed.
2019-05-28Enable the use of the kernel __realpath() system call in the libc wrapper.Bob Beck
For now, this also still uses the existing realpath implmentation and emits a syslog if we see differening results. Once we have run with that for a little while we will remove the old code ok deraadt@
2019-05-23Only override size of chunk if we're not given the actual length.Otto Moerbeek
Fixes malloc_conceal...freezero with malloc options C and/or G.
2019-05-19clarify that later flags modify earlier flags;Ingo Schwarze
triggered by a question from Jan Stary <hans at stare dot cz> on misc@; OK otto@
2019-05-15delete two stray blank linesIngo Schwarze
2019-05-13Mention introduction of *_conceal.Otto Moerbeek
2019-05-10Inroduce malloc_conceal() and calloc_conceal(). Similar to theirOtto Moerbeek
counterparts but return memory in pages marked MAP_CONCEAL and on free() freezero() is actually called.
2019-03-20escape backslashes;Ingo Schwarze
patch from Peter Piwowarski <peterjpiwowarski at gmail dot com>
2019-01-25I am retiring my old email address; replace it with my OpenBSD one.Todd C. Miller
2019-01-22sort sections, and add a missing verb to the EXAMPLES text;Jason McIntyre
2019-01-22Wrap long lineOtto Moerbeek
2019-01-21a few tweaksTed Unangst