mirror of
https://gitlab.freedesktop.org/libbsd/libbsd.git
synced 2025-10-20 05:49:08 +02:00
Compare commits
29 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
084911ce87 | ||
![]() |
3538d38fe7 | ||
![]() |
03fccd1505 | ||
![]() |
6b6e686b23 | ||
![]() |
da1f45ac71 | ||
![]() |
2f9eddc277 | ||
![]() |
28298ac037 | ||
![]() |
ef981f930b | ||
![]() |
6928d7895e | ||
![]() |
d5865759f8 | ||
![]() |
be327c6ebe | ||
![]() |
a14612d968 | ||
![]() |
f4baceb82c | ||
![]() |
f35c545847 | ||
![]() |
b466b14afb | ||
![]() |
1f6a48b209 | ||
![]() |
873639ebb5 | ||
![]() |
c9c78fdfd0 | ||
![]() |
5f21307570 | ||
![]() |
84acf21568 | ||
![]() |
15200ec7ac | ||
![]() |
f7465b93ec | ||
![]() |
e5ed5fdd62 | ||
![]() |
abb1a6b1a7 | ||
![]() |
c9ff83687c | ||
![]() |
62e67bb49e | ||
![]() |
87b1307040 | ||
![]() |
ba3c46b30f | ||
![]() |
091097e062 |
@@ -1,19 +1,37 @@
|
||||
image: debian:buster
|
||||
.unit-tests:
|
||||
script:
|
||||
- ./autogen && ./configure
|
||||
- make check
|
||||
|
||||
.coverage:
|
||||
script:
|
||||
- ./autogen && ./configure --disable-static
|
||||
- make check CFLAGS="--coverage -O0 -ggdb" LDFLAGS="--coverage -O0 -ggdb"
|
||||
- gcovr -s -e test/
|
||||
|
||||
.debian:
|
||||
image: debian:buster
|
||||
stage: test
|
||||
before_script:
|
||||
- apt-get update -qq
|
||||
- apt-get install -qq -y --no-install-recommends
|
||||
git gcc make autoconf automake libtool libmd-dev gcovr
|
||||
|
||||
unit-tests:
|
||||
.alpine:
|
||||
image: alpine:latest
|
||||
stage: test
|
||||
script:
|
||||
- ./autogen && ./configure
|
||||
- make check
|
||||
before_script:
|
||||
- apk add --no-cache git gcc make autoconf automake libtool
|
||||
bsd-compat-headers linux-headers libmd-dev musl-dev gcovr
|
||||
|
||||
coverage:
|
||||
stage: test
|
||||
script:
|
||||
- ./autogen && ./configure --disable-static
|
||||
- make check CFLAGS="--coverage -O0 -ggdb" LDFLAGS="--coverage -O0 -ggdb"
|
||||
- gcovr -s -e test/
|
||||
unit-tests:debian:
|
||||
extends: [.debian, .unit-tests]
|
||||
|
||||
coverage:debian:
|
||||
extends: [.debian, .coverage]
|
||||
|
||||
unit-tests:alpine:
|
||||
extends: [.alpine, .unit-tests]
|
||||
|
||||
coverage:alpine:
|
||||
extends: [.alpine, .coverage]
|
||||
|
42
COPYING
42
COPYING
@@ -3,7 +3,7 @@ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||
Files:
|
||||
*
|
||||
Copyright:
|
||||
Copyright © 2004-2006, 2008-2021 Guillem Jover <guillem@hadrons.org>
|
||||
Copyright © 2004-2006, 2008-2022 Guillem Jover <guillem@hadrons.org>
|
||||
License: BSD-3-clause
|
||||
|
||||
Files:
|
||||
@@ -37,39 +37,6 @@ License: BSD-4-clause-Niels-Provos
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Files:
|
||||
man/getprogname.3bsd
|
||||
Copyright:
|
||||
Copyright © 2001 Christopher G. Demetriou
|
||||
All rights reserved.
|
||||
License: BSD-4-clause-Christopher-G-Demetriou
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. All advertising materials mentioning features or use of this software
|
||||
must display the following acknowledgement:
|
||||
This product includes software developed for the
|
||||
NetBSD Project. See http://www.netbsd.org/ for
|
||||
information about NetBSD.
|
||||
4. The name of the author may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
.
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Files:
|
||||
include/bsd/err.h
|
||||
include/bsd/stdlib.h
|
||||
@@ -364,7 +331,6 @@ Files:
|
||||
man/strtonum.3bsd
|
||||
src/arc4random.c
|
||||
src/arc4random_linux.h
|
||||
src/arc4random_openbsd.h
|
||||
src/arc4random_uniform.c
|
||||
src/arc4random_unix.h
|
||||
src/arc4random_win.h
|
||||
@@ -383,6 +349,8 @@ Files:
|
||||
src/recallocarray.c
|
||||
src/strlcat.c
|
||||
src/strlcpy.c
|
||||
test/explicit_bzero.c
|
||||
test/strtonum.c
|
||||
Copyright:
|
||||
Copyright © 2004 Ted Unangst and Todd Miller
|
||||
All rights reserved.
|
||||
@@ -391,6 +359,7 @@ Copyright:
|
||||
Copyright © 1998, 2000-2002, 2004-2005, 2007, 2010, 2012-2015
|
||||
Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
Copyright © 2004 Ted Unangst
|
||||
Copyright © 2004 Otto Moerbeek <otto@drijf.net>
|
||||
Copyright © 2008 Damien Miller <djm@openbsd.org>
|
||||
Copyright © 2008, 2010-2011, 2016-2017 Otto Moerbeek <otto@drijf.net>
|
||||
Copyright © 2013 Markus Friedl <markus@openbsd.org>
|
||||
@@ -398,8 +367,9 @@ Copyright:
|
||||
Copyright © 2014 Brent Cook <bcook@openbsd.org>
|
||||
Copyright © 2014 Pawel Jakub Dawidek <pjd@FreeBSD.org>
|
||||
Copyright © 2014 Theo de Raadt <deraadt@openbsd.org>
|
||||
Copyright © 2014 Google Inc.
|
||||
Copyright © 2015 Michael Felt <aixtools@gmail.com>
|
||||
Copyright © 2015 Guillem Jover <guillem@hadrons.org>
|
||||
Copyright © 2015, 2022 Guillem Jover <guillem@hadrons.org>
|
||||
License: ISC
|
||||
Permission to use, copy, modify, and distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
|
5
README
5
README
@@ -9,6 +9,7 @@ A BSD compatible message-digest library is required, on systems where
|
||||
this is not provided by its libc or libmd libraries, the canonical
|
||||
implementation to use is <https://www.hadrons.org/software/libmd/>.
|
||||
|
||||
|
||||
Releases
|
||||
--------
|
||||
|
||||
@@ -30,7 +31,7 @@ The mail address is:
|
||||
Source Repository
|
||||
-----------------
|
||||
|
||||
The master repository can be browsed at:
|
||||
The primary repository can be browsed at:
|
||||
|
||||
<https://cgit.freedesktop.org/libbsd>
|
||||
|
||||
@@ -38,6 +39,7 @@ and cloned from:
|
||||
|
||||
<https://anongit.freedesktop.org/git/libbsd>
|
||||
|
||||
|
||||
Building from git source
|
||||
------------------------
|
||||
|
||||
@@ -55,6 +57,7 @@ the git tree:
|
||||
|
||||
the source should be roughly equivalent to the distributed tar source.
|
||||
|
||||
|
||||
Building from tar source
|
||||
------------------------
|
||||
|
||||
|
@@ -13,7 +13,7 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])],
|
||||
|
||||
LIBBSD_ABI_MAJOR=0
|
||||
LIBBSD_ABI_MINOR=11
|
||||
LIBBSD_ABI_PATCH=5
|
||||
LIBBSD_ABI_PATCH=7
|
||||
|
||||
LIBBSD_ABI="$LIBBSD_ABI_MAJOR:$LIBBSD_ABI_MINOR:$LIBBSD_ABI_PATCH"
|
||||
AC_SUBST([LIBBSD_ABI])
|
||||
|
@@ -51,11 +51,15 @@
|
||||
#include <stdint.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
#if !defined(__GLIBC__) || \
|
||||
!__GLIBC_PREREQ(2, 36) || \
|
||||
!defined(_DEFAULT_SOURCE)
|
||||
uint32_t arc4random(void);
|
||||
void arc4random_stir(void);
|
||||
void arc4random_addrandom(unsigned char *dat, int datlen);
|
||||
void arc4random_buf(void *_buf, size_t n);
|
||||
uint32_t arc4random_uniform(uint32_t upper_bound);
|
||||
#endif
|
||||
void arc4random_stir(void);
|
||||
void arc4random_addrandom(unsigned char *dat, int datlen);
|
||||
|
||||
int dehumanize_number(const char *str, int64_t *size);
|
||||
|
||||
@@ -72,7 +76,9 @@ int sradixsort(const unsigned char **base, int nmemb,
|
||||
|
||||
void *reallocf(void *ptr, size_t size);
|
||||
#if !defined(__GLIBC__) || \
|
||||
(defined(__GLIBC__) && (!__GLIBC_PREREQ(2, 26) || !defined(_GNU_SOURCE)))
|
||||
!__GLIBC_PREREQ(2, 26) || \
|
||||
(__GLIBC_PREREQ(2, 26) && !__GLIBC_PREREQ(2, 29) && !defined(_GNU_SOURCE)) || \
|
||||
(__GLIBC_PREREQ(2, 29) && !defined(_DEFAULT_SOURCE))
|
||||
void *reallocarray(void *ptr, size_t nmemb, size_t size);
|
||||
#endif
|
||||
void *recallocarray(void *ptr, size_t oldnmemb, size_t nmemb, size_t size);
|
||||
|
@@ -47,7 +47,8 @@ char *strnstr(const char *str, const char *find, size_t str_len);
|
||||
void strmode(mode_t mode, char *str);
|
||||
|
||||
#if !defined(__GLIBC__) || \
|
||||
(defined(__GLIBC__) && (!__GLIBC_PREREQ(2, 25) || !defined(_GNU_SOURCE)))
|
||||
!__GLIBC_PREREQ(2, 25) || \
|
||||
!defined(_DEFAULT_SOURCE)
|
||||
void explicit_bzero(void *buf, size_t len);
|
||||
#endif
|
||||
__END_DECLS
|
||||
|
@@ -1,4 +1,4 @@
|
||||
.\" $OpenBSD: arc4random.3,v 1.34 2014/07/19 16:11:16 naddy Exp $
|
||||
.\" $OpenBSD: arc4random.3,v 1.37 2019/09/29 16:30:35 jmc Exp $
|
||||
.\"
|
||||
.\" Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
|
||||
.\" All rights reserved.
|
||||
@@ -30,8 +30,8 @@
|
||||
.\"
|
||||
.\" Manual page, using -mandoc macros
|
||||
.\"
|
||||
.Dd $Mdocdate: July 19 2014 $
|
||||
.Dt ARC4RANDOM 3bsd
|
||||
.Dd $Mdocdate: September 29 2019 $
|
||||
.Dt arc4random 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm arc4random ,
|
||||
@@ -39,7 +39,7 @@
|
||||
.Nm arc4random_uniform ,
|
||||
.Nm arc4random_stir ,
|
||||
.Nm arc4random_addrandom
|
||||
.Nd arc4 random number generator
|
||||
.Nd random number generator
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
|
@@ -31,7 +31,7 @@
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd July 19, 1993
|
||||
.Dt BITSTRING 3bsd
|
||||
.Dt bitstring 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm bit_alloc ,
|
||||
|
@@ -25,7 +25,7 @@
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd April 29, 2002
|
||||
.Dt BYTEORDER 3bsd
|
||||
.Dt byteorder 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm be16enc , be16dec , be32enc , be32dec , be64enc , be64dec ,
|
||||
|
@@ -26,7 +26,7 @@
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd June 12, 2009
|
||||
.Dt CLOSEFROM 3bsd
|
||||
.Dt closefrom 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm closefrom
|
||||
|
@@ -28,7 +28,7 @@
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd $Mdocdate: April 23 2014 $
|
||||
.Dt ERRC 3bsd
|
||||
.Dt errc 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm errc ,
|
||||
|
@@ -26,7 +26,7 @@
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd August 15, 2010
|
||||
.Dt EXPAND_NUMBER 3bsd
|
||||
.Dt expand_number 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm expand_number
|
||||
|
@@ -30,7 +30,7 @@
|
||||
.\" $OpenBSD: bzero.3,v 1.10 2014/01/22 21:06:45 tedu Exp $
|
||||
.\"
|
||||
.Dd $Mdocdate: January 22 2014 $
|
||||
.Dt EXPLICIT_BZERO 3bsd
|
||||
.Dt explicit_bzero 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm explicit_bzero
|
||||
|
@@ -29,7 +29,7 @@
|
||||
.\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/stdio/fgetln.3,v 1.8 2004/07/16 06:07:12 tjr Exp $
|
||||
.\"
|
||||
.Dd April 19, 1994
|
||||
.Dt FGETLN 3bsd
|
||||
.Dt fgetln 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm fgetln
|
||||
|
@@ -29,7 +29,7 @@
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd July 16, 2004
|
||||
.Dt FGETWLN 3bsd
|
||||
.Dt fgetwln 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm fgetwln
|
||||
|
@@ -26,7 +26,7 @@
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd July 28, 2017
|
||||
.Dt FLOPEN 3bsd
|
||||
.Dt flopen 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm flopen ,
|
||||
|
@@ -27,7 +27,7 @@
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd June 14, 2014
|
||||
.Dt FMTCHECK 3bsd
|
||||
.Dt fmtcheck 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm fmtcheck
|
||||
|
@@ -23,7 +23,7 @@
|
||||
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd November 30, 2002
|
||||
.Dt FPARSELN 3bsd
|
||||
.Dt fparseln 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm fparseln
|
||||
|
@@ -32,7 +32,7 @@
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd $Mdocdate: November 4 2015 $
|
||||
.Dt FPURGE 3bsd
|
||||
.Dt fpurge 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm fpurge
|
||||
|
@@ -31,7 +31,7 @@
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd March 19, 2004
|
||||
.Dt FUNOPEN 3bsd
|
||||
.Dt funopen 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm funopen ,
|
||||
|
@@ -29,7 +29,7 @@
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd November 16, 2012
|
||||
.Dt GETBSIZE 3bsd
|
||||
.Dt getbsize 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm getbsize
|
||||
|
@@ -26,7 +26,7 @@
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd July 15, 2001
|
||||
.Dt GETPEEREID 3bsd
|
||||
.Dt getpeereid 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm getpeereid
|
||||
|
@@ -1,6 +1,4 @@
|
||||
.\"
|
||||
.\" Copyright (c) 2001 Christopher G. Demetriou
|
||||
.\" All rights reserved.
|
||||
.\" Copyright (c) 2022 Guillem Jover <guillem@hadrons.org>
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
@@ -10,34 +8,27 @@
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed for the
|
||||
.\" NetBSD Project. See http://www.netbsd.org/ for
|
||||
.\" information about NetBSD.
|
||||
.\" 4. The name of the author may not be used to endorse or promote products
|
||||
.\" 3. The name of the author may not be used to endorse or promote products
|
||||
.\" derived from this software without specific prior written permission.
|
||||
.\" .
|
||||
.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
.\" AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
.\" THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
.\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
.\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
.\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd May 1, 2001
|
||||
.Dt GETPROGNAME 3bsd
|
||||
.Dd August 03, 2022
|
||||
.Dt getprogname 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm getprogname ,
|
||||
.Nm setprogname
|
||||
.Nd get or set the program name
|
||||
.Nd get and set program name
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
@@ -54,46 +45,39 @@ for include usage.)
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn getprogname
|
||||
and
|
||||
.Fn setprogname
|
||||
functions manipulate the name of the current program.
|
||||
They are used by error-reporting routines to produce
|
||||
consistent output.
|
||||
.Pp
|
||||
The
|
||||
.Fn getprogname
|
||||
function returns the name of the program.
|
||||
If the name has not been set yet, it will return
|
||||
.Dv NULL .
|
||||
returns a string with the current program name,
|
||||
excluding any directory component.
|
||||
The function will return
|
||||
.Dv NULL
|
||||
if it was unable to get the program name from any known source.
|
||||
.Pp
|
||||
The
|
||||
.Fn setprogname
|
||||
function sets the name of the program to be the last component of the
|
||||
.Fa progname
|
||||
argument.
|
||||
Since a pointer to the given string is kept as the program name,
|
||||
it should not be modified for the rest of the program's lifetime.
|
||||
function sets the current program name,
|
||||
stripping any directory component prefix.
|
||||
The function will keep a reference to the passed string pointer,
|
||||
so it must not be freed or modified while these functions might
|
||||
be called.
|
||||
.Pp
|
||||
In
|
||||
.Fx ,
|
||||
the name of the program is set by the start-up code that is run before
|
||||
.Fn main ;
|
||||
thus,
|
||||
running
|
||||
.Fn setprogname
|
||||
is not necessary.
|
||||
Programs that desire maximum portability should still call it;
|
||||
on another operating system,
|
||||
these functions may be implemented in a portability library.
|
||||
Calling
|
||||
.Fn setprogname
|
||||
allows the aforementioned library to learn the program name without
|
||||
modifications to the start-up code.
|
||||
The implementations on most BSDs will try to initialize the program name
|
||||
at program startup time, and
|
||||
.Nm libbsd
|
||||
will try to infer it from various known sources depending on the
|
||||
target system.
|
||||
But it is not a portable assumption that the program name will be set
|
||||
without calling
|
||||
.Fn setprogname ,
|
||||
so portable programs should always call it after starting up.
|
||||
.Sh SEE ALSO
|
||||
.Xr err 3 ,
|
||||
.Xr setproctitle 3bsd
|
||||
.Xr setproctitle 3bsd .
|
||||
.Sh HISTORY
|
||||
These functions first appeared in
|
||||
The
|
||||
.Fn setprogname
|
||||
and
|
||||
.Fn getprogname
|
||||
functions first appeared in
|
||||
.Nx 1.6 ,
|
||||
and made their way into
|
||||
.Fx 4.4 .
|
||||
.Fx 4.4 ,
|
||||
.Dx 2.1
|
||||
and
|
||||
.Ox 5.4 .
|
||||
|
@@ -33,7 +33,7 @@
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd September 30, 2003
|
||||
.Dt HEAPSORT 3bsd
|
||||
.Dt heapsort 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm heapsort , mergesort
|
||||
|
@@ -28,7 +28,7 @@
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd February 9, 2008
|
||||
.Dt HUMANIZE_NUMBER 3bsd
|
||||
.Dt humanize_number 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm dehumanize_number ,
|
||||
|
36
man/libbsd.7
36
man/libbsd.7
@@ -1,6 +1,6 @@
|
||||
.\" libbsd man page
|
||||
.\"
|
||||
.\" Copyright © 2017-2021 Guillem Jover <guillem@hadrons.org>
|
||||
.\" Copyright © 2017-2022 Guillem Jover <guillem@hadrons.org>
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
@@ -24,8 +24,8 @@
|
||||
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd Feb 13, 2021
|
||||
.Dt LIBBSD 7
|
||||
.Dd August 3, 2022
|
||||
.Dt libbsd 7
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm libbsd
|
||||
@@ -42,7 +42,7 @@ The library can be used in an overlay mode, which is the preferred way, so
|
||||
that the code is portable and requires no modification to the original BSD
|
||||
code.
|
||||
This can be done easily with the
|
||||
.Xr pkg-config 1
|
||||
.Xr pkgconf 1
|
||||
library named
|
||||
.Pa libbsd-overlay .
|
||||
Or by adding the system-specific include directory with the
|
||||
@@ -59,12 +59,12 @@ The includes in this case should be the usual system ones, such as
|
||||
.In unistd.h .
|
||||
.Pp
|
||||
The other way to use the library is to use the namespaced headers,
|
||||
this is less portable as it makes using
|
||||
which is a discouraged way, being less portable as it makes using
|
||||
.Nm libbsd
|
||||
mandatory and it will not work on BSD-based systems, and requires
|
||||
modifying original BSD code.
|
||||
This can be done with the
|
||||
.Xr pkg-config 1
|
||||
.Xr pkgconf 1
|
||||
library named
|
||||
.Pa libbsd .
|
||||
The includes in this case should be namespaced with
|
||||
@@ -79,7 +79,7 @@ program so that the
|
||||
.Fn setproctitle_init 3
|
||||
function gets invoked automatically at startup time.
|
||||
This can be done with the
|
||||
.Xr pkg-config 1
|
||||
.Xr pkgconf 1
|
||||
library named
|
||||
.Pa libbsd-ctor .
|
||||
.Sh HEADERS
|
||||
@@ -134,7 +134,8 @@ originated from, and these various implementations provided are selectable
|
||||
at build-time.
|
||||
.Pp
|
||||
This is the list of functions that provide multiple implementations:
|
||||
.Bl -tag -width 4m
|
||||
.Pp
|
||||
.Bl -tag -width 4m -compact
|
||||
.It Fn strnvis 3
|
||||
.It Fn strnunvis 3
|
||||
.Nx
|
||||
@@ -230,11 +231,26 @@ companion library, so it is advised to switch to use that directly instead.
|
||||
.It Fn explicit_bzero 3
|
||||
This function is provided by
|
||||
.Nm glibc
|
||||
2.25.
|
||||
2.25, and
|
||||
.Nm musl
|
||||
1.1.20.
|
||||
.It Fn reallocarray 3
|
||||
This function is provided by
|
||||
.Nm glibc
|
||||
2.26.
|
||||
2.26, and
|
||||
.Nm musl
|
||||
1.2.2.
|
||||
.It Fn arc4random 3
|
||||
.It Fn arc4random_buf 3
|
||||
.It Fn arc4random_uniform 3
|
||||
These functions are provided by
|
||||
.Nm glibc
|
||||
2.36.
|
||||
Note that it does not provide the
|
||||
.Fn arc4random_stir 3
|
||||
and
|
||||
.Fn arc4random_addrandom 3
|
||||
functions.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr arc4random 3bsd ,
|
||||
|
@@ -29,7 +29,7 @@
|
||||
.\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/gen/nlist.3,v 1.7 2001/10/01 16:08:51 ru Exp $
|
||||
.\"
|
||||
.Dd April 19, 1994
|
||||
.Dt NLIST 3bsd
|
||||
.Dt nlist 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm nlist
|
||||
|
@@ -25,7 +25,7 @@
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd February 8, 2012
|
||||
.Dt PIDFILE 3bsd
|
||||
.Dt pidfile 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm pidfile_open ,
|
||||
|
@@ -28,7 +28,7 @@
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd $Mdocdate: September 13 2018 $
|
||||
.Dt USER_FROM_UID 3
|
||||
.Dt user_from_uid 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm user_from_uid ,
|
||||
|
@@ -29,7 +29,7 @@
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd September 8, 2016
|
||||
.Dt QUEUE 3bsd
|
||||
.Dt queue 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm SLIST_CLASS_ENTRY ,
|
||||
|
@@ -30,7 +30,7 @@
|
||||
.\" from: @(#)radixsort.3 8.2 (Berkeley) 1/27/94
|
||||
.\"
|
||||
.Dd January 27, 1994
|
||||
.Dt RADIXSORT 3bsd
|
||||
.Dt radixsort 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm radixsort ,
|
||||
|
@@ -19,7 +19,7 @@
|
||||
.\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
|
||||
.\"
|
||||
.Dd $Mdocdate: March 6 2014 $
|
||||
.Dt READPASSPHRASE 3bsd
|
||||
.Dt readpassphrase 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm readpassphrase
|
||||
|
@@ -33,7 +33,7 @@
|
||||
.\" $OpenBSD: malloc.3,v 1.126 2019/09/14 13:16:50 otto Exp $
|
||||
.\"
|
||||
.Dd $Mdocdate: September 14 2019 $
|
||||
.Dt REALLOCARRAY 3bsd
|
||||
.Dt reallocarray 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm reallocarray ,
|
||||
|
@@ -33,7 +33,7 @@
|
||||
.\" $FreeBSD: src/lib/libc/stdlib/malloc.3,v 1.80.2.2.2.1 2010/06/14 02:09:06 kensmith Exp $
|
||||
.\"
|
||||
.Dd September 26, 2009
|
||||
.Dt REALLOCF 3bsd
|
||||
.Dt reallocf 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm reallocf
|
||||
|
@@ -31,7 +31,7 @@
|
||||
.\" $FreeBSD: src/lib/libc/gen/setmode.3,v 1.12 2007/01/09 00:27:55 imp Exp $
|
||||
.\"
|
||||
.Dd January 4, 2009
|
||||
.Dt SETMODE 3bsd
|
||||
.Dt setmode 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm getmode ,
|
||||
|
@@ -21,7 +21,7 @@
|
||||
.\"
|
||||
.\" The following requests are required for all man pages.
|
||||
.Dd December 16, 1995
|
||||
.Dt SETPROCTITLE 3bsd
|
||||
.Dt setproctitle 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm setproctitle
|
||||
@@ -54,7 +54,7 @@ library routine only needs to be called (before any call to
|
||||
and with
|
||||
.Fn main
|
||||
arguments), if the automatic constructor support has not
|
||||
been linked in through the libbsd-ctor pkg-config file.
|
||||
been linked in through the libbsd-ctor pkgconf file.
|
||||
.Pp
|
||||
The title is set from the executable's name, followed by the
|
||||
result of a
|
||||
|
@@ -27,7 +27,7 @@
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd May 6, 2010
|
||||
.Dt STRINGLIST 3bsd
|
||||
.Dt stringlist 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm stringlist ,
|
||||
|
@@ -15,7 +15,7 @@
|
||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
.\"
|
||||
.Dd $Mdocdate: May 31 2007 $
|
||||
.Dt STRLCPY 3bsd
|
||||
.Dt strlcpy 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strlcpy ,
|
||||
|
@@ -29,7 +29,7 @@
|
||||
.\" $FreeBSD: src/lib/libc/string/strmode.3,v 1.9 2003/07/01 15:28:05 maxim Exp $
|
||||
.\"
|
||||
.Dd July 28, 1994
|
||||
.Dt STRMODE 3bsd
|
||||
.Dt strmode 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strmode
|
||||
|
@@ -34,7 +34,7 @@
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd October 11, 2001
|
||||
.Dt STRSTR 3bsd
|
||||
.Dt strstr 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strnstr
|
||||
|
@@ -37,7 +37,7 @@
|
||||
.\" NetBSD: strtol.3,v 1.31 2015/03/11 09:57:35 wiz Exp
|
||||
.\"
|
||||
.Dd November 13, 2015
|
||||
.Dt STRTOI 3bsd
|
||||
.Dt strtoi 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strtoi
|
||||
|
@@ -16,7 +16,7 @@
|
||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
.\"
|
||||
.Dd January 18, 2015
|
||||
.Dt STRTONUM 3bsd
|
||||
.Dt strtonum 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strtonum
|
||||
|
@@ -37,7 +37,7 @@
|
||||
.\" NetBSD: strtoul.3,v 1.29 2015/03/10 13:00:58 christos Exp
|
||||
.\"
|
||||
.Dd November 13, 2015
|
||||
.Dt STRTOU 3bsd
|
||||
.Dt strtou 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strtou
|
||||
|
@@ -31,7 +31,7 @@
|
||||
.\" $FreeBSD: src/share/man/man3/timeradd.3,v 1.3 2003/09/08 19:57:19 ru Exp $
|
||||
.\"
|
||||
.Dd June 7, 2010
|
||||
.Dt TIMERADD 3bsd
|
||||
.Dt timeradd 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm timeradd ,
|
||||
|
@@ -28,7 +28,7 @@
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd April 12, 2011
|
||||
.Dt TIMEVAL 3bsd
|
||||
.Dt timeval 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm timeval ,
|
||||
|
@@ -24,7 +24,7 @@
|
||||
.\" * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
.\" */
|
||||
.Dd May 10, 2019
|
||||
.Dt TREE 3bsd
|
||||
.Dt tree 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm SPLAY_PROTOTYPE ,
|
||||
|
@@ -30,7 +30,7 @@
|
||||
.\" @(#)unvis.3 8.2 (Berkeley) 12/11/93
|
||||
.\"
|
||||
.Dd March 12, 2011
|
||||
.Dt UNVIS 3bsd
|
||||
.Dt unvis 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm unvis ,
|
||||
|
@@ -30,7 +30,7 @@
|
||||
.\" @(#)vis.3 8.1 (Berkeley) 6/9/93
|
||||
.\"
|
||||
.Dd April 22, 2017
|
||||
.Dt VIS 3bsd
|
||||
.Dt vis 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm vis ,
|
||||
|
@@ -36,7 +36,7 @@
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd March 4, 2009
|
||||
.Dt WCSLCPY 3bsd
|
||||
.Dt wcslcpy 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm wcslcat ,
|
||||
|
@@ -66,7 +66,6 @@ libbsd_la_SOURCES = \
|
||||
arc4random.c \
|
||||
arc4random.h \
|
||||
arc4random_linux.h \
|
||||
arc4random_openbsd.h \
|
||||
arc4random_uniform.c \
|
||||
arc4random_unix.h \
|
||||
arc4random_win.h \
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: arc4random.c,v 1.53 2015/09/10 18:53:50 bcook Exp $ */
|
||||
/* $OpenBSD: arc4random.c,v 1.58 2022/07/31 13:41:45 tb Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996, David Mazieres <dm@uun.org>
|
||||
@@ -50,6 +50,8 @@
|
||||
#define BLOCKSZ 64
|
||||
#define RSBUFSZ (16*BLOCKSZ)
|
||||
|
||||
#define REKEY_BASE (1024*1024) /* NB. should be a power of 2 */
|
||||
|
||||
/* Marked MAP_INHERIT_ZERO, so zero'd out in fork children. */
|
||||
static struct _rs {
|
||||
size_t rs_have; /* valid bytes at end of rs_buf */
|
||||
@@ -74,10 +76,10 @@ _rs_init(unsigned char *buf, size_t n)
|
||||
|
||||
if (rs == NULL) {
|
||||
if (_rs_allocate(&rs, &rsx) == -1)
|
||||
abort();
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
chacha_keysetup(&rsx->rs_chacha, buf, KEYSZ * 8, 0);
|
||||
chacha_keysetup(&rsx->rs_chacha, buf, KEYSZ * 8);
|
||||
chacha_ivsetup(&rsx->rs_chacha, buf + KEYSZ);
|
||||
}
|
||||
|
||||
@@ -108,6 +110,7 @@ static void
|
||||
_rs_stir(void)
|
||||
{
|
||||
unsigned char rnd[KEYSZ + IVSZ];
|
||||
uint32_t rekey_fuzz = 0;
|
||||
|
||||
if (getentropy(rnd, sizeof rnd) == -1)
|
||||
_getentropy_fail();
|
||||
@@ -122,7 +125,10 @@ _rs_stir(void)
|
||||
rs->rs_have = 0;
|
||||
memset(rsx->rs_buf, 0, sizeof(rsx->rs_buf));
|
||||
|
||||
rs->rs_count = 1600000;
|
||||
/* rekey interval should not be predictable */
|
||||
chacha_encrypt_bytes(&rsx->rs_chacha, (uint8_t *)&rekey_fuzz,
|
||||
(uint8_t *)&rekey_fuzz, sizeof(rekey_fuzz));
|
||||
rs->rs_count = REKEY_BASE + (rekey_fuzz % REKEY_BASE);
|
||||
}
|
||||
|
||||
static inline void
|
||||
|
@@ -32,9 +32,7 @@
|
||||
int
|
||||
getentropy(void *buf, size_t len);
|
||||
|
||||
#if defined(__OpenBSD__)
|
||||
#include "arc4random_openbsd.h"
|
||||
#elif defined(__linux__)
|
||||
#if defined(__linux__)
|
||||
#include "arc4random_linux.h"
|
||||
#elif defined(_WIN32)
|
||||
#include "arc4random_win.h"
|
||||
|
@@ -1,61 +0,0 @@
|
||||
/* $OpenBSD: arc4random.h,v 1.3 2014/07/20 20:51:13 bcook Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996, David Mazieres <dm@uun.org>
|
||||
* Copyright (c) 2008, Damien Miller <djm@openbsd.org>
|
||||
* Copyright (c) 2013, Markus Friedl <markus@openbsd.org>
|
||||
* Copyright (c) 2014, Theo de Raadt <deraadt@openbsd.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Stub functions for portability.
|
||||
*/
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#include "thread_private.h"
|
||||
|
||||
static inline void
|
||||
_getentropy_fail(void)
|
||||
{
|
||||
raise(SIGKILL);
|
||||
}
|
||||
|
||||
static inline int
|
||||
_rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
|
||||
{
|
||||
struct {
|
||||
struct _rs rs;
|
||||
struct _rsx rsx;
|
||||
} *p;
|
||||
|
||||
if ((p = mmap(NULL, sizeof(*p), PROT_READ|PROT_WRITE,
|
||||
MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED)
|
||||
return (-1);
|
||||
if (minherit(p, sizeof(*p), MAP_INHERIT_ZERO) == -1) {
|
||||
munmap(p, sizeof(*p));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
*rsp = &p->rs;
|
||||
*rsxp = &p->rsx;
|
||||
return (0);
|
||||
}
|
||||
|
||||
static inline void
|
||||
_rs_forkdetect(void)
|
||||
{
|
||||
}
|
@@ -4,7 +4,7 @@ D. J. Bernstein
|
||||
Public domain.
|
||||
*/
|
||||
|
||||
/* $OpenBSD: chacha_private.h,v 1.2 2013/10/04 07:02:27 djm Exp $ */
|
||||
/* $OpenBSD: chacha_private.h,v 1.3 2022/02/28 21:56:29 dtucker Exp $ */
|
||||
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned int u32;
|
||||
@@ -52,7 +52,7 @@ static const char sigma[16] = "expand 32-byte k";
|
||||
static const char tau[16] = "expand 16-byte k";
|
||||
|
||||
static void
|
||||
chacha_keysetup(chacha_ctx *x,const u8 *k,u32 kbits,u32 ivbits)
|
||||
chacha_keysetup(chacha_ctx *x,const u8 *k,u32 kbits)
|
||||
{
|
||||
const char *constants;
|
||||
|
||||
|
@@ -87,6 +87,9 @@ fgetwln(FILE *stream, size_t *lenp)
|
||||
*lenp = wused;
|
||||
return wused ? fb->wbuf : NULL;
|
||||
}
|
||||
/* XXX: Ideally we'd recommend getwline(3), but unfortunately even though it
|
||||
* was part of the ISO/IEC TR 24731-2:2010 draft, it did not make it into C11
|
||||
* and is not widely implemented. */
|
||||
libbsd_link_warning(fgetwln,
|
||||
"The fgetwln() function cannot be safely ported, use fgetwc(3) "
|
||||
"instead, as it is supported by C99 and POSIX.1-2001.");
|
||||
|
@@ -32,7 +32,7 @@
|
||||
int
|
||||
fpurge(FILE *fp)
|
||||
{
|
||||
if (fp == NULL || fileno(fp) < 0) {
|
||||
if (fp == NULL) {
|
||||
errno = EBADF;
|
||||
return EOF;
|
||||
}
|
||||
|
@@ -415,17 +415,17 @@ getentropy_fallback(void *buf, size_t len)
|
||||
#ifdef HAVE_GETAUXVAL
|
||||
#ifdef AT_RANDOM
|
||||
/* Not as random as you think but we take what we are given */
|
||||
p = (char *) getauxval(AT_RANDOM);
|
||||
p = (char *) ((intptr_t) getauxval(AT_RANDOM));
|
||||
if (p)
|
||||
HR(p, 16);
|
||||
#endif
|
||||
#ifdef AT_SYSINFO_EHDR
|
||||
p = (char *) getauxval(AT_SYSINFO_EHDR);
|
||||
p = (char *) ((intptr_t) getauxval(AT_SYSINFO_EHDR));
|
||||
if (p)
|
||||
HR(p, pgs);
|
||||
#endif
|
||||
#ifdef AT_BASE
|
||||
p = (char *) getauxval(AT_BASE);
|
||||
p = (char *) ((intptr_t) getauxval(AT_BASE));
|
||||
if (p)
|
||||
HD(p);
|
||||
#endif
|
||||
|
@@ -124,6 +124,16 @@
|
||||
#define ELF_TARG_CLASS ELFCLASS64
|
||||
#define ELF_TARG_DATA ELFDATA2LSB
|
||||
|
||||
#elif defined(__loongarch__)
|
||||
|
||||
#define ELF_TARG_MACH EM_LOONGARCH
|
||||
#if defined(__loongarch64)
|
||||
#define ELF_TARG_CLASS ELFCLASS64
|
||||
#else
|
||||
#error Unsupported ELF class
|
||||
#endif
|
||||
#define ELF_TARG_DATA ELFDATA2LSB
|
||||
|
||||
#elif defined(__m32r__)
|
||||
|
||||
#define ELF_TARG_MACH EM_M32R
|
||||
@@ -220,7 +230,7 @@
|
||||
#if defined(__LITTLE_ENDIAN__)
|
||||
#define ELF_TARG_DATA ELFDATA2LSB
|
||||
#elif defined(__BIG_ENDIAN__)
|
||||
#define ELF_TARG_DATA ELFDATA2LMSB
|
||||
#define ELF_TARG_DATA ELFDATA2MSB
|
||||
#else
|
||||
#error Unknown SH endianness
|
||||
#endif
|
||||
|
@@ -36,6 +36,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
@@ -144,12 +145,13 @@ common: if (set->cmd2 & CMD2_CLR) {
|
||||
|
||||
#define ADDCMD(a, b, c, d) do { \
|
||||
if (set >= endset) { \
|
||||
ptrdiff_t setdiff = set - saveset; \
|
||||
BITCMD *newset; \
|
||||
setlen += SET_LEN_INCR; \
|
||||
newset = reallocarray(saveset, setlen, sizeof(BITCMD)); \
|
||||
if (newset == NULL) \
|
||||
goto out; \
|
||||
set = newset + (set - saveset); \
|
||||
set = newset + setdiff; \
|
||||
saveset = newset; \
|
||||
endset = newset + (setlen - 2); \
|
||||
} \
|
||||
|
@@ -38,7 +38,7 @@
|
||||
*
|
||||
* To avoid any other possible fallout, the constructor is split into a
|
||||
* new static library that needs to be linked explicitly into programs
|
||||
* using setproctitle(). As an additional safety measure the pkg-config
|
||||
* using setproctitle(). As an additional safety measure the pkgconf(1)
|
||||
* linker flags will mark the program as not allowing to be dlopen()ed
|
||||
* so that we make sure to avoid the problem described above.
|
||||
*/
|
||||
|
6
test/.gitignore
vendored
6
test/.gitignore
vendored
@@ -2,23 +2,25 @@ arc4random
|
||||
bzero
|
||||
closefrom
|
||||
endian
|
||||
explicit_bzero
|
||||
fgetln
|
||||
funopen
|
||||
fparseln
|
||||
fpurge
|
||||
funopen
|
||||
headers-overlay-gen.c
|
||||
headers-system-gen.c
|
||||
humanize
|
||||
md5
|
||||
nlist
|
||||
overlay
|
||||
proctitle-init
|
||||
proctitle
|
||||
proctitle-init
|
||||
progname
|
||||
pwcache
|
||||
setmode
|
||||
strl
|
||||
strmode
|
||||
strnstr
|
||||
strtonum
|
||||
vis
|
||||
vis-openbsd
|
||||
|
@@ -34,6 +34,7 @@ check_PROGRAMS = \
|
||||
bzero \
|
||||
closefrom \
|
||||
endian \
|
||||
explicit_bzero \
|
||||
humanize \
|
||||
fgetln \
|
||||
funopen \
|
||||
@@ -48,6 +49,7 @@ check_PROGRAMS = \
|
||||
strl \
|
||||
strmode \
|
||||
strnstr \
|
||||
strtonum \
|
||||
vis \
|
||||
vis-openbsd \
|
||||
$(nil)
|
||||
|
229
test/explicit_bzero.c
Normal file
229
test/explicit_bzero.c
Normal file
@@ -0,0 +1,229 @@
|
||||
/* $OpenBSD: explicit_bzero.c,v 1.7 2021/03/27 11:17:58 bcook Exp $ */
|
||||
/*
|
||||
* Copyright (c) 2014 Google Inc.
|
||||
* Copyright (c) 2022 Guillem Jover <guillem@hadrons.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define ASSERT_EQ(a, b) assert((a) == (b))
|
||||
#define ASSERT_NE(a, b) assert((a) != (b))
|
||||
#define ASSERT_GE(a, b) assert((a) >= (b))
|
||||
|
||||
/* 128 bits of random data. */
|
||||
static const char secret[16] = {
|
||||
0xa0, 0x6c, 0x0c, 0x81, 0xba, 0xd8, 0x5b, 0x0c,
|
||||
0xb0, 0xd6, 0xd4, 0xe3, 0xeb, 0x52, 0x5f, 0x96,
|
||||
};
|
||||
|
||||
enum {
|
||||
SECRETCOUNT = 64,
|
||||
SECRETBYTES = SECRETCOUNT * sizeof(secret)
|
||||
};
|
||||
|
||||
/*
|
||||
* As of glibc 2.34, when _GNU_SOURCE is defined, SIGSTKSZ is no longer
|
||||
* constant on Linux. SIGSTKSZ is redefined to sysconf (_SC_SIGSTKSZ).
|
||||
*/
|
||||
static char *altstack;
|
||||
#define ALTSTACK_SIZE (SIGSTKSZ + SECRETBYTES)
|
||||
|
||||
static void
|
||||
setup_stack(void)
|
||||
{
|
||||
const stack_t sigstk = {
|
||||
.ss_sp = altstack = calloc(1, ALTSTACK_SIZE),
|
||||
.ss_size = ALTSTACK_SIZE
|
||||
};
|
||||
|
||||
ASSERT_NE(NULL, altstack);
|
||||
ASSERT_EQ(0, sigaltstack(&sigstk, NULL));
|
||||
}
|
||||
|
||||
static void
|
||||
cleanup_stack(void)
|
||||
{
|
||||
free(altstack);
|
||||
}
|
||||
|
||||
static void
|
||||
assert_on_stack(void)
|
||||
{
|
||||
stack_t cursigstk;
|
||||
ASSERT_EQ(0, sigaltstack(NULL, &cursigstk));
|
||||
ASSERT_EQ(SS_ONSTACK, cursigstk.ss_flags & (SS_DISABLE|SS_ONSTACK));
|
||||
}
|
||||
|
||||
static void
|
||||
call_on_stack(void (*fn)(int))
|
||||
{
|
||||
/*
|
||||
* This is a bit more complicated than strictly necessary, but
|
||||
* it ensures we don't have any flaky test failures due to
|
||||
* inherited signal masks/actions/etc.
|
||||
*
|
||||
* On systems where SA_ONSTACK is not supported, this could
|
||||
* alternatively be implemented using makecontext() or
|
||||
* pthread_attr_setstack().
|
||||
*/
|
||||
|
||||
const struct sigaction sigact = {
|
||||
.sa_handler = fn,
|
||||
.sa_flags = SA_ONSTACK,
|
||||
};
|
||||
struct sigaction oldsigact;
|
||||
sigset_t sigset, oldsigset;
|
||||
|
||||
/* First, block all signals. */
|
||||
ASSERT_EQ(0, sigemptyset(&sigset));
|
||||
ASSERT_EQ(0, sigfillset(&sigset));
|
||||
ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &sigset, &oldsigset));
|
||||
|
||||
/* Next setup the signal handler for SIGUSR1. */
|
||||
ASSERT_EQ(0, sigaction(SIGUSR1, &sigact, &oldsigact));
|
||||
|
||||
/* Raise SIGUSR1 and momentarily unblock it to run the handler. */
|
||||
ASSERT_EQ(0, raise(SIGUSR1));
|
||||
ASSERT_EQ(0, sigdelset(&sigset, SIGUSR1));
|
||||
ASSERT_EQ(-1, sigsuspend(&sigset));
|
||||
ASSERT_EQ(EINTR, errno);
|
||||
|
||||
/* Restore the original signal action, stack, and mask. */
|
||||
ASSERT_EQ(0, sigaction(SIGUSR1, &oldsigact, NULL));
|
||||
ASSERT_EQ(0, sigprocmask(SIG_SETMASK, &oldsigset, NULL));
|
||||
}
|
||||
|
||||
static void
|
||||
populate_secret(char *buf, ssize_t len)
|
||||
{
|
||||
int i, fds[2];
|
||||
ASSERT_EQ(0, pipe(fds));
|
||||
|
||||
for (i = 0; i < SECRETCOUNT; i++)
|
||||
ASSERT_EQ(sizeof(secret), write(fds[1], secret, sizeof(secret)));
|
||||
ASSERT_EQ(0, close(fds[1]));
|
||||
|
||||
ASSERT_EQ(len, read(fds[0], buf, len));
|
||||
ASSERT_EQ(0, close(fds[0]));
|
||||
}
|
||||
|
||||
static void __attribute__((__noinline__))
|
||||
blank_stack_side_effects(char *buf, size_t len)
|
||||
{
|
||||
char scratch[SECRETBYTES * 4];
|
||||
|
||||
/* If the read(3) in populate_secret() wrote into the stack, as it
|
||||
* might happen on the Hurd for small data, then we might incorrectly
|
||||
* detect the wrong secret on the stack. */
|
||||
memset(scratch, 0xFF, sizeof(scratch));
|
||||
ASSERT_EQ(NULL, memmem(scratch, sizeof(scratch), buf, len));
|
||||
}
|
||||
|
||||
static int
|
||||
count_secrets(const char *buf)
|
||||
{
|
||||
int res = 0;
|
||||
size_t i;
|
||||
for (i = 0; i < SECRETCOUNT; i++) {
|
||||
if (memcmp(buf + i * sizeof(secret), secret,
|
||||
sizeof(secret)) == 0)
|
||||
res += 1;
|
||||
}
|
||||
return (res);
|
||||
}
|
||||
|
||||
static char *
|
||||
test_without_bzero(void)
|
||||
{
|
||||
char buf[SECRETBYTES];
|
||||
char *res;
|
||||
assert_on_stack();
|
||||
populate_secret(buf, sizeof(buf));
|
||||
blank_stack_side_effects(buf, sizeof(buf));
|
||||
res = memmem(altstack, ALTSTACK_SIZE, buf, sizeof(buf));
|
||||
ASSERT_NE(NULL, res);
|
||||
return (res);
|
||||
}
|
||||
|
||||
static char *
|
||||
test_with_bzero(void)
|
||||
{
|
||||
char buf[SECRETBYTES];
|
||||
char *res;
|
||||
assert_on_stack();
|
||||
populate_secret(buf, sizeof(buf));
|
||||
blank_stack_side_effects(buf, sizeof(buf));
|
||||
res = memmem(altstack, ALTSTACK_SIZE, buf, sizeof(buf));
|
||||
ASSERT_NE(NULL, res);
|
||||
explicit_bzero(buf, sizeof(buf));
|
||||
return (res);
|
||||
}
|
||||
|
||||
static void
|
||||
do_test_without_bzero(int signo)
|
||||
{
|
||||
char *buf = test_without_bzero();
|
||||
ASSERT_GE(count_secrets(buf), 1);
|
||||
}
|
||||
|
||||
static void
|
||||
do_test_with_bzero(int signo)
|
||||
{
|
||||
char *buf = test_with_bzero();
|
||||
ASSERT_EQ(count_secrets(buf), 0);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
setup_stack();
|
||||
|
||||
/*
|
||||
* Solaris and OS X clobber the signal stack after returning to the
|
||||
* normal stack, so we need to inspect altstack while we're still
|
||||
* running on it. Unfortunately, this means we risk clobbering the
|
||||
* buffer ourselves.
|
||||
*
|
||||
* To minimize this risk, test_with{,out}_bzero() are responsible for
|
||||
* locating the offset of their buf variable within altstack, and
|
||||
* and returning that address. Then we can simply memcmp() repeatedly
|
||||
* to count how many instances of secret we found.
|
||||
*/
|
||||
|
||||
/*
|
||||
* First, test that if we *don't* call explicit_bzero, that we
|
||||
* *are* able to find at least one instance of the secret data still
|
||||
* on the stack. This sanity checks that call_on_stack() and
|
||||
* populate_secret() work as intended.
|
||||
*/
|
||||
memset(altstack, 0, ALTSTACK_SIZE);
|
||||
call_on_stack(do_test_without_bzero);
|
||||
|
||||
/*
|
||||
* Now test with a call to explicit_bzero() and check that we
|
||||
* *don't* find any instances of the secret data.
|
||||
*/
|
||||
memset(altstack, 0, ALTSTACK_SIZE);
|
||||
call_on_stack(do_test_with_bzero);
|
||||
|
||||
cleanup_stack();
|
||||
|
||||
return (0);
|
||||
}
|
@@ -25,24 +25,33 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
static FILE fp_bad;
|
||||
FILE *fp;
|
||||
char *buf = NULL;
|
||||
size_t bufsz = 0;
|
||||
|
||||
if (fpurge(NULL) == 0)
|
||||
return 1;
|
||||
|
||||
if (fpurge(&fp_bad) == 0)
|
||||
return 1;
|
||||
|
||||
fp = fopen("/dev/zero", "r");
|
||||
if (fpurge(fp) < 0)
|
||||
return 1;
|
||||
|
||||
fclose(fp);
|
||||
|
||||
fp = open_memstream(&buf, &bufsz);
|
||||
fputs("World", fp);
|
||||
if (fpurge(fp) < 0)
|
||||
return 1;
|
||||
fflush(fp);
|
||||
if (bufsz != 0)
|
||||
return 1;
|
||||
free(buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
64
test/strtonum.c
Normal file
64
test/strtonum.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/* $OpenBSD: strtonumtest.c,v 1.1 2004/08/03 20:38:36 otto Exp $ */
|
||||
/*
|
||||
* Copyright (c) 2004 Otto Moerbeek <otto@drijf.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static int fail;
|
||||
|
||||
static void
|
||||
test(const char *p, long long lb, long long ub, int ok)
|
||||
{
|
||||
long long val;
|
||||
const char *q;
|
||||
|
||||
val = strtonum(p, lb, ub, &q);
|
||||
if (ok && q != NULL) {
|
||||
fprintf(stderr, "%s [%lld-%lld] ", p, lb, ub);
|
||||
fprintf(stderr, "NUMBER NOT ACCEPTED %s\n", q);
|
||||
fail = 1;
|
||||
} else if (!ok && q == NULL) {
|
||||
fprintf(stderr, "%s [%lld-%lld] %lld ", p, lb, ub, val);
|
||||
fprintf(stderr, "NUMBER ACCEPTED\n");
|
||||
fail = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
test("1", 0, 10, 1);
|
||||
test("0", -2, 5, 1);
|
||||
test("0", 2, 5, 0);
|
||||
test("0", 2, LLONG_MAX, 0);
|
||||
test("-2", 0, LLONG_MAX, 0);
|
||||
test("0", -5, LLONG_MAX, 1);
|
||||
test("-3", -3, LLONG_MAX, 1);
|
||||
test("-9223372036854775808", LLONG_MIN, LLONG_MAX, 1);
|
||||
test("9223372036854775807", LLONG_MIN, LLONG_MAX, 1);
|
||||
test("-9223372036854775809", LLONG_MIN, LLONG_MAX, 0);
|
||||
test("9223372036854775808", LLONG_MIN, LLONG_MAX, 0);
|
||||
test("1000000000000000000000000", LLONG_MIN, LLONG_MAX, 0);
|
||||
test("-1000000000000000000000000", LLONG_MIN, LLONG_MAX, 0);
|
||||
test("-2", 10, -1, 0);
|
||||
test("-2", -10, -1, 1);
|
||||
test("-20", -10, -1, 0);
|
||||
test("20", -10, -1, 0);
|
||||
|
||||
return (fail);
|
||||
}
|
||||
|
Reference in New Issue
Block a user