Commit Graph

526 Commits

Author SHA1 Message Date
Guillem Jover
a4e0db2b97 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.
2021-02-09 06:23:38 +01:00
Guillem Jover
43d34c9d3b build: Fix message digest library checks
They were not failing when not finding the SHA-2 functions and
were hardcoding -lmd regardless of what library had been found.
2021-02-09 06:23:38 +01:00
Guillem Jover
1c3ff61699 Use uintptr_t and size_t instead of __-prefixed types in <sys/cdefs.h>
The __-prefixed types cannot be assumed to be defined. Use the standard
types instead.

Closes: #6
2021-02-09 06:23:27 +01:00
Guillem Jover
edea268ce9 Release libbsd 0.11.2 2021-02-08 04:02:46 +01:00
Guillem Jover
e832b7687e closefrom: Use close_range() on Linux when available
Closes: !11
Based-on-patch-by: cptpcrd <cptpcrd.git@gmail.com>
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2021-02-08 04:02:46 +01:00
cptpcrd
c4fca5bb4f closefrom: Handle lowfd < 0 properly
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-08 04:02:46 +01:00
Guillem Jover
a1f79978e8 closefrom: Import some changes from sudo
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-08 04:02:46 +01:00
Faidon Liambotis
4676026286 Update <sys/queue.h> from FreeBSD
This brings <sys/queue.h> to the most up-to-date version from FreeBSD,
incorporating 18 commits from the past 5 years (2015-02-24 - 2021-01-25):

  $ git log --oneline 9090a24aed70..8d55837dc133 sys/sys/queue.h share/man/man3/queue.3

Only minimal changes compared to the FreeBSD version have been applied
(queue.3 -> queue.3bsd, _LIBBSD_ prefix).

[guillem@hadrons.org: Remove reference to kernel mode in man page. ]

Closes: !12
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2021-02-08 04:02:16 +01:00
Guillem Jover
25f9b30678 test: Improve code coverage for strnstr(3) unit tests 2021-02-07 23:24:51 +01:00
Guillem Jover
18ebabf223 man: Update libbsd(7) man page with updates in 0.11.0 2021-02-07 15:17:33 +01:00
Guillem Jover
4ab11c7f48 build: Install libmd-dev in the gitlab CI 2021-02-07 10:37:18 +01:00
Guillem Jover
766c883e30 build: Switch gitlab CI to use a Debian buster 2021-02-07 10:35:57 +01:00
Guillem Jover
a4de4d95a6 Release libbsd 0.11.1 2021-02-07 02:03:59 +01:00
Guillem Jover
233cab9d64 Add support for new LIBBSD_VIS_OPENBSD selection macro
This will make it possible to explicitly select the OpenBSD vis
implementation (the current default) for code of OpenBSD origins.
2021-02-07 02:03:22 +01:00
Guillem Jover
2462cd8888 Release libbsd 0.11.0 2021-02-07 01:28:27 +01:00
Guillem Jover
d54ceb37ce Update copyright claims 2021-02-07 01:28:27 +01:00
Guillem Jover
847e682f8d 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.
2021-02-07 01:28:27 +01:00
Aaron Dierking
68f980c90d Provide a default progname on Windows
[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-07 01:28:27 +01:00
Guillem Jover
37a9b56c05 Import pwcache module from OpenBSD 2021-02-07 01:28:27 +01:00
Guillem Jover
45dd5229ea man: Remove empty line in reallocarray(3bsd)
Warned-by: lintian
Fixes: commit 01f0d1ea1e
2021-02-07 01:28:27 +01:00
Faidon Liambotis
01f0d1ea1e 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. ]

Closes: !10
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2021-01-01 18:18:51 +01:00
Seth R Johnson
9c85d828a1 Fix ELF detection on Intel compilers
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>
2021-01-01 18:12:12 +01:00
Guillem Jover
eac4ce0c67 man: Add a timespec(3bsd) alias to timeval(3bsd)
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.
2020-12-21 17:48:46 +01:00
Guillem Jover
5ecff0c903 man: Add missing LIBRARY section 2020-12-21 17:44:26 +01:00
Guillem Jover
8c5a83d678 Fix coding style 2020-12-21 17:44:26 +01:00
Guillem Jover
d5b04ab19c test: Fix short lived memory leaks
These are non-issues, but having a clean ASAN test suite makes it
possible to detect actual problems in the tested code.

Warned-by: gcc ASAN
2020-12-21 17:44:26 +01:00
Guillem Jover
cfeafeabad funopen: Fix memory leak in funopen_close() when closefn is NULL
We need to free the cookiewrap even when the closefn method is NULL.

Warned-by: gcc ASAN
2020-12-21 17:44:26 +01:00
Guillem Jover
3d6b6ead64 build: Detect support for --version-script in ld 2020-12-21 17:43:11 +01:00
Guillem Jover
eb445425ff Do not define SIZE_T_MAX if already defined 2020-12-21 17:19:30 +01:00
Guillem Jover
59f6a95609 man: Add missing doc-operating-system-NetBSD string variable
Fixes: commit 99320b9168.
2020-12-21 17:19:23 +01:00
Guillem Jover
3548c5f6bf Add missing strnvisx() to the symbols script
Fixes: commit 2d7de186e9.
2020-12-21 17:19:12 +01:00
Guillem Jover
a11c98a6b5 Release libbsd 0.10.0 2019-08-08 17:07:25 +02:00
Guillem Jover
5745ca0362 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.
2019-08-08 03:47:05 +02:00
Guillem Jover
9628798d7d 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.
2019-08-08 03:47:05 +02:00
Guillem Jover
f34a5f71d9 err: Mark error functions as non-returning with __dead2 2019-08-08 03:47:05 +02:00
Michael Shigorin
72c68868c8 Add e2k support for nlist()
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-08 03:47:05 +02:00
Frank Schaefer
a4323f2b16 Add AArch64 ILP32 support to nlist()
Closes: !7
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:47:04 +02:00
Rosen Penev
4997efa59a Add ARC support to nlist()
Closes: !6
Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:47:04 +02:00
Guillem Jover
96202c6c14 Add a comment to note the ELF entries are sorted alphabetically
This should help people wanting to add new entries.
2019-08-08 03:47:04 +02:00
James Clarke
61d378f5e9 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. ]

Closes: !4
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:47:04 +02:00
Guillem Jover
9d917aad37 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.

Warned-by: coverity
2019-08-08 03:22:52 +02:00
Guillem Jover
18662cadfc 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>
2019-08-08 03:22:09 +02:00
Guillem Jover
ce53f7c25f 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>
2019-08-08 03:22:09 +02:00
Guillem Jover
24d1f4dd34 nlist: Check whether sh_link is within bounds
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-08 03:22:09 +02:00
Guillem Jover
e9529d9b4a 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>
2019-08-08 03:22:09 +02:00
Guillem Jover
3aaedb1208 nlist: Check whether the nl argument is not NULL
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-08 03:22:09 +02:00
Guillem Jover
2c754f435b man: Add man page sections to function references
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00
Sebastian
ee4d24970a man: Fix typo
Closes: !5
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00
Guillem Jover
8d2afa3a9f man: Fix typos
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00
Guillem Jover
e9f6faf3aa man: Replace references to a.out(5) with elf(5)
The a.out(5) support in nlist(3) got removed some time ago, and
there is now only elf(5) support.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00