Commit Graph

193 Commits

Author SHA1 Message Date
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
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
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
Guillem Jover
6f68c93076 Switch strtonum() implementation from strtoll() to strtoi()
Import from NetBSD.
2018-05-21 04:48:32 +02:00
Guillem Jover
e13b1a337a Import strtoi() and strtou() functions from NetBSD 2018-05-21 04:47:28 +02:00
Guillem Jover
ef5faeb575 Update few RCS keyword contents to match BSD originals
This will slightly reduce the delta, and makes it easier to compare the
sources.
2018-05-21 04:47:28 +02:00
Guillem Jover
2d7de186e9 Update vis/unvis modules from NetBSD 2018-05-21 04:47:28 +02:00
Guillem Jover
3efad64155 Update readpassphrase() from OpenBSD 2018-05-21 04:47:28 +02:00
Guillem Jover
a6f407ab0d Update heapsort() from OpenBSD 2018-05-21 04:47:28 +02:00
Guillem Jover
21edbb4f22 Update fmtcheck() from NetBSD 2018-05-21 04:47:28 +02:00
Guillem Jover
e3979d1a7c Update humanize_number() from FreeBSD
Implements HN_IEC_PREFIXES.
2018-05-21 04:47:28 +02:00
Guillem Jover
facbddb652 Update pidfile module from FreeBSD
Use EINVAL instead of EDOOFUS. Add a missing synopsis for
pidfile_fileno() in the man page. Move the definition of struct pidfh
from libutil.h into pidfile.c following upstream change.
2018-05-21 04:47:28 +02:00
Guillem Jover
3d88c999b4 Update arc4random() headers from OpenBSD
Split Linux support into its own header separate from the generic Unix
to fix a Linux-specific issue with clone(). Reset rsp to NULL on failure.
2018-05-21 04:47:28 +02:00
Guillem Jover
e42381dc51 Update getentropy() code from OpenBSD
Includes changes to handle the Linux syscall blocking when there is not
enough entropy during boot, by switching it to non-blocking mode and
falling back to the alternative implementations. Man page URL reference
fixes. Build fixes for Mac OS X.

Fixes: https://bugs.debian.org/898088
2018-05-21 04:47:28 +02:00
Guillem Jover
993828d84e Add flopenat() function from FreeBSD 2018-05-21 03:49:26 +02:00
Baruch Siach
f6ed7c278b Fix build for openrisc with uClibc
uClibc defines EM_OR1K instead of EM_OPENRISC for the OpenRISC ELF
e_machine ID. Use EM_OR1K when EM_OPENRISC is not defined.

This fixes the following build failure:

In file included from nlist.c:44:0:
nlist.c: In function ‘__elf_is_okay__’:
local-elf.h:224:23: error: ‘EM_OPENRISC’ undeclared (first use in this function)
 #define ELF_TARG_MACH EM_OPENRISC
                       ^
nlist.c:77:26: note: in expansion of macro ‘ELF_TARG_MACH’
   if (ehdr->e_machine == ELF_TARG_MACH &&
                          ^

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-04-04 02:29:15 +02:00
Guillem Jover
5ba8c5bab0 progname: Port to Windows
Define the directory separator depending on the system targetted.

Reported-by: Progyan Bhattacharya <progyanb@acm.org>
2018-03-06 01:10:14 +01:00
Guillem Jover
0093ca2b0e Handle SPARC V8+ on Sun Studio compiler 2018-03-05 00:02:34 +01:00
James Clarke
0b65d43963 Add support for ELF machine EM_SPARC32PLUS
32-bit SPARC on V8+ uses a different ELF machine type.

Fixes: https://bugs.gentoo.org/634550
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-03-04 23:49:25 +01:00
Guillem Jover
2a8514d8a5 Fix handling of non-contiguous argv + envp in setproctitle()
The two arrays might not reference contiguous memory, and assuming they
are does break at least now on GNU/Hurd, which contains an unmapped
memory block between the memory used by the two arrays.

Just check that each element is strictly after the previous one, so that
we know there are no unmapped memory blocks inbetween.
2017-07-17 00:58:06 +02:00
James Cowgill
b480b7a3f8 Fix ELF definitions for MIPS in local-elf.h
Add a check for _MIPS_SIM inside the __mips__ #elif to detect mips64el
and use ELFCLASS64 in that case. Note that we can't use defined(__mips64)
here because that is also defined when the n32 ABI is in use, which uses
ELFCLASS32.

Fixes: https://bugs.debian.org/865091
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2017-06-24 16:08:22 +02:00
James Cowgill
4cc20e23f5 Fix ELF definitions for PowerPC in local-elf.h
* ppc64el defines both __powerpc__ and __powerpc64__ but since the
  __powerpc64__ #elif is below the __powerpc__ one, it will never be hit.
* Both assumed that powerpc* was big-endian.

Fixes: https://bugs.debian.org/865091
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2017-06-24 16:08:14 +02:00
Guillem Jover
8e8834d8e5 Remove RCSID tags
These are obsolete markers, and in some cases they repeat the
information already present in the comment header.
2017-06-19 03:17:21 +02:00
Guillem Jover
47013bc92a Fix broken mmap() usage in nlist() by switching to pread()
The offset is not page aligned, which makes mmap() return EINVAL on
Linux. Switch to use pread() which handles unaligned offset and non-page
sized reads, and because we are already loading parts of the executable
by read() calls, so there's not much point in using mmap() anyway.
2017-06-19 03:17:21 +02:00
Guillem Jover
e8d340de9e Remove a.out support from nlist()
Some libc libraries do not have an <a.out.h> header. And a.out as an
executable format is very much obsolete on pretty much all currently
supported systems, even if they might still support loading such
objects.

Remove the a.out support to increase portability.
2017-06-19 03:17:21 +02:00
Igor Gnatenko
7aede6a999 Make strlcpy()/strlcat() slightly easier to read
Backport new changes from OpenBSD.

[guillem@hadrons.org:
 - Update copyright years in COPYING. ]

References: https://svnweb.freebsd.org/base?view=revision&revision=281135
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2017-06-19 03:17:21 +02:00
Guillem Jover
07c76b666d Do not use legacy BSD u_* types
Some systems do not have these types available, and they are simply
convenience aliases. Instead use the expanded versions which are more
portable.

Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=101192
2017-06-05 06:18:27 +02:00
Guillem Jover
d6c35f618c Do not provide funopen() on musl
Fixes: https://bugs.debian.org/818246
2017-06-05 05:52:07 +02:00
Guillem Jover
088f147ec8 Add support for RISC-V 2017-06-05 05:31:35 +02:00
Helmut Grohne
b2b1020d8e Add support for TileGX
Fixes: https://bugs.debian.org/847560
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2017-01-16 09:59:20 +01:00
Szabolcs Nagy
cbfe0ebca9 Add missing <fcntl.h> includes
These are required due to the O_* macro usage, but have passed
undetected on glibc-based systems due to implicit inclusions.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2016-03-27 12:42:34 +02:00
Guillem Jover
b7ce33cf51 build: Support clock_gettime() provided in librt
In older glibc versions (< 2.17) clock_gettime() is in librt. Add a
check for this to avoid build breakage for programs/libraries that
use libbsd on such systems.

Based-on-patch-by: Gustavo Zacarias <gustavo@zacarias.com.ar>
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2016-02-13 08:46:47 +01:00
Guillem Jover
ed84bec5aa Switch URLs from http or git to https 2016-02-13 08:46:35 +01:00
Guillem Jover
cbe3057703 Fix file descriptor leak in HASHFileChunk helper
This leak only happens on error conditions, so it's not too bad.

Warned-by: coverity
2016-02-07 09:17:08 +01:00
Guillem Jover
5a32ea0a72 Fix unportable sizeof() usage
We are calculating the size of the array, and need to pass the size of
each element, not the size of a pointer to an element. Although this
happens to be the same in many cases, this is not a portable assumption.

Warned-by: coverity
2016-02-07 09:16:47 +01:00
Hanno Boeck
c8f0723d2b Fix heap buffer overflow in fgetwln()
In the function fgetwln() there's a 4 byte heap overflow.

There is a while loop that has this check to see whether there's still
enough space in the buffer:

		if (!fb->len || wused > fb->len) {

If this is true more memory gets allocated. However this test won't be
true if wused == fb->len, but at that point wused already points out
of the buffer. Some lines later there's a write to the buffer:

		fb->wbuf[wused++] = wc;

This bug was found with the help of address sanitizer.

Warned-by: ASAN
Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=93881
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2016-01-27 15:24:50 +01:00
Guillem Jover
7a75687541 Add support for GNU/Hurd to getentropy()
Reuse the getentropy code for Linux on the Hurd, which has fallbacks
for when the better interfaces are not present. And remove all the code
that is not supported currently on the Hurd. Ideally the Hurd should
get an equivalent interfaces that does not suffer from the same
problems as /dev/urandom.
2015-12-14 03:38:23 +01:00
Guillem Jover
da137a0921 Add missing copyright and license headers 2015-12-07 01:56:25 +01:00
Guillem Jover
d2f59a23d5 Fix getentropy implementation to use the correct system hooks
Include getentropy_<SYSTEM>.c instead of arc4random_<SYSTEM>.c.
2015-12-02 04:03:16 +01:00
Guillem Jover
01b77f0dcf Add support for GNU/kFreeBSD for closefrom() and getentropy() 2015-12-02 03:32:13 +01:00
Guillem Jover
75729394af Unify most arc4random Unix hooks into a single file
The Unix hook should work for most Unix-like systems, move glibc
specific code there and a FreeBSd specific comment, and remove the rest.
Also change the code to always fallback to use the generic Unix code.

This should cover GNU/Hurd and GNU/kFreeBSD among others.
2015-12-02 03:08:17 +01:00
Guillem Jover
8493c7f27d Use local SHA512 header
Actually use the local private SHA512 header instead of relying on the
OpenSSL one for no good reason. Add definition for expected macro
SHA512_DIGEST_LENGTH.
2015-12-01 03:40:57 +01:00
Guillem Jover
874a0e51d3 Update arc4random module from OpenBSD and LibreSSL
Rework arc4random_stir() and arc4random_addrandom() code over the new
internal API, and documentation in the man page. Adapt the code to the
local build system.

Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=85827
2015-11-30 23:48:50 +01:00
Guillem Jover
9a9a8b2dba Add private getentropy module from OpenBSD and LibreSSL
Adapt the code to the local build system.
2015-11-30 23:48:50 +01:00
Guillem Jover
5f9265f816 Add private SHA512 module from FreeBSD 2015-11-30 23:48:50 +01:00
Marek Vasut
1f77cdb40a Add NIOS2 support to nlist()
Add support for the NIOS2 soft-core CPU provided by Altera.

Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Guillem Jover <guillem@hadrons.org>
Cc: Ley Foon Tan <lftan@altera.com>
Cc: Thomas Chou <thomas@wytron.com.tw>
Cc: Walter Goossens <waltergoossens@home.nl>
2015-11-30 23:48:50 +01:00
Guillem Jover
0871daf7b0 build: Move hash/helper.c into new libbsd_la_included_sources
Use this variable in EXTRA_DIST and libbsd_la_DEPENDENCIES.
2015-11-30 04:12:02 +01:00
Guillem Jover
45443583df Add explicit_bzero() function from OpenBSD 2015-09-24 05:47:58 +02:00