summaryrefslogtreecommitdiff
path: root/src
AgeCommit message (Collapse)AuthorFilesLines
2021-02-28nlist: Remove repeated shadowing variable declarationHEADmasterGuillem Jover1-1/+0
Warned-by: gcc
2021-02-28getentropy: Fix function cast for getauxval()Guillem Jover1-3/+3
Warned-by: gcc
2021-02-28Mark local functions as staticGuillem Jover1-1/+1
Warned-by: gcc
2021-02-28Add link-time warnings to MD5 wrapper functionsGuillem Jover1-0/+19
Let's get the word out that these functions are deprecated and should be switched away from.
2021-02-28Require a semicolon for libbsd_link_warning() macroGuillem Jover3-3/+3
Remove the semicolon in the macro definition to force adding one on the call sites, to make the code look like an actual function.
2021-02-09build: Add a Libs.private field to overlay pkg-config fileGuillem Jover1-0/+1
We need to list all internal libraries there so that we can statically link. Fixes: commit 2374f409defb380d0c5c07f28b9c166ef8bdc742
2021-02-09Switch libmd wrapper to use dlsym()Guillem Jover1-27/+59
Switch from the previous versioned symbol implementation which required users to also link against the message digest provider explicitly, or they would fail to find the symbols, to an implementation that loads the symbols from the linked library providing the functions using dlsym(), thus preserving backwards compatibility.
2021-02-09build: Add a Libs.private field to pkg-config fileGuillem Jover1-0/+1
We need to list all internal libraries there so that we can statically link.
2021-02-09build: Use a single variable to track libraries to link againstGuillem Jover1-3/+1
Using various variables means we have to keep these in sync in various places. Just use a single variable that we can use anywhere where this is needed.
2021-02-08closefrom: Use close_range() on Linux when availableGuillem Jover1-1/+20
Closes: !11 Based-on-patch-by: cptpcrd <cptpcrd.git@gmail.com> Signed-off-by: Guillem Jover <guillem@hadrons.org>
2021-02-08closefrom: Handle lowfd < 0 properlycptpcrd1-0/+3
More important if close_range() is going to be used, since casting negative values to 'unsigned int' might hide the errors. [guillem@hadrons.org: Minor coding style fix. ] Signed-off-by: Guillem Jover <guillem@hadrons.org>
2021-02-08closefrom: Import some changes from sudoGuillem Jover1-44/+49
Take most of the changes done in sudo, but preserve the existing local changes and refactoring. In addition, refactor pstat implementation into closefrom_pstat(), so that the code is easier to read, and requires no conditional declarations.
2021-02-07Update copyright claimsGuillem Jover1-1/+1
2021-02-07Use libmd hashing function implementations instead of embedding our ownGuillem Jover14-763/+120
This splits the implementation responsibilities, and reduces embedded code copies, which was one of the driving points with this project to start with, so it's nice to give a good example.
2021-02-07Provide a default progname on WindowsAaron Dierking1-1/+71
[guillem@hadrons.org: - Remove .exe extension from default program name. - Call reallocarray() once by switching to a «do {} while» loop. - Minor coding style fixes. ] Signed-off-by: Guillem Jover <guillem@hadrons.org>
2021-02-07Import pwcache module from OpenBSDGuillem Jover3-0/+443
2021-01-01Add recallocarray() and freezero() from OpenBSDFaidon Liambotis4-0/+115
Add recallocarray(), introduced in OpenBSD 6.1, and freezero(), introduced in OpenBSD 6.2. The former is imported as-is from OpenBSD, while the latter is the non-malloc-internal branch of the same code (and also the OpenSSH portable variant). Both of these originated in OpenBSD, but have also been implemented by IllumOS, cf. https://www.illumos.org/issues/8546 Documentation for these functions is in malloc(3) upstream, the relevant parts of which were previously imported in reallocarray(3bsd). Update reallocarray(3bsd) with the changes that were introduced since, and add the relevant bits for recallocarray() and freezero(), plus aliases. [guillem@hadrons.org: Update copyright in COPYING. ] Closes: !10 Signed-off-by: Guillem Jover <guillem@hadrons.org>
2021-01-01Fix ELF detection on Intel compilersSeth R Johnson1-1/+1
The Intel compiler does not define __amd64__ on x86_64 platforms; instead, like other compilers, it defines __x86_64__ . Closes: !8 Signed-off-by: Guillem Jover <guillem@hadrons.org>
2020-12-21funopen: Fix memory leak in funopen_close() when closefn is NULLGuillem Jover1-4/+4
We need to free the cookiewrap even when the closefn method is NULL. Warned-by: gcc ASAN
2020-12-21build: Detect support for --version-script in ldGuillem Jover1-1/+4
2020-12-21Do not define SIZE_T_MAX if already definedGuillem Jover1-0/+2
2020-12-21Add missing strnvisx() to the symbols scriptGuillem Jover1-0/+4
Fixes: commit 2d7de186e9cb19a756c0630ee85cb3f2d29b3484.
2019-08-08err: Add err(), warn(), errx() and warnx() familiy of functionsGuillem Jover2-0/+89
Some systems such as Windows or musl-libc based ones do not have these BSD extensions. In addition libbsd itself is making use of the warnx() functions, so we better provide these interfaces in case they are missing.
2019-08-08err: Rewrite warnc() and errc() family functions to be standaloneGuillem Jover1-15/+23
Do not depend on the system vwarn() and verr() functions to implement the *c() variants, as the system might actually lack any of the <err.h> BSD extensions.
2019-08-08Add e2k support for nlist()Michael Shigorin1-0/+6
This is a Russian 64-bit LE VLIW architecture named Elbrus (formerly Elbrus 2000). [guillem@hadrons.org: - Place the entry in alphabetical order. ] Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08Add AArch64 ILP32 support to nlist()Frank Schaefer1-0/+4
Closes: !7 Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08Add ARC support to nlist()Rosen Penev1-0/+6
Closes: !6 Signed-off-by: Rosen Penev <rosenp@gmail.com> Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08Add a comment to note the ELF entries are sorted alphabeticallyGuillem Jover1-0/+2
This should help people wanting to add new entries.
2019-08-08nlist: Fix out-of-bounds read on strtabGuillem Jover1-2/+4
When doing a string comparison for a symbol name from the string table, we should make sure we do a bounded comparison, otherwise a non-NUL terminated string might make the code read out-of-bounds. Warned-by: coverity
2019-08-08nlist: Fix unbounded malloc() callsGuillem Jover1-2/+2
There are a couple of malloc() calls with unbounded size arguments, coming from the parsed file. We need to make sure the size is not larger than the file being parsed, otherwise we might end up with out of memory conditions. Reported-by: Daniel Hodson <daniel@elttam.com.au> Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08nlist: Fix pread() return value checkGuillem Jover1-2/+2
We should check for partial reads, and not continue in those cases, as we are not retrying them, otherwise we might end up operating on uninitialized data. Reported-by: Daniel Hodson <daniel@elttam.com.au> Based-on-patch-by: Daniel Hodson <daniel@elttam.com.au> Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08nlist: Check whether sh_link is within boundsGuillem Jover1-0/+3
The sh_link members should be >= e_shnum, otherwise we might do out of bounds read accesses on the shdr array. Reported-by: Daniel Hodson <daniel@elttam.com.au> Based-on-patch-by: Daniel Hodson <daniel@elttam.com.au> Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08nlist: Check that e_shnum and e_shentsize are within boundsGuillem Jover1-0/+6
The e_shnum must not be 0, otherwise we will do a zero sized allocation and further processing of the executable will lead to out of bounds read/write accesses. The e_shentsize must be equal to sizeof(Elf_Shdr), otherwise we will perform out of bounds read accesses on the shdr array. Reported-by: Daniel Hodson <daniel@elttam.com.au> Based-on-patch-by: Daniel Hodson <daniel@elttam.com.au> Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08nlist: Check whether the nl argument is not NULLGuillem Jover1-0/+4
This prevents programming errors. Reported-by: Daniel Hodson <daniel@elttam.com.au> Based-on-patch-by: Daniel Hodson <daniel@elttam.com.au> Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08build: Disable CRT warnings on WindowsAaron Dierking1-0/+7
These warnings are not helpful for libbsd. [guillem@hadrons.org: - Rename WINDOWS conditional to OS_WINDOWS. - Add a nil terminator to the AM_CPPFLAGS. ] Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08build: Support platforms without symbol versioningGuillem Jover1-0/+7
The .symver directive is ELF-specific. On non-ELF platforms, work around this with __attribute__((__alias__)) for the default symbol, and ignore the variant versioned symbols. Based-on-patch-by: Aaron Dierking <aarond@fb.com> Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08build: Abstract symbol versioning via new libbsd_symver_* macrosGuillem Jover4-6/+18
This makes it more obvious what they are doing. It will make it easier to make these directives more portable, as they are really ELF specific.
2019-08-08build: Use __register_atfork() only if really availableGuillem Jover3-3/+5
This is a glibc-specific symbol that has no public declaration. But is being used by the OpenBSD and this implementation as a hack to avoid having to link against the pthread library. This interface is at least included in LSB 5.0 [L], and using pthread_atfork() is otherwise problematic anyway [P]. [L] <https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/baselib---register-atfork.html> [P] <http://austingroupbugs.net/view.php?id=851> One problem is that we were using it whenever __GLIBC__ is defined, which is supposed to be defined only on an actual glibc, but uClibc defines that macro, but it does not provide the symbol on its noMMU variant. We add a new configure check that will try to link a program that uses that symbol to make sure it is present. Closes: !2 Reported-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2018-06-18Correct Clang feature detectionAaron Dierking1-3/+3
Clang's __GNUC__ and __GNUC_MINOR__ definitions are not reliable and may not be defined at all when targeting the MSVC ABI. Use feature-checking macros when possible or check for __clang__. [guillem@hadrons.org: Update for __ protected keyword change. ] Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-06-18Protect C language extensions with two leading and trailing underscoresGuillem Jover4-6/+9
This should make their usage safer against user macros.
2018-06-18Windows support for inet_net_pton()Aaron Dierking1-0/+5
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-06-18Windows support for HASHFileChunk()Aaron Dierking1-0/+3
<io.h> provides the necessary file I/O functions. [guillem@hadrons.org: Move include before <hashinc>. ] Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-06-18Use CHAR_BIT instead of NBBY in strnvis()Aaron Dierking1-3/+2
<sys/param.h> is not available on Windows. Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-06-18Replace reintroduced legacy u_* type usage in strnvis() and strnunvis()Aaron Dierking2-7/+11
This fixes a regression caused by 2d7de18. These types are not available on all systems. Fixes: commit 2d7de186e9cb19a756c0630ee85cb3f2d29b3484 Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-06-17Remove dead code in visGuillem Jover1-1/+1
The loop only executes while len > 0, and the trinary operator in the function argument is checking against len >= 1 which will always be true. Warned-by: coverity
2018-06-17Fix vis family of functions to not leakGuillem Jover1-14/+25
The code uses an internal helper function to avoid code repetition. But to get there, the function takes a pointer to a pointer, so that the few functions that require returning an allocated buffer can get hold of it this way. The problem is that the user might pass a NULL pointer and trigger an internal allocation even if the functions are not expected to do so. Add a new internal helper for non-allocations, that will assert that condition, and make any other function that requires this behavior call this one instead. Warned-by: coverity
2018-06-17flopen: Add missing <fcntl.h> includeBaruch Siach1-0/+1
Commit 993828d84ee (Add flopenat() function from FreeBSD) dropped the fcntl.h header. This breaks the build with musl libc: flopen.c: In function ‘vflopenat’: flopen.c:60:14: error: ‘O_CREAT’ undeclared (first use in this function) if (flags & O_CREAT) { ^~~~~~~ Restore the fcntl.h header include to fix the build. Fixes: commit 993828d84eed0468c6c15b2818e534e6b134b8e4 Submitted-also-by: parazyd <parazyd@dyne.org> Signed-off-by: Baruch Siach <baruch@tkos.co.il> Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-05-22Fix strnvis() and strnunvis() NetBSD ABI breakGuillem Jover3-2/+60
The NetBSD implementations have different prototypes to the ones coming from OpenBSD, which will break builds, and have caused segfaults at run-time. We provide now both interfaces with different prototypes as different version nodes allow selecting them at compile-time, defaulting for now to the OpenBSD one to avoid build-time breakage, while emitting a compile-time warning. Later on, in 0.10.0, we will be switching the compile-time default to the NetBSD version. Ref: http://gnats.netbsd.org/44977 Fixes: https://bugs.debian.org/899282
2018-05-21Deprecate fgetwln()Guillem Jover1-0/+5
This function has the same problems as fgetln() which is already marked as deprecated.
2018-05-21Fix typo in fgetln() linker warningGuillem Jover1-1/+1