Add explicit_bzero()

This function is used by LibreSSL and OpenSSH and is provided by the
OpenBSD libc.

	* libc/include/string.h (explicit_bzero): Declare.
	* libc/string/explicit_bzero.c: New file.
	* libc/string/Makefile.am: Add new file.
	* libc/string/Makefile.in: Regenerate.
This commit is contained in:
Sebastian Huber 2016-03-18 11:49:25 +01:00 committed by Corinna Vinschen
parent a10dacbdac
commit 8740fa7fd0
4 changed files with 75 additions and 46 deletions

View File

@ -51,6 +51,9 @@ int _EXFUN(bcmp,(const void *, const void *, size_t));
void _EXFUN(bcopy,(const void *, void *, size_t)); void _EXFUN(bcopy,(const void *, void *, size_t));
void _EXFUN(bzero,(void *, size_t)); void _EXFUN(bzero,(void *, size_t));
#endif #endif
#if __BSD_VISIBLE
void _EXFUN(explicit_bzero,(void *, size_t));
#endif
#if __MISC_VISIBLE || __POSIX_VISIBLE >= 200809 #if __MISC_VISIBLE || __POSIX_VISIBLE >= 200809
int _EXFUN(ffs,(int)); int _EXFUN(ffs,(int));
#endif #endif

View File

@ -7,6 +7,7 @@ INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
GENERAL_SOURCES = \ GENERAL_SOURCES = \
bcopy.c \ bcopy.c \
bzero.c \ bzero.c \
explicit_bzero.c \
index.c \ index.c \
memchr.c \ memchr.c \
memcmp.c \ memcmp.c \

View File

@ -73,39 +73,40 @@ ARFLAGS = cru
lib_a_AR = $(AR) $(ARFLAGS) lib_a_AR = $(AR) $(ARFLAGS)
lib_a_LIBADD = lib_a_LIBADD =
am__objects_1 = lib_a-bcopy.$(OBJEXT) lib_a-bzero.$(OBJEXT) \ am__objects_1 = lib_a-bcopy.$(OBJEXT) lib_a-bzero.$(OBJEXT) \
lib_a-index.$(OBJEXT) lib_a-memchr.$(OBJEXT) \ lib_a-explicit_bzero.$(OBJEXT) lib_a-index.$(OBJEXT) \
lib_a-memcmp.$(OBJEXT) lib_a-memcpy.$(OBJEXT) \ lib_a-memchr.$(OBJEXT) lib_a-memcmp.$(OBJEXT) \
lib_a-memmove.$(OBJEXT) lib_a-memset.$(OBJEXT) \ lib_a-memcpy.$(OBJEXT) lib_a-memmove.$(OBJEXT) \
lib_a-rindex.$(OBJEXT) lib_a-strcasecmp.$(OBJEXT) \ lib_a-memset.$(OBJEXT) lib_a-rindex.$(OBJEXT) \
lib_a-strcat.$(OBJEXT) lib_a-strchr.$(OBJEXT) \ lib_a-strcasecmp.$(OBJEXT) lib_a-strcat.$(OBJEXT) \
lib_a-strcmp.$(OBJEXT) lib_a-strcoll.$(OBJEXT) \ lib_a-strchr.$(OBJEXT) lib_a-strcmp.$(OBJEXT) \
lib_a-strcpy.$(OBJEXT) lib_a-strcspn.$(OBJEXT) \ lib_a-strcoll.$(OBJEXT) lib_a-strcpy.$(OBJEXT) \
lib_a-strdup.$(OBJEXT) lib_a-strdup_r.$(OBJEXT) \ lib_a-strcspn.$(OBJEXT) lib_a-strdup.$(OBJEXT) \
lib_a-strerror.$(OBJEXT) lib_a-strerror_r.$(OBJEXT) \ lib_a-strdup_r.$(OBJEXT) lib_a-strerror.$(OBJEXT) \
lib_a-strlcat.$(OBJEXT) lib_a-strlcpy.$(OBJEXT) \ lib_a-strerror_r.$(OBJEXT) lib_a-strlcat.$(OBJEXT) \
lib_a-strlen.$(OBJEXT) lib_a-strlwr.$(OBJEXT) \ lib_a-strlcpy.$(OBJEXT) lib_a-strlen.$(OBJEXT) \
lib_a-strncasecmp.$(OBJEXT) lib_a-strncat.$(OBJEXT) \ lib_a-strlwr.$(OBJEXT) lib_a-strncasecmp.$(OBJEXT) \
lib_a-strncmp.$(OBJEXT) lib_a-strncpy.$(OBJEXT) \ lib_a-strncat.$(OBJEXT) lib_a-strncmp.$(OBJEXT) \
lib_a-strnlen.$(OBJEXT) lib_a-strpbrk.$(OBJEXT) \ lib_a-strncpy.$(OBJEXT) lib_a-strnlen.$(OBJEXT) \
lib_a-strrchr.$(OBJEXT) lib_a-strsep.$(OBJEXT) \ lib_a-strpbrk.$(OBJEXT) lib_a-strrchr.$(OBJEXT) \
lib_a-strsignal.$(OBJEXT) lib_a-strspn.$(OBJEXT) \ lib_a-strsep.$(OBJEXT) lib_a-strsignal.$(OBJEXT) \
lib_a-strtok.$(OBJEXT) lib_a-strtok_r.$(OBJEXT) \ lib_a-strspn.$(OBJEXT) lib_a-strtok.$(OBJEXT) \
lib_a-strupr.$(OBJEXT) lib_a-strxfrm.$(OBJEXT) \ lib_a-strtok_r.$(OBJEXT) lib_a-strupr.$(OBJEXT) \
lib_a-strstr.$(OBJEXT) lib_a-swab.$(OBJEXT) \ lib_a-strxfrm.$(OBJEXT) lib_a-strstr.$(OBJEXT) \
lib_a-u_strerr.$(OBJEXT) lib_a-wcscat.$(OBJEXT) \ lib_a-swab.$(OBJEXT) lib_a-u_strerr.$(OBJEXT) \
lib_a-wcschr.$(OBJEXT) lib_a-wcscmp.$(OBJEXT) \ lib_a-wcscat.$(OBJEXT) lib_a-wcschr.$(OBJEXT) \
lib_a-wcscoll.$(OBJEXT) lib_a-wcscpy.$(OBJEXT) \ lib_a-wcscmp.$(OBJEXT) lib_a-wcscoll.$(OBJEXT) \
lib_a-wcscspn.$(OBJEXT) lib_a-wcslcat.$(OBJEXT) \ lib_a-wcscpy.$(OBJEXT) lib_a-wcscspn.$(OBJEXT) \
lib_a-wcslcpy.$(OBJEXT) lib_a-wcslen.$(OBJEXT) \ lib_a-wcslcat.$(OBJEXT) lib_a-wcslcpy.$(OBJEXT) \
lib_a-wcsncat.$(OBJEXT) lib_a-wcsncmp.$(OBJEXT) \ lib_a-wcslen.$(OBJEXT) lib_a-wcsncat.$(OBJEXT) \
lib_a-wcsncpy.$(OBJEXT) lib_a-wcsnlen.$(OBJEXT) \ lib_a-wcsncmp.$(OBJEXT) lib_a-wcsncpy.$(OBJEXT) \
lib_a-wcspbrk.$(OBJEXT) lib_a-wcsrchr.$(OBJEXT) \ lib_a-wcsnlen.$(OBJEXT) lib_a-wcspbrk.$(OBJEXT) \
lib_a-wcsspn.$(OBJEXT) lib_a-wcsstr.$(OBJEXT) \ lib_a-wcsrchr.$(OBJEXT) lib_a-wcsspn.$(OBJEXT) \
lib_a-wcstok.$(OBJEXT) lib_a-wcswidth.$(OBJEXT) \ lib_a-wcsstr.$(OBJEXT) lib_a-wcstok.$(OBJEXT) \
lib_a-wcsxfrm.$(OBJEXT) lib_a-wcwidth.$(OBJEXT) \ lib_a-wcswidth.$(OBJEXT) lib_a-wcsxfrm.$(OBJEXT) \
lib_a-wmemchr.$(OBJEXT) lib_a-wmemcmp.$(OBJEXT) \ lib_a-wcwidth.$(OBJEXT) lib_a-wmemchr.$(OBJEXT) \
lib_a-wmemcpy.$(OBJEXT) lib_a-wmemmove.$(OBJEXT) \ lib_a-wmemcmp.$(OBJEXT) lib_a-wmemcpy.$(OBJEXT) \
lib_a-wmemset.$(OBJEXT) lib_a-xpg_strerror_r.$(OBJEXT) lib_a-wmemmove.$(OBJEXT) lib_a-wmemset.$(OBJEXT) \
lib_a-xpg_strerror_r.$(OBJEXT)
@ELIX_LEVEL_1_FALSE@am__objects_2 = lib_a-bcmp.$(OBJEXT) \ @ELIX_LEVEL_1_FALSE@am__objects_2 = lib_a-bcmp.$(OBJEXT) \
@ELIX_LEVEL_1_FALSE@ lib_a-memccpy.$(OBJEXT) \ @ELIX_LEVEL_1_FALSE@ lib_a-memccpy.$(OBJEXT) \
@ELIX_LEVEL_1_FALSE@ lib_a-mempcpy.$(OBJEXT) \ @ELIX_LEVEL_1_FALSE@ lib_a-mempcpy.$(OBJEXT) \
@ -129,19 +130,20 @@ am__objects_1 = lib_a-bcopy.$(OBJEXT) lib_a-bzero.$(OBJEXT) \
lib_a_OBJECTS = $(am_lib_a_OBJECTS) lib_a_OBJECTS = $(am_lib_a_OBJECTS)
LTLIBRARIES = $(noinst_LTLIBRARIES) LTLIBRARIES = $(noinst_LTLIBRARIES)
libstring_la_LIBADD = libstring_la_LIBADD =
am__objects_4 = bcopy.lo bzero.lo index.lo memchr.lo memcmp.lo \ am__objects_4 = bcopy.lo bzero.lo explicit_bzero.lo index.lo memchr.lo \
memcpy.lo memmove.lo memset.lo rindex.lo strcasecmp.lo \ memcmp.lo memcpy.lo memmove.lo memset.lo rindex.lo \
strcat.lo strchr.lo strcmp.lo strcoll.lo strcpy.lo strcspn.lo \ strcasecmp.lo strcat.lo strchr.lo strcmp.lo strcoll.lo \
strdup.lo strdup_r.lo strerror.lo strerror_r.lo strlcat.lo \ strcpy.lo strcspn.lo strdup.lo strdup_r.lo strerror.lo \
strlcpy.lo strlen.lo strlwr.lo strncasecmp.lo strncat.lo \ strerror_r.lo strlcat.lo strlcpy.lo strlen.lo strlwr.lo \
strncmp.lo strncpy.lo strnlen.lo strpbrk.lo strrchr.lo \ strncasecmp.lo strncat.lo strncmp.lo strncpy.lo strnlen.lo \
strsep.lo strsignal.lo strspn.lo strtok.lo strtok_r.lo \ strpbrk.lo strrchr.lo strsep.lo strsignal.lo strspn.lo \
strupr.lo strxfrm.lo strstr.lo swab.lo u_strerr.lo wcscat.lo \ strtok.lo strtok_r.lo strupr.lo strxfrm.lo strstr.lo swab.lo \
wcschr.lo wcscmp.lo wcscoll.lo wcscpy.lo wcscspn.lo wcslcat.lo \ u_strerr.lo wcscat.lo wcschr.lo wcscmp.lo wcscoll.lo wcscpy.lo \
wcslcpy.lo wcslen.lo wcsncat.lo wcsncmp.lo wcsncpy.lo \ wcscspn.lo wcslcat.lo wcslcpy.lo wcslen.lo wcsncat.lo \
wcsnlen.lo wcspbrk.lo wcsrchr.lo wcsspn.lo wcsstr.lo wcstok.lo \ wcsncmp.lo wcsncpy.lo wcsnlen.lo wcspbrk.lo wcsrchr.lo \
wcswidth.lo wcsxfrm.lo wcwidth.lo wmemchr.lo wmemcmp.lo \ wcsspn.lo wcsstr.lo wcstok.lo wcswidth.lo wcsxfrm.lo \
wmemcpy.lo wmemmove.lo wmemset.lo xpg_strerror_r.lo wcwidth.lo wmemchr.lo wmemcmp.lo wmemcpy.lo wmemmove.lo \
wmemset.lo xpg_strerror_r.lo
@ELIX_LEVEL_1_FALSE@am__objects_5 = bcmp.lo memccpy.lo mempcpy.lo \ @ELIX_LEVEL_1_FALSE@am__objects_5 = bcmp.lo memccpy.lo mempcpy.lo \
@ELIX_LEVEL_1_FALSE@ stpcpy.lo stpncpy.lo strndup.lo \ @ELIX_LEVEL_1_FALSE@ stpcpy.lo stpncpy.lo strndup.lo \
@ELIX_LEVEL_1_FALSE@ strcasestr.lo strchrnul.lo strndup_r.lo \ @ELIX_LEVEL_1_FALSE@ strcasestr.lo strchrnul.lo strndup_r.lo \
@ -329,6 +331,7 @@ INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
GENERAL_SOURCES = \ GENERAL_SOURCES = \
bcopy.c \ bcopy.c \
bzero.c \ bzero.c \
explicit_bzero.c \
index.c \ index.c \
memchr.c \ memchr.c \
memcmp.c \ memcmp.c \
@ -537,6 +540,12 @@ lib_a-bzero.o: bzero.c
lib_a-bzero.obj: bzero.c lib_a-bzero.obj: bzero.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-bzero.obj `if test -f 'bzero.c'; then $(CYGPATH_W) 'bzero.c'; else $(CYGPATH_W) '$(srcdir)/bzero.c'; fi` $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-bzero.obj `if test -f 'bzero.c'; then $(CYGPATH_W) 'bzero.c'; else $(CYGPATH_W) '$(srcdir)/bzero.c'; fi`
lib_a-explicit_bzero.o: explicit_bzero.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-explicit_bzero.o `test -f 'explicit_bzero.c' || echo '$(srcdir)/'`explicit_bzero.c
lib_a-explicit_bzero.obj: explicit_bzero.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-explicit_bzero.obj `if test -f 'explicit_bzero.c'; then $(CYGPATH_W) 'explicit_bzero.c'; else $(CYGPATH_W) '$(srcdir)/explicit_bzero.c'; fi`
lib_a-index.o: index.c lib_a-index.o: index.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-index.o `test -f 'index.c' || echo '$(srcdir)/'`index.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-index.o `test -f 'index.c' || echo '$(srcdir)/'`index.c

View File

@ -0,0 +1,16 @@
/* $OpenBSD: explicit_bzero.c,v 1.2 2014/06/10 04:17:37 deraadt Exp $ */
/*
* Public domain.
* Written by Ted Unangst
*/
#include <string.h>
/*
* explicit_bzero - don't let the compiler optimize away bzero
*/
void
explicit_bzero(void *p, size_t n)
{
bzero(p, n);
}