sync with OpenBSD -current

This commit is contained in:
purplerain 2024-01-20 03:21:37 +00:00
parent fdad81bcfc
commit ed28f347da
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
53 changed files with 1138 additions and 405 deletions

View file

@ -1,9 +1,7 @@
# $OpenBSD: Makefile.inc,v 1.6 2023/02/27 15:00:17 deraadt Exp $
# $OpenBSD: Makefile.inc,v 1.7 2024/01/19 17:02:28 deraadt Exp $
.PATH: ${LIBCSRCDIR}/dlfcn
.include <bsd.own.mk>
SRCS+= dlfcn_stubs.c init.c tib.c
init.o init.po: _execvesize.c

View file

@ -1,4 +1,4 @@
/* $OpenBSD: init.c,v 1.20 2024/01/18 19:00:11 deraadt Exp $ */
/* $OpenBSD: init.c,v 1.21 2024/01/19 14:15:51 deraadt Exp $ */
/*
* Copyright (c) 2014,2015 Philip Guenther <guenther@openbsd.org>
*
@ -71,9 +71,6 @@ extern Elf_Ehdr __executable_start[] __attribute__((weak));
/* provide definitions for these */
const dl_cb *_dl_cb __relro = NULL;
int pinsyscall(int, void *, size_t);
PROTO_NORMAL(pinsyscall);
int HIDDEN(execve)(const char *, char *const *, char *const *)
__attribute__((weak));
@ -141,23 +138,9 @@ _libc_preinit(int argc, char **argv, char **envp, dl_cb_cb *cb)
_static_phdr_info.dlpi_phnum = phnum;
/* static libc in a static link? */
if (cb == NULL) {
if (cb == NULL)
setup_static_tib(phdr, phnum);
#if !defined(__hppa__)
if (&HIDDEN(execve)) {
extern const int _execve_size;
pinsyscall(SYS_execve, &HIDDEN(execve), _execve_size);
} else {
static const int not_syscall;
/* Static binary which does not use execve() */
pinsyscall(SYS_execve, (void *)&not_syscall, 1);
}
#endif
}
/*
* If a static binary has text relocations (DT_TEXT), then un-writeable
* segments were not made immutable by the kernel. Textrel and RELRO

View file

@ -1,4 +1,4 @@
/* $OpenBSD: stdlib.h,v 1.18 2023/05/27 04:33:00 otto Exp $ */
/* $OpenBSD: stdlib.h,v 1.19 2024/01/19 19:45:02 millert Exp $ */
/* $NetBSD: stdlib.h,v 1.25 1995/12/27 21:19:08 jtc Exp $ */
/*-
@ -38,6 +38,7 @@
#include_next <stdlib.h>
__BEGIN_HIDDEN_DECLS
int __mktemp4(char *, int, int, int (*)(const char *, int));
char *__findenv(const char *, int, int *);
void __atexit_register_cleanup(void (*)(void));
__END_HIDDEN_DECLS

View file

@ -1,4 +1,4 @@
# $OpenBSD: Makefile.inc,v 1.29 2016/03/30 06:38:41 jmc Exp $
# $OpenBSD: Makefile.inc,v 1.30 2024/01/19 16:30:28 millert Exp $
# stdio sources
.PATH: ${LIBCSRCDIR}/stdio
@ -9,7 +9,7 @@ SRCS+= asprintf.c clrerr.c fclose.c fdopen.c feof.c ferror.c fflush.c fgetc.c \
fgetln.c fgetpos.c fgets.c fileno.c findfp.c flags.c fmemopen.c \
fopen.c fprintf.c fpurge.c fputc.c fputs.c fread.c freopen.c fscanf.c \
fseek.c fsetpos.c ftell.c funopen.c fvwrite.c fwalk.c fwrite.c \
getc.c getchar.c getw.c makebuf.c mktemp.c open_memstream.c \
getc.c getchar.c getw.c makebuf.c open_memstream.c \
open_wmemstream.c perror.c printf.c putc.c putchar.c puts.c putw.c \
refill.c remove.c rewind.c rget.c scanf.c setbuf.c setbuffer.c \
setvbuf.c snprintf.c sprintf.c sscanf.c stdio.c tempnam.c tmpfile.c \
@ -22,7 +22,7 @@ SRCS+= asprintf.c clrerr.c fclose.c fdopen.c feof.c ferror.c fflush.c fgetc.c \
getdelim.c getline.c dprintf.c vdprintf.c
MAN+= fclose.3 ferror.3 fflush.3 fgetln.3 fgets.3 fgetwln.3 fmemopen.3 \
fopen.3 fputs.3 fread.3 fseek.3 funopen.3 getc.3 mktemp.3 \
fopen.3 fputs.3 fread.3 fseek.3 funopen.3 getc.3 \
open_memstream.3 perror.3 printf.3 putc.3 remove.3 scanf.3 setbuf.3 \
setvbuf.3 stdio.3 tmpnam.3 ungetc.3 fgetws.3 fputws.3 fwide.3 getwc.3 \
putwc.3 ungetwc.3 wprintf.3 wscanf.3 getdelim.3

View file

@ -1,4 +1,4 @@
# $OpenBSD: Makefile.inc,v 1.64 2017/12/16 20:06:55 guenther Exp $
# $OpenBSD: Makefile.inc,v 1.66 2024/01/19 19:45:02 millert Exp $
# stdlib sources
.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/stdlib ${LIBCSRCDIR}/stdlib
@ -6,9 +6,9 @@
SRCS+= a64l.c abort.c atexit.c atoi.c atof.c atol.c atoll.c bsearch.c \
exit.c ecvt.c gcvt.c getenv.c getopt_long.c \
getsubopt.c hcreate.c heapsort.c imaxabs.c imaxdiv.c insque.c \
l64a.c llabs.c lldiv.c lsearch.c malloc.c reallocarray.c \
merge.c posix_pty.c qsort.c radixsort.c rand.c random.c \
realpath.c remque.c setenv.c strtoimax.c \
l64a.c llabs.c lldiv.c lsearch.c malloc.c __mktemp4.c mkdtemp.c \
mkstemp.c mktemp.c reallocarray.c merge.c posix_pty.c qsort.c \
radixsort.c rand.c random.c realpath.c remque.c setenv.c strtoimax.c \
strtol.c strtoll.c strtonum.c strtoul.c strtoull.c strtoumax.c \
system.c \
tfind.c thread_atexit.c tsearch.c \
@ -28,6 +28,6 @@ SRCS+= abs.c div.c labs.c ldiv.c
MAN+= a64l.3 abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 atoll.3 \
bsearch.3 div.3 ecvt.3 exit.3 getenv.3 getopt.3 getopt_long.3 \
getsubopt.3 hcreate.3 imaxabs.3 imaxdiv.3 insque.3 labs.3 ldiv.3 \
lldiv.3 lsearch.3 malloc.3 posix_memalign.3 posix_openpt.3 ptsname.3 \
qsort.3 radixsort.3 rand48.3 rand.3 random.3 realpath.3 \
lldiv.3 lsearch.3 malloc.3 mktemp.3 posix_memalign.3 posix_openpt.3 \
ptsname.3 qsort.3 radixsort.3 rand48.3 rand.3 random.3 realpath.3 \
strtod.3 strtonum.3 strtol.3 strtoul.3 system.3 tsearch.3

View file

@ -1,7 +1,7 @@
/* $OpenBSD: mktemp.c,v 1.39 2017/11/28 06:55:49 tb Exp $ */
/* $OpenBSD: __mktemp4.c,v 1.1 2024/01/19 19:45:02 millert Exp $ */
/*
* Copyright (c) 1996-1998, 2008 Theo de Raadt
* Copyright (c) 1997, 2008-2009 Todd C. Miller
* Copyright (c) 1997, 2008-2009, 2024 Todd C. Miller
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@ -16,45 +16,37 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#define MKTEMP_NAME 0
#define MKTEMP_FILE 1
#define MKTEMP_DIR 2
#define TEMPCHARS "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
#define NUM_CHARS (sizeof(TEMPCHARS) - 1)
#define MIN_X 6
#define MKOTEMP_FLAGS (O_APPEND | O_CLOEXEC | O_DSYNC | O_RSYNC | O_SYNC)
#ifndef nitems
#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
#endif
static int
mktemp_internal(char *path, int slen, int mode, int flags)
/*
* Internal driver for the mktemp(3) family of functions.
* The supplied callback does the actual work of testing or
* creating the file/directory.
*/
int
__mktemp4(char *path, int slen, int flags, int (*cb)(const char *, int))
{
char *start, *cp, *ep;
const char tempchars[] = TEMPCHARS;
unsigned int tries;
struct stat sb;
size_t len;
int fd;
int ret;
len = strlen(path);
if (len < MIN_X || slen < 0 || (size_t)slen > len - MIN_X) {
errno = EINVAL;
return(-1);
return -1;
}
ep = path + len - slen;
@ -62,15 +54,9 @@ mktemp_internal(char *path, int slen, int mode, int flags)
;
if (ep - start < MIN_X) {
errno = EINVAL;
return(-1);
return -1;
}
if (flags & ~MKOTEMP_FLAGS) {
errno = EINVAL;
return(-1);
}
flags |= O_CREAT | O_EXCL | O_RDWR;
tries = INT_MAX;
do {
cp = start;
@ -87,77 +73,11 @@ mktemp_internal(char *path, int slen, int mode, int flags)
*cp++ = tempchars[rbuf[i] % NUM_CHARS];
} while (cp != ep);
switch (mode) {
case MKTEMP_NAME:
if (lstat(path, &sb) != 0)
return(errno == ENOENT ? 0 : -1);
break;
case MKTEMP_FILE:
fd = open(path, flags, S_IRUSR|S_IWUSR);
if (fd != -1 || errno != EEXIST)
return(fd);
break;
case MKTEMP_DIR:
if (mkdir(path, S_IRUSR|S_IWUSR|S_IXUSR) == 0)
return(0);
if (errno != EEXIST)
return(-1);
break;
}
ret = cb(path, flags);
if (ret != -1 || errno != EEXIST)
return ret;
} while (--tries);
errno = EEXIST;
return(-1);
}
char *
_mktemp(char *path)
{
if (mktemp_internal(path, 0, MKTEMP_NAME, 0) == -1)
return(NULL);
return(path);
}
__warn_references(mktemp,
"mktemp() possibly used unsafely; consider using mkstemp()");
char *
mktemp(char *path)
{
return(_mktemp(path));
}
int
mkostemps(char *path, int slen, int flags)
{
return(mktemp_internal(path, slen, MKTEMP_FILE, flags));
}
int
mkstemp(char *path)
{
return(mktemp_internal(path, 0, MKTEMP_FILE, 0));
}
DEF_WEAK(mkstemp);
int
mkostemp(char *path, int flags)
{
return(mktemp_internal(path, 0, MKTEMP_FILE, flags));
}
DEF_WEAK(mkostemp);
int
mkstemps(char *path, int slen)
{
return(mktemp_internal(path, slen, MKTEMP_FILE, 0));
}
char *
mkdtemp(char *path)
{
int error;
error = mktemp_internal(path, 0, MKTEMP_DIR, 0);
return(error ? NULL : path);
return -1;
}

33
lib/libc/stdlib/mkdtemp.c Normal file
View file

@ -0,0 +1,33 @@
/* $OpenBSD: mkdtemp.c,v 1.1 2024/01/19 19:45:02 millert Exp $ */
/*
* Copyright (c) 2024 Todd C. Miller
*
* 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 <sys/stat.h>
#include <stdlib.h>
static int
mkdtemp_cb(const char *path, int flags)
{
return mkdir(path, S_IRUSR|S_IWUSR|S_IXUSR);
}
char *
mkdtemp(char *path)
{
if (__mktemp4(path, 0, 0, mkdtemp_cb) == 0)
return path;
return NULL;
}

64
lib/libc/stdlib/mkstemp.c Normal file
View file

@ -0,0 +1,64 @@
/* $OpenBSD: mkstemp.c,v 1.1 2024/01/19 19:45:02 millert Exp $ */
/*
* Copyright (c) 2024 Todd C. Miller
*
* 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 <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#define MKOSTEMP_FLAGS (O_APPEND | O_CLOEXEC | O_DSYNC | O_RSYNC | O_SYNC)
static int
mkstemp_cb(const char *path, int flags)
{
flags |= O_CREAT | O_EXCL | O_RDWR;
return open(path, flags, S_IRUSR|S_IWUSR);
}
int
mkostemps(char *path, int slen, int flags)
{
if (flags & ~MKOSTEMP_FLAGS) {
errno = EINVAL;
return -1;
}
return __mktemp4(path, slen, flags, mkstemp_cb);
}
int
mkostemp(char *path, int flags)
{
if (flags & ~MKOSTEMP_FLAGS) {
errno = EINVAL;
return -1;
}
return __mktemp4(path, 0, flags, mkstemp_cb);
}
DEF_WEAK(mkostemp);
int
mkstemp(char *path)
{
return __mktemp4(path, 0, 0, mkstemp_cb);
}
DEF_WEAK(mkstemp);
int
mkstemps(char *path, int slen)
{
return __mktemp4(path, slen, 0, mkstemp_cb);
}

View file

@ -1,4 +1,4 @@
.\" $OpenBSD: mktemp.3,v 1.56 2022/08/04 06:20:24 jsg Exp $
.\" $OpenBSD: mktemp.3,v 1.1 2024/01/19 16:30:28 millert Exp $
.\"
.\" Copyright (c) 1989, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -27,7 +27,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd $Mdocdate: August 4 2022 $
.Dd $Mdocdate: January 19 2024 $
.Dt MKTEMP 3
.Os
.Sh NAME

48
lib/libc/stdlib/mktemp.c Normal file
View file

@ -0,0 +1,48 @@
/* $OpenBSD: mktemp.c,v 1.2 2024/01/19 19:45:02 millert Exp $ */
/*
* Copyright (c) 2024 Todd C. Miller
*
* 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 <sys/stat.h>
#include <errno.h>
#include <stdlib.h>
static int
mktemp_cb(const char *path, int flags)
{
struct stat sb;
if (lstat(path, &sb) == 0)
errno = EEXIST;
return (errno == ENOENT ? 0 : -1);
}
/* Also called via tmpnam(3) and tempnam(3). */
char *
_mktemp(char *path)
{
if (__mktemp4(path, 0, 0, mktemp_cb) == 0)
return path;
return NULL;
}
__warn_references(mktemp,
"mktemp() possibly used unsafely; consider using mkstemp()");
char *
mktemp(char *path)
{
return _mktemp(path);
}

View file

@ -1,4 +1,4 @@
# $OpenBSD: Makefile.inc,v 1.176 2023/12/12 15:30:55 deraadt Exp $
# $OpenBSD: Makefile.inc,v 1.177 2024/01/19 14:15:51 deraadt Exp $
# $NetBSD: Makefile.inc,v 1.35 1995/10/16 23:49:07 jtc Exp $
# @(#)Makefile.inc 8.1 (Berkeley) 6/17/93
@ -23,23 +23,6 @@ SRCS+= ptrace.c semctl.c \
# stack protector helper functions
SRCS+= stack_protector.c
# Extract execve stub size for static binary pinsyscall(2) in dlfcn/init.c
SRCS+= _execvesize.c
CLEANFILES+=_execvesize.c
_execvesize.c: execve.o execve.po
readelf -s execve.po | awk \
'/ execve$$/{ printf("#ifdef _PROFILE\nconst int _execve_size = %d;\n", $$3); }' > $@
readelf -s execve.o | awk \
'/ execve$$/{ printf("#else\nconst int _execve_size = %d;\n#endif\n", $$3); }' >> $@
# _libc_preinit() needs to know if compiled with or without profiling
_execvesize.po:
@echo "${COMPILE.c} -D_PROFILE ${.IMPSRC} -o ${.TARGET}"
@${COMPILE.c} ${DFLAGS} -D_PROFILE ${.IMPSRC} -o ${.TARGET}.o
@-mv $@.d $*.d
@${LD} -X -r ${.TARGET}.o -o ${.TARGET}
@rm -f ${.TARGET}.o
# cancelation details
SRCS+= canceled.c
@ -79,7 +62,7 @@ ASM= __semctl.o __thrsigdivert.o \
mknod.o mknodat.o mlock.o mlockall.o mmap.o mount.o mprotect.o \
mquery.o msgctl.o msgget.o munlock.o munlockall.o munmap.o \
nfssvc.o \
pathconf.o pipe.o pipe2.o pinsyscall.o pledge.o profil.o \
pathconf.o pipe.o pipe2.o pledge.o profil.o \
quotactl.o \
readlink.o readlinkat.o reboot.o \
rename.o renameat.o revoke.o rmdir.o \
@ -208,7 +191,7 @@ MAN+= __get_tcb.2 __thrsigdivert.2 __thrsleep.2 _exit.2 accept.2 \
mimmutable.2 minherit.2 mkdir.2 mkfifo.2 mknod.2 mlock.2 \
mlockall.2 mmap.2 mount.2 mprotect.2 mquery.2 msyscall.2 msgctl.2 \
msgget.2 msgrcv.2 msgsnd.2 msync.2 munmap.2 nanosleep.2 \
nfssvc.2 open.2 pathconf.2 pinsyscall.2 pinsyscalls.2 pipe.2 pledge.2 \
nfssvc.2 open.2 pathconf.2 pinsyscalls.2 pipe.2 pledge.2 \
poll.2 profil.2 ptrace.2 quotactl.2 read.2 readlink.2 reboot.2 recv.2 \
rename.2 revoke.2 rmdir.2 sched_yield.2 select.2 semctl.2 semget.2 \
semop.2 send.2 setgroups.2 setpgid.2 setregid.2 \

View file

@ -1,4 +1,4 @@
/* $OpenBSD: radius.h,v 1.2 2023/07/08 08:53:26 yasuoka Exp $ */
/* $OpenBSD: radius.h,v 1.3 2024/01/19 06:32:28 yasuoka Exp $ */
/*-
* Copyright (c) 2009 Internet Initiative Japan Inc.
@ -141,7 +141,14 @@
#define RADIUS_TYPE_FRAMED_IPV6_PREFIX 97
#define RADIUS_TYPE_LOGIN_IPV6_HOST 98
#define RADIUS_TYPE_FRAMED_IPV6_ROUTE 99
#define RADIUS_TYPE_FRAMED_IPV6_POOL 100
#define RADIUS_TYPE_FRAMED_IPV6_POOL 100
/* RFC 6911 3. Attributes */
#define RADIUS_TYPE_FRAMED_IPV6_ADDRESS 168
#define RADIUS_TYPE_DNS_SERVER_IPV6_ADDRESS 169
#define RADIUS_TYPE_ROUTE_IPV6_INFORMATION 170
#define RADIUS_TYPE_DELEGATED_IPV6_PREFIX_POOL 171
#define RADIUS_TYPE_STATEFUL_IPV6_ADDRESS_POOL 172
/* RFC 2865 5.7. Framed-Protocol */