Compare commits

...

19 Commits

Author SHA1 Message Date
Guillem Jover
084911ce87 Release libbsd 0.11.7 2022-10-06 04:07:52 +02:00
Guillem Jover
3538d38fe7 man: Discourage using the library in non-overlay mode
This makes code using it non-portable, and requires the namespeced
headers from libbsd, instead of any generic system headers. It also
requires more code changes than the overlay mode.
2022-10-06 03:59:33 +02:00
Guillem Jover
03fccd1505 include: Adjust reallocarray() per glibc adoption
On glibc 2.29 reallocarray() was moved to _DEFAULT_SOURCE.

Closes: !20
Based-on-patch-by: Callum Farmer <gmbr3@opensuse.org>
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2022-10-05 12:31:49 +02:00
Callum Farmer
6b6e686b23 include: Adjust arc4random() per glibc adoption
Some arc4random functions were added in glibc 2.36.

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2022-10-05 12:31:49 +02:00
Callum Farmer
da1f45ac71 include: explicit_bzero() requires _DEFAULT_SOURCE
Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2022-10-05 12:15:36 +02:00
Guillem Jover
2f9eddc277 include: Simplify glibc version dependent macro handling
We test once whether __GLIBC__ is not defined, so we do not need to test
whether it is on the OR branch afterwards. We decouple the glibc version
restriction check from the _*_SOURCE variable, as that contains an
implicit opposite version check.
2022-10-05 12:12:34 +02:00
Guillem Jover
28298ac037 doc: Switch references from pkg-config to pkgconf
The former used to be the reference implementation, but it has been
stagnant to the point of not showing much signs of life. Switch to
the currently active and more complete implementation for references.
2022-10-05 01:36:28 +02:00
Guillem Jover
ef981f930b doc: Add missing empty line to separate README sections 2022-10-04 04:29:37 +02:00
Guillem Jover
6928d7895e doc: Refer to the main git repository as primary 2022-10-04 04:29:37 +02:00
Guillem Jover
d5865759f8 test: Fix explicit_bzero() test on the Hurd
On the Hurd a small read(3) might end up (indirectly) copying the data
on the stack, which we will end up finding even when we have cleared
the buffer.

To avoid these side effects, we add a new function, that we force not
to be inlined, so that we can reuse the same stack space, that will
blank any possible stack side effects. This should be portable
regardless of stack growing up or down.

Diagnosis-by: Samuel Thibault <sthibault@debian.org>
2022-10-04 04:29:37 +02:00
Guillem Jover
be327c6ebe fgetwln: Add comment about lack of getwline(3) for recommendation
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.
2022-10-04 04:29:07 +02:00
Guillem Jover
a14612d968 setmode: Dot not use saveset after free
While we are only doing a pointer difference and not dereferencing it,
it's easier and more correct to do the pointer difference before passing
it to reallocarray().

Warned-by: gcc
2022-08-23 23:51:05 +02:00
Guillem Jover
f4baceb82c man: Rewrite gerprogname(3bsd) from scratch
This gets rid of one of the last man pages with a BSD-4-clause license.
2022-08-03 11:39:31 +02:00
Guillem Jover
f35c545847 man: Lowercase man page title
While using fully uppercase man page titles has been the usual
convention for a very long time, it is rather ugly and something that
some other projects are switching away from.
2022-08-03 11:39:31 +02:00
Guillem Jover
b466b14afb man: Document that some arc4random(3) functions are now in glibc 2.36 2022-08-03 11:39:31 +02:00
Guillem Jover
1f6a48b209 Sync arc4random(3) implementation from OpenBSD
Closes: #12
2022-08-03 11:39:31 +02:00
Fabrice Fontaine
873639ebb5 Fix ELF support for big endian SH
Fix the following build failure with big endian SH (e.g. sh4aeb):

  ,---
  In file included from nlist.c:44:
  nlist.c: In function '__elf_is_okay__':
  local-elf.h:223:25: error: 'ELFDATA2LMSB' undeclared (first use in this function); did you mean 'ELFDATA2LSB'?
    223 | #define ELF_TARG_DATA   ELFDATA2LMSB
        |                         ^~~~~~~~~~~~
  `---

Fixes: http://autobuild.buildroot.org/results/2980fb79c208454195d77383f1ece9afbd7f981b
Closes: !19
Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2022-06-08 11:51:55 +02:00
Guillem Jover
c9c78fdfd0 man: Use -compact also for alternative functions in libbsd(7)
The other function lists use the compact mode, let's be uniform about
this.
2022-06-08 11:50:47 +02:00
Guillem Jover
5f21307570 getentropy: Fix function cast for getauxval()
Fix also the Hurd implementation, missed in the original fix.

Extends: commit 72a82ee262
Warned-by: gcc
2022-06-08 11:49:16 +02:00
56 changed files with 164 additions and 165 deletions

35
COPYING
View File

@@ -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
@@ -402,7 +369,7 @@ Copyright:
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
View File

@@ -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
------------------------

View File

@@ -13,7 +13,7 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])],
LIBBSD_ABI_MAJOR=0
LIBBSD_ABI_MINOR=11
LIBBSD_ABI_PATCH=6
LIBBSD_ABI_PATCH=7
LIBBSD_ABI="$LIBBSD_ABI_MAJOR:$LIBBSD_ABI_MINOR:$LIBBSD_ABI_PATCH"
AC_SUBST([LIBBSD_ABI])

View File

@@ -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);

View File

@@ -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

View File

@@ -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]

View File

@@ -31,7 +31,7 @@
.\" $FreeBSD$
.\"
.Dd July 19, 1993
.Dt BITSTRING 3bsd
.Dt bitstring 3bsd
.Os
.Sh NAME
.Nm bit_alloc ,

View File

@@ -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 ,

View File

@@ -26,7 +26,7 @@
.\" $FreeBSD$
.\"
.Dd June 12, 2009
.Dt CLOSEFROM 3bsd
.Dt closefrom 3bsd
.Os
.Sh NAME
.Nm closefrom

View File

@@ -28,7 +28,7 @@
.\" SUCH DAMAGE.
.\"
.Dd $Mdocdate: April 23 2014 $
.Dt ERRC 3bsd
.Dt errc 3bsd
.Os
.Sh NAME
.Nm errc ,

View File

@@ -26,7 +26,7 @@
.\" $FreeBSD$
.\"
.Dd August 15, 2010
.Dt EXPAND_NUMBER 3bsd
.Dt expand_number 3bsd
.Os
.Sh NAME
.Nm expand_number

View File

@@ -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

View File

@@ -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

View File

@@ -29,7 +29,7 @@
.\" $FreeBSD$
.\"
.Dd July 16, 2004
.Dt FGETWLN 3bsd
.Dt fgetwln 3bsd
.Os
.Sh NAME
.Nm fgetwln

View File

@@ -26,7 +26,7 @@
.\" $FreeBSD$
.\"
.Dd July 28, 2017
.Dt FLOPEN 3bsd
.Dt flopen 3bsd
.Os
.Sh NAME
.Nm flopen ,

View File

@@ -27,7 +27,7 @@
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd June 14, 2014
.Dt FMTCHECK 3bsd
.Dt fmtcheck 3bsd
.Os
.Sh NAME
.Nm fmtcheck

View File

@@ -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

View File

@@ -32,7 +32,7 @@
.\" SUCH DAMAGE.
.\"
.Dd $Mdocdate: November 4 2015 $
.Dt FPURGE 3bsd
.Dt fpurge 3bsd
.Os
.Sh NAME
.Nm fpurge

View File

@@ -31,7 +31,7 @@
.\" $FreeBSD$
.\"
.Dd March 19, 2004
.Dt FUNOPEN 3bsd
.Dt funopen 3bsd
.Os
.Sh NAME
.Nm funopen ,

View File

@@ -29,7 +29,7 @@
.\" $FreeBSD$
.\"
.Dd November 16, 2012
.Dt GETBSIZE 3bsd
.Dt getbsize 3bsd
.Os
.Sh NAME
.Nm getbsize

View File

@@ -26,7 +26,7 @@
.\" $FreeBSD$
.\"
.Dd July 15, 2001
.Dt GETPEEREID 3bsd
.Dt getpeereid 3bsd
.Os
.Sh NAME
.Nm getpeereid

View File

@@ -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 .

View File

@@ -33,7 +33,7 @@
.\" $FreeBSD$
.\"
.Dd September 30, 2003
.Dt HEAPSORT 3bsd
.Dt heapsort 3bsd
.Os
.Sh NAME
.Nm heapsort , mergesort

View File

@@ -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 ,

View File

@@ -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 Mar 30, 2022
.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
@@ -239,6 +240,17 @@ This function is provided by
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 ,

View File

@@ -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

View File

@@ -25,7 +25,7 @@
.\" $FreeBSD$
.\"
.Dd February 8, 2012
.Dt PIDFILE 3bsd
.Dt pidfile 3bsd
.Os
.Sh NAME
.Nm pidfile_open ,

View File

@@ -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 ,

View File

@@ -29,7 +29,7 @@
.\" $FreeBSD$
.\"
.Dd September 8, 2016
.Dt QUEUE 3bsd
.Dt queue 3bsd
.Os
.Sh NAME
.Nm SLIST_CLASS_ENTRY ,

View File

@@ -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 ,

View File

@@ -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

View File

@@ -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 ,

View File

@@ -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

View File

@@ -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 ,

View File

@@ -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

View File

@@ -27,7 +27,7 @@
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd May 6, 2010
.Dt STRINGLIST 3bsd
.Dt stringlist 3bsd
.Os
.Sh NAME
.Nm stringlist ,

View File

@@ -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 ,

View File

@@ -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

View File

@@ -34,7 +34,7 @@
.\" $FreeBSD$
.\"
.Dd October 11, 2001
.Dt STRSTR 3bsd
.Dt strstr 3bsd
.Os
.Sh NAME
.Nm strnstr

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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 ,

View File

@@ -28,7 +28,7 @@
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd April 12, 2011
.Dt TIMEVAL 3bsd
.Dt timeval 3bsd
.Os
.Sh NAME
.Nm timeval ,

View File

@@ -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 ,

View File

@@ -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 ,

View File

@@ -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 ,

View File

@@ -36,7 +36,7 @@
.\" $FreeBSD$
.\"
.Dd March 4, 2009
.Dt WCSLCPY 3bsd
.Dt wcslcpy 3bsd
.Os
.Sh NAME
.Nm wcslcat ,

View File

@@ -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

View File

@@ -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;

View File

@@ -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.");

View File

@@ -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

View File

@@ -230,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

View File

@@ -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); \
} \

View File

@@ -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.
*/

View File

@@ -1,6 +1,7 @@
/* $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
@@ -123,6 +124,18 @@ populate_secret(char *buf, ssize_t 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)
{
@@ -143,6 +156,7 @@ test_without_bzero(void)
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);
@@ -155,6 +169,7 @@ test_with_bzero(void)
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));