Guillem Jover [Fri, 19 Feb 2021 05:55:17 +0000 (06:55 +0100)]
build: Add compiler warnings support
Detect as many warnings as possible during configure and enable them
if the user did not supply any, so that any such problem can be spotted
and fixed.
Guillem Jover [Tue, 9 Feb 2021 04:57:37 +0000 (05:57 +0100)]
Switch libmd wrapper to use dlsym()
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.
Guillem Jover [Tue, 9 Feb 2021 05:04:38 +0000 (06:04 +0100)]
build: Use a single variable to track libraries to link against
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.
Guillem Jover [Sat, 6 Feb 2021 23:09:30 +0000 (00:09 +0100)]
Use libmd hashing function implementations instead of embedding our own
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.
[guillem@hadrons.org:
- Remove .exe extension from default program name.
- Call reallocarray() once by switching to a «do {} while» loop.
- Minor coding style fixes. ]
Faidon Liambotis [Thu, 31 Dec 2020 10:46:03 +0000 (12:46 +0200)]
Add recallocarray() and freezero() from OpenBSD
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. ]
Even though man-pages project now includes man pages for system data
types, we still include these for any other system that does not have
them, to provide a self-contained project with code and documentation.
Guillem Jover [Tue, 6 Aug 2019 13:49:41 +0000 (15:49 +0200)]
err: Add err(), warn(), errx() and warnx() familiy of functions
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.
Guillem Jover [Tue, 6 Aug 2019 13:37:43 +0000 (15:37 +0200)]
err: Rewrite warnc() and errc() family functions to be standalone
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.
James Clarke [Sun, 3 Feb 2019 00:11:15 +0000 (00:11 +0000)]
Re-allow direct use of nlist.n_name in <nlist.h>
Commit e8d340de ("Remove a.out support from nlist()") introduced a copy
of the definition of nlist from a.out.h. However, as well as having
n_name inside n_un, on the various BSDs n_name could also be accessed
as a direct member of nlist, and this is made use of by FreeBSD's
usr.bin/netstat/main.c. Thus we should also add the same enclosing
anonymous union.
[guillem@hadrons.org:
- Add a minimal unit test. ]
Guillem Jover [Wed, 7 Aug 2019 20:58:30 +0000 (22:58 +0200)]
nlist: Fix out-of-bounds read on strtab
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.
Guillem Jover [Sat, 15 Jun 2019 12:33:32 +0000 (14:33 +0200)]
nlist: Fix unbounded malloc() calls
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>
Guillem Jover [Sat, 15 Jun 2019 12:33:32 +0000 (14:33 +0200)]
nlist: Fix pread() return value check
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>
Guillem Jover [Sat, 15 Jun 2019 12:33:32 +0000 (14:33 +0200)]
nlist: Check that e_shnum and e_shentsize are within bounds
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>
Guillem Jover [Thu, 13 Jun 2019 21:36:09 +0000 (23:36 +0200)]
man: Add doc-str-Lb-libbsd aliases for str-Lb-libbsd
groff(1) has changed the internal layout for the .Lb doc strings, but to
preserve backwards compatibility we cannot simply rename them, we need
to create new aliases so that these will work with old and new macros.
Aaron Dierking [Thu, 14 Jun 2018 18:38:32 +0000 (11:38 -0700)]
build: Detect Windows/MinGW at configure time
Extend the host OS checks to define an OS_WINDOWS automake conditional if
the host is MinGW-like. This will be useful for future Windows-specific
build tweaks.
[guillem@hadrons.org:
- Rename WINDOWS conditional to OS_WINDOWS. ]
Guillem Jover [Tue, 6 Aug 2019 17:14:29 +0000 (19:14 +0200)]
build: Support platforms without symbol versioning
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.
Guillem Jover [Tue, 6 Aug 2019 21:16:42 +0000 (23:16 +0200)]
build: Use __register_atfork() only if really available
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].
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.
Aaron Dierking [Thu, 14 Jun 2018 18:38:31 +0000 (11:38 -0700)]
Correct Clang feature detection
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. ]
Guillem Jover [Wed, 6 Jun 2018 03:41:34 +0000 (05:41 +0200)]
Fix vis family of functions to not leak
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.
Guillem Jover [Thu, 31 May 2018 01:34:07 +0000 (03:34 +0200)]
build: Fix gitlab CI configuration
Run «apt install» in non-interactive mode, and do not install
Recommends. Replace build-essential, which is rather fat, with gcc
and make. Execute autogen instead of autoreconf directly.
Guillem Jover [Tue, 22 May 2018 11:50:44 +0000 (13:50 +0200)]
Fix strnvis() and strnunvis() NetBSD ABI break
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.
Guillem Jover [Mon, 21 May 2018 20:41:23 +0000 (22:41 +0200)]
Fix COPYING file format
We cannot refer to a License short-name if that is not on its own
License paragraph. Split several other common License fields into
their own paragraphs to avoid this problem in the future.