Commit Graph

489 Commits

Author SHA1 Message Date
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
Guillem Jover
99320b9168 man: Define doc-operating-system-NetBSD string variables
This way we do not depend on the installed groff being new enough.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00
Guillem Jover
71c710e9a8 man: Use major.minor version for .Nx macros
The macro only recognizes this version form, and not just major alone.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00
Guillem Jover
21f4052c5b 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.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00
Guillem Jover
1899e2c5ab Update TODO
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00
Aaron Dierking
4803340802 Provide a <sys/param.h> with MIN() and MAX()
Windows doesn't provide <sys/param.h>. Several libbsd sources require it
for MIN(), and these are useful non-system-specific macros anyway.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00
Aaron Dierking
f99b8ea527 build: Disable CRT warnings on Windows
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-08 03:22:09 +02:00
Aaron Dierking
4bed48398f 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. ]

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00
Guillem Jover
2e071c3cc1 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.

Based-on-patch-by: Aaron Dierking <aarond@fb.com>
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00
Guillem Jover
890699a78b build: Abstract symbol versioning via new libbsd_symver_* macros
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-08 03:22:09 +02:00
Guillem Jover
b0ebb0d4c2 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].

 [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>
2019-08-08 03:21:49 +02:00
Guillem Jover
73aea4f808 build: Fix check for clock_gettime() within librt
The check was always setting the libraries to link to include -lrt,
as the success case includes the builtin one. Handle the various
values.
2019-08-07 00:03:25 +02:00
Aaron Dierking
7cfa2d4530 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. ]

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-06-18 04:31:00 +02:00
Guillem Jover
574c7a1365 Protect C language extensions with two leading and trailing underscores
This should make their usage safer against user macros.
2018-06-18 04:31:00 +02:00
Aaron Dierking
c2d9d84088 Guard non-portable forwarded includes
These headers are not available on Windows. <bsd/sys/cdefs.h> ensures
that __has_include() and __has_include_next() are defined.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-06-18 04:31:00 +02:00
Aaron Dierking
2ebe6d5a02 Windows support for inet_net_pton()
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-06-18 04:31:00 +02:00
Aaron Dierking
aeea1f4083 Windows support for HASHFileChunk()
<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-18 04:31:00 +02:00
Aaron Dierking
0500a1bd08 Don't require <grp.h>
This is only used in the overlay test and Windows does not provide it.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-06-18 04:31:00 +02:00
Aaron Dierking
3d9c6c08ed Only define S_ISTXT if S_ISVTX is defined
Windows doesn't provide S_ISVTX. Prefer not defining it rather than
defining it to something invalid.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-06-18 04:31:00 +02:00
Aaron Dierking
b9dee9f69a Use CHAR_BIT instead of NBBY in strnvis()
<sys/param.h> is not available on Windows.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-06-18 04:31:00 +02:00
Aaron Dierking
81c3c3e405 Replace reintroduced legacy u_* type usage in strnvis() and strnunvis()
This fixes a regression caused by 2d7de18. These types are not available
on all systems.

Fixes: commit 2d7de186e9
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-06-18 04:28:45 +02:00
Guillem Jover
5e0998fa4f Remove dead code in vis
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-17 23:01:02 +02:00
Guillem Jover
8e2d55047c 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.

Warned-by: coverity
2018-06-17 23:00:52 +02:00
Baruch Siach
13c32916b4 flopen: Add missing <fcntl.h> include
Commit 993828d84e (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 993828d84e
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-06-17 20:23:48 +02:00
Guillem Jover
8e834cd068 build: Simplify gitlab CI configuration
Merge all stages so that we do not need to pass artifacts around.
Quiesce «apt install».
2018-05-31 04:00:26 +02:00
Guillem Jover
e354f9b1d0 build: Install git in gitlab CI configuration 2018-05-31 03:46:14 +02:00
Guillem Jover
4c5e9b478e 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.
2018-05-31 03:42:33 +02:00
Guillem Jover
005b509061 build: Add a gitlab CI configuration file 2018-05-31 03:23:16 +02:00
Jakub Wilk
a8531ad051 man: Fix comma splice
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-05-23 02:58:09 +02:00
Jakub Wilk
c4b0fd2c9f man: Fix name of the function injected by libbsd-ctor
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-05-23 02:58:09 +02:00
Guillem Jover
1ca09c18f7 Release libbsd 0.9.1 2018-05-22 16:07:42 +02:00
Guillem Jover
e4e15ed286 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.

Ref: http://gnats.netbsd.org/44977
Fixes: https://bugs.debian.org/899282
2018-05-22 16:07:42 +02:00
Guillem Jover
bf697b900c Add symbol redirection support
We need this to be able to select different version symbols at
compile-time.
2018-05-22 15:45:37 +02:00
Guillem Jover
f1966385b3 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.
2018-05-22 13:47:05 +02:00
Guillem Jover
e007233cf0 Release libbsd 0.9.0 2018-05-21 04:48:32 +02:00
Guillem Jover
3cabf46bb0 Deprecate fgetwln()
This function has the same problems as fgetln() which is already marked
as deprecated.
2018-05-21 04:48:32 +02:00
Guillem Jover
6eebc1f264 Fix typo in fgetln() linker warning 2018-05-21 04:48:32 +02:00
Guillem Jover
a1730c1063 Add Windows support for getentropy() and arc4random()
Import from OpenBSD.
2018-05-21 04:48:32 +02:00