From b9b725514027a560daae1c5518c700360b5764bc Mon Sep 17 00:00:00 2001 From: deraadt <> Date: Wed, 11 Jun 2014 15:08:43 +0000 Subject: Provide support for non-funopen systems. ok beck --- src/lib/libcrypto/bio/b_print.c | 38 ++++++++++++++++++++++++++------- src/lib/libcrypto/crypto/Makefile | 4 ++-- src/lib/libssl/src/crypto/bio/b_print.c | 38 ++++++++++++++++++++++++++------- 3 files changed, 62 insertions(+), 18 deletions(-) diff --git a/src/lib/libcrypto/bio/b_print.c b/src/lib/libcrypto/bio/b_print.c index 3a8fdcc821..a790bb0b7d 100644 --- a/src/lib/libcrypto/bio/b_print.c +++ b/src/lib/libcrypto/bio/b_print.c @@ -1,14 +1,8 @@ -/* $OpenBSD: b_print.c,v 1.22 2014/04/21 11:18:34 deraadt Exp $ */ +/* $OpenBSD: b_print.c,v 1.23 2014/06/11 15:08:43 deraadt Exp $ */ /* Theo de Raadt places this file in the public domain. */ #include -static int -_BIO_write(void *cookie, const char *buf, int nbytes) -{ - return BIO_write(cookie, buf, nbytes); -} - int BIO_printf(BIO *bio, const char *format, ...) { @@ -21,11 +15,18 @@ BIO_printf(BIO *bio, const char *format, ...) return (ret); } +#ifdef HAVE_FUNOPEN +static int +_BIO_write(void *cookie, const char *buf, int nbytes) +{ + return BIO_write(cookie, buf, nbytes); +} + int BIO_vprintf(BIO *bio, const char *format, va_list args) { - FILE *fp; int ret; + FILE *fp; fp = funopen(bio, NULL, &_BIO_write, NULL, NULL); if (fp == NULL) { @@ -38,6 +39,27 @@ fail: return (ret); } +#else /* !HAVE_FUNOPEN */ + +int +BIO_vprintf(BIO *bio, const char *format, va_list args) +{ + int ret; + char *buf = NULL; + + ret = vasprintf(&buf, format, args); + if (buf == NULL) { + ret = -1 + goto fail; + } + BIO_write(bio, buf, ret); + free(buf); +fail: + return (ret); +} + +#endif /* HAVE_FUNOPEN */ + /* * BIO_snprintf and BIO_vsnprintf return -1 for overflow, * due to the history of this API. Justification: diff --git a/src/lib/libcrypto/crypto/Makefile b/src/lib/libcrypto/crypto/Makefile index e71912dd57..c27985e113 100644 --- a/src/lib/libcrypto/crypto/Makefile +++ b/src/lib/libcrypto/crypto/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.39 2014/06/10 16:15:19 deraadt Exp $ +# $OpenBSD: Makefile,v 1.40 2014/06/11 15:08:41 deraadt Exp $ LIB= crypto @@ -9,7 +9,7 @@ CFLAGS+= -Wall -Werror .include # for 'NOPIC' definition .if !defined(NOPIC) -CFLAGS+= -DDSO_DLFCN -DHAVE_DLFCN_H +CFLAGS+= -DDSO_DLFCN -DHAVE_DLFCN_H -DHAVE_FUNOPEN .endif .if ${MACHINE_ARCH} == "sparc" diff --git a/src/lib/libssl/src/crypto/bio/b_print.c b/src/lib/libssl/src/crypto/bio/b_print.c index 3a8fdcc821..a790bb0b7d 100644 --- a/src/lib/libssl/src/crypto/bio/b_print.c +++ b/src/lib/libssl/src/crypto/bio/b_print.c @@ -1,14 +1,8 @@ -/* $OpenBSD: b_print.c,v 1.22 2014/04/21 11:18:34 deraadt Exp $ */ +/* $OpenBSD: b_print.c,v 1.23 2014/06/11 15:08:43 deraadt Exp $ */ /* Theo de Raadt places this file in the public domain. */ #include -static int -_BIO_write(void *cookie, const char *buf, int nbytes) -{ - return BIO_write(cookie, buf, nbytes); -} - int BIO_printf(BIO *bio, const char *format, ...) { @@ -21,11 +15,18 @@ BIO_printf(BIO *bio, const char *format, ...) return (ret); } +#ifdef HAVE_FUNOPEN +static int +_BIO_write(void *cookie, const char *buf, int nbytes) +{ + return BIO_write(cookie, buf, nbytes); +} + int BIO_vprintf(BIO *bio, const char *format, va_list args) { - FILE *fp; int ret; + FILE *fp; fp = funopen(bio, NULL, &_BIO_write, NULL, NULL); if (fp == NULL) { @@ -38,6 +39,27 @@ fail: return (ret); } +#else /* !HAVE_FUNOPEN */ + +int +BIO_vprintf(BIO *bio, const char *format, va_list args) +{ + int ret; + char *buf = NULL; + + ret = vasprintf(&buf, format, args); + if (buf == NULL) { + ret = -1 + goto fail; + } + BIO_write(bio, buf, ret); + free(buf); +fail: + return (ret); +} + +#endif /* HAVE_FUNOPEN */ + /* * BIO_snprintf and BIO_vsnprintf return -1 for overflow, * due to the history of this API. Justification: -- cgit v1.2.3-55-g6feb