From 0a74a4d4648f8655ad4862f28d995fcf2865b3b2 Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Sun, 27 Jul 2014 06:11:56 -0500 Subject: add strndup/strnlen compat functions from OpenBSD --- .gitignore | 2 ++ configure.ac.tpl | 5 +++++ crypto/Makefile.am.tpl | 5 +++++ include/string.h | 4 ++++ update.sh | 2 +- 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7578eee..26f2783 100644 --- a/.gitignore +++ b/.gitignore @@ -108,6 +108,8 @@ crypto/compat/getentropy_*.c crypto/compat/reallocarray.c crypto/compat/strlcat.c crypto/compat/strlcpy.c +crypto/compat/strndup.c +crypto/compat/strnlen.c crypto/compat/strtonum.c crypto/compat/timingsafe_bcmp.c crypto/compat/timingsafe_memcmp.c diff --git a/configure.ac.tpl b/configure.ac.tpl index 8e85e9b..61476cf 100644 --- a/configure.ac.tpl +++ b/configure.ac.tpl @@ -64,6 +64,11 @@ AC_CHECK_FUNC(strlcat,[AC_SEARCH_LIBS(strlcat,, [NO_STRLCAT=], AC_SUBST(NO_STRLCAT) AM_CONDITIONAL(NO_STRLCAT, test "x$NO_STRLCAT" = "xyes") +AC_CHECK_FUNC(strndup,[AC_SEARCH_LIBS(strndup,, [NO_STRNDUP=], + [NO_STRNDUP=yes])], [NO_STRNDUP=yes]) +AC_SUBST(NO_STRNDUP) +AM_CONDITIONAL(NO_STRNDUP, test "x$NO_STRNDUP" = "xyes") + AC_CHECK_FUNC(reallocarray,[AC_SEARCH_LIBS(reallocarray,, [NO_REALLOCARRAY=], [NO_REALLOCARRAY=yes])], [NO_REALLOCARRAY=yes]) AC_SUBST(NO_REALLOCARRAY) diff --git a/crypto/Makefile.am.tpl b/crypto/Makefile.am.tpl index a29e07f..6ac6c4f 100644 --- a/crypto/Makefile.am.tpl +++ b/crypto/Makefile.am.tpl @@ -33,6 +33,11 @@ if NO_STRLCPY libcompat_la_SOURCES += compat/strlcpy.c endif +if NO_STRNDUP +libcompat_la_SOURCES += compat/strndup.c +libcompat_la_SOURCES += compat/strnlen.c +endif + if NO_REALLOCARRAY libcompat_la_SOURCES += compat/reallocarray.c endif diff --git a/include/string.h b/include/string.h index 6277247..cd3430a 100644 --- a/include/string.h +++ b/include/string.h @@ -16,6 +16,10 @@ size_t strlcpy(char *dst, const char *src, size_t siz); size_t strlcat(char *dst, const char *src, size_t siz); +char * strndup(const char *str, size_t maxlen); + +size_t strnlen(const char *str, size_t maxlen); + void explicit_bzero(void *, size_t); int timingsafe_bcmp(const void *b1, const void *b2, size_t n); diff --git a/update.sh b/update.sh index 290e06d..30c2286 100755 --- a/update.sh +++ b/update.sh @@ -64,7 +64,7 @@ $CP $libssl_src/src/crypto/opensslfeatures.h include/openssl $CP $libssl_src/src/e_os2.h include/openssl $CP $libssl_src/src/ssl/pqueue.h include -for i in explicit_bzero.c strlcpy.c strlcat.c timingsafe_bcmp.c timingsafe_memcmp.c; do +for i in explicit_bzero.c strlcpy.c strlcat.c strndup.c strnlen.c timingsafe_bcmp.c timingsafe_memcmp.c; do $CP $libc_src/string/$i crypto/compat done $CP $libc_src/stdlib/reallocarray.c crypto/compat -- cgit v1.2.3-55-g6feb