summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libcrypto/Symbols.list3
-rw-r--r--src/lib/libcrypto/Symbols.namespace3
-rw-r--r--src/lib/libcrypto/bio/b_print.c59
-rw-r--r--src/lib/libcrypto/bio/bio.h18
-rw-r--r--src/lib/libcrypto/bio/bio_local.h6
-rw-r--r--src/lib/libcrypto/bn/bn_print.c3
-rw-r--r--src/lib/libcrypto/hidden/openssl/bio.h5
-rw-r--r--src/lib/libcrypto/man/BIO_printf.359
8 files changed, 18 insertions, 138 deletions
diff --git a/src/lib/libcrypto/Symbols.list b/src/lib/libcrypto/Symbols.list
index a801880ecc..7877295ccb 100644
--- a/src/lib/libcrypto/Symbols.list
+++ b/src/lib/libcrypto/Symbols.list
@@ -332,7 +332,6 @@ BIO_set_next
332BIO_set_retry_reason 332BIO_set_retry_reason
333BIO_set_shutdown 333BIO_set_shutdown
334BIO_set_tcp_ndelay 334BIO_set_tcp_ndelay
335BIO_snprintf
336BIO_sock_cleanup 335BIO_sock_cleanup
337BIO_sock_error 336BIO_sock_error
338BIO_sock_init 337BIO_sock_init
@@ -343,8 +342,6 @@ BIO_socket_nbio
343BIO_test_flags 342BIO_test_flags
344BIO_up_ref 343BIO_up_ref
345BIO_vfree 344BIO_vfree
346BIO_vprintf
347BIO_vsnprintf
348BIO_write 345BIO_write
349BN_CTX_end 346BN_CTX_end
350BN_CTX_free 347BN_CTX_free
diff --git a/src/lib/libcrypto/Symbols.namespace b/src/lib/libcrypto/Symbols.namespace
index c35225e798..04ea27935c 100644
--- a/src/lib/libcrypto/Symbols.namespace
+++ b/src/lib/libcrypto/Symbols.namespace
@@ -1215,9 +1215,6 @@ _libre_BIO_new_connect
1215_libre_BIO_new_accept 1215_libre_BIO_new_accept
1216_libre_BIO_copy_next_retry 1216_libre_BIO_copy_next_retry
1217_libre_BIO_printf 1217_libre_BIO_printf
1218_libre_BIO_vprintf
1219_libre_BIO_snprintf
1220_libre_BIO_vsnprintf
1221_libre_ERR_load_BIO_strings 1218_libre_ERR_load_BIO_strings
1222_libre_ASN1_item_ex_new 1219_libre_ASN1_item_ex_new
1223_libre_ASN1_item_ex_free 1220_libre_ASN1_item_ex_free
diff --git a/src/lib/libcrypto/bio/b_print.c b/src/lib/libcrypto/bio/b_print.c
index a750ac413f..f6943ea3f3 100644
--- a/src/lib/libcrypto/bio/b_print.c
+++ b/src/lib/libcrypto/bio/b_print.c
@@ -1,21 +1,10 @@
1/* $OpenBSD: b_print.c,v 1.27 2023/07/05 21:23:37 beck Exp $ */ 1/* $OpenBSD: b_print.c,v 1.28 2024/03/02 09:18:28 tb Exp $ */
2 2
3/* Theo de Raadt places this file in the public domain. */ 3/* Theo de Raadt places this file in the public domain. */
4 4
5#include <openssl/bio.h> 5#include <openssl/bio.h>
6 6
7int 7#include "bio_local.h"
8BIO_printf(BIO *bio, const char *format, ...)
9{
10 va_list args;
11 int ret;
12
13 va_start(args, format);
14 ret = BIO_vprintf(bio, format, args);
15 va_end(args);
16 return (ret);
17}
18LCRYPTO_ALIAS(BIO_printf);
19 8
20#ifdef HAVE_FUNOPEN 9#ifdef HAVE_FUNOPEN
21static int 10static int
@@ -40,7 +29,6 @@ BIO_vprintf(BIO *bio, const char *format, va_list args)
40fail: 29fail:
41 return (ret); 30 return (ret);
42} 31}
43LCRYPTO_ALIAS(BIO_vprintf);
44 32
45#else /* !HAVE_FUNOPEN */ 33#else /* !HAVE_FUNOPEN */
46 34
@@ -57,55 +45,18 @@ BIO_vprintf(BIO *bio, const char *format, va_list args)
57 free(buf); 45 free(buf);
58 return (ret); 46 return (ret);
59} 47}
60LCRYPTO_ALIAS(BIO_vprintf);
61 48
62#endif /* HAVE_FUNOPEN */ 49#endif /* HAVE_FUNOPEN */
63 50
64/*
65 * BIO_snprintf and BIO_vsnprintf return -1 for overflow,
66 * due to the history of this API. Justification:
67 *
68 * Traditional snprintf surfaced in 4.4BSD, and returned
69 * "number of bytes wanted". Solaris and Windows opted to
70 * return -1. A draft standard was written which returned -1.
71 * Due to the large volume of code already using the first
72 * semantics, the draft was repaired before standardization to
73 * specify "number of bytes wanted" plus "-1 for character conversion
74 * style errors". Solaris adapted to this rule, but Windows stuck
75 * with -1.
76 *
77 * Original OpenSSL comment which is full of lies:
78 *
79 * "In case of truncation, return -1 like traditional snprintf.
80 * (Current drafts for ISO/IEC 9899 say snprintf should return
81 * the number of characters that would have been written,
82 * had the buffer been large enough.)"
83 */
84int 51int
85BIO_snprintf(char *buf, size_t n, const char *format, ...) 52BIO_printf(BIO *bio, const char *format, ...)
86{ 53{
87 va_list args; 54 va_list args;
88 int ret; 55 int ret;
89 56
90 va_start(args, format); 57 va_start(args, format);
91 ret = vsnprintf(buf, n, format, args); 58 ret = BIO_vprintf(bio, format, args);
92 va_end(args); 59 va_end(args);
93
94 if (ret >= n || ret == -1)
95 return (-1);
96 return (ret);
97}
98LCRYPTO_ALIAS(BIO_snprintf);
99
100int
101BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)
102{
103 int ret;
104
105 ret = vsnprintf(buf, n, format, args);
106
107 if (ret >= n || ret == -1)
108 return (-1);
109 return (ret); 60 return (ret);
110} 61}
111LCRYPTO_ALIAS(BIO_vsnprintf); 62LCRYPTO_ALIAS(BIO_printf);
diff --git a/src/lib/libcrypto/bio/bio.h b/src/lib/libcrypto/bio/bio.h
index b955524c45..10b0924f73 100644
--- a/src/lib/libcrypto/bio/bio.h
+++ b/src/lib/libcrypto/bio/bio.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bio.h,v 1.60 2023/08/25 12:37:33 schwarze Exp $ */ 1/* $OpenBSD: bio.h,v 1.61 2024/03/02 09:18:28 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -648,25 +648,9 @@ void BIO_copy_next_retry(BIO *b);
648#ifndef __MINGW_PRINTF_FORMAT 648#ifndef __MINGW_PRINTF_FORMAT
649int BIO_printf(BIO *bio, const char *format, ...) 649int BIO_printf(BIO *bio, const char *format, ...)
650 __attribute__((__format__(__printf__, 2, 3), __nonnull__(2))); 650 __attribute__((__format__(__printf__, 2, 3), __nonnull__(2)));
651int BIO_vprintf(BIO *bio, const char *format, va_list args)
652 __attribute__((__format__(__printf__, 2, 0), __nonnull__(2)));
653int BIO_snprintf(char *buf, size_t n, const char *format, ...)
654 __attribute__((__deprecated__, __format__(__printf__, 3, 4),
655 __nonnull__(3)));
656int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)
657 __attribute__((__deprecated__, __format__(__printf__, 3, 0),
658 __nonnull__(3)));
659#else 651#else
660int BIO_printf(BIO *bio, const char *format, ...) 652int BIO_printf(BIO *bio, const char *format, ...)
661 __attribute__((__format__(__MINGW_PRINTF_FORMAT, 2, 3), __nonnull__(2))); 653 __attribute__((__format__(__MINGW_PRINTF_FORMAT, 2, 3), __nonnull__(2)));
662int BIO_vprintf(BIO *bio, const char *format, va_list args)
663 __attribute__((__format__(__MINGW_PRINTF_FORMAT, 2, 0), __nonnull__(2)));
664int BIO_snprintf(char *buf, size_t n, const char *format, ...)
665 __attribute__((__deprecated__, __format__(__MINGW_PRINTF_FORMAT, 3, 4),
666 __nonnull__(3)));
667int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)
668 __attribute__((__deprecated__, __format__(__MINGW_PRINTF_FORMAT, 3, 0),
669 __nonnull__(3)));
670#endif 654#endif
671 655
672void ERR_load_BIO_strings(void); 656void ERR_load_BIO_strings(void);
diff --git a/src/lib/libcrypto/bio/bio_local.h b/src/lib/libcrypto/bio/bio_local.h
index 4eecf7e04a..f59b5756c9 100644
--- a/src/lib/libcrypto/bio/bio_local.h
+++ b/src/lib/libcrypto/bio/bio_local.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bio_local.h,v 1.5 2022/12/02 19:44:04 tb Exp $ */ 1/* $OpenBSD: bio_local.h,v 1.6 2024/03/02 09:18:28 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -59,6 +59,8 @@
59#ifndef HEADER_BIO_LOCAL_H 59#ifndef HEADER_BIO_LOCAL_H
60#define HEADER_BIO_LOCAL_H 60#define HEADER_BIO_LOCAL_H
61 61
62#include <stdarg.h>
63
62__BEGIN_HIDDEN_DECLS 64__BEGIN_HIDDEN_DECLS
63 65
64struct bio_method_st { 66struct bio_method_st {
@@ -118,6 +120,8 @@ typedef struct bio_f_buffer_ctx_struct {
118 int obuf_off; /* write/read offset */ 120 int obuf_off; /* write/read offset */
119} BIO_F_BUFFER_CTX; 121} BIO_F_BUFFER_CTX;
120 122
123int BIO_vprintf(BIO *bio, const char *format, va_list args);
124
121__END_HIDDEN_DECLS 125__END_HIDDEN_DECLS
122 126
123#endif /* !HEADER_BIO_LOCAL_H */ 127#endif /* !HEADER_BIO_LOCAL_H */
diff --git a/src/lib/libcrypto/bn/bn_print.c b/src/lib/libcrypto/bn/bn_print.c
index e7678f7a99..cd8b663602 100644
--- a/src/lib/libcrypto/bn/bn_print.c
+++ b/src/lib/libcrypto/bn/bn_print.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_print.c,v 1.46 2023/07/22 17:14:08 tb Exp $ */ 1/* $OpenBSD: bn_print.c,v 1.47 2024/03/02 09:18:28 tb Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2023 Theo Buehler <tb@openbsd.org> 4 * Copyright (c) 2023 Theo Buehler <tb@openbsd.org>
@@ -25,6 +25,7 @@
25#include <openssl/bio.h> 25#include <openssl/bio.h>
26#include <openssl/bn.h> 26#include <openssl/bn.h>
27 27
28#include "bio_local.h"
28#include "bn_local.h" 29#include "bn_local.h"
29#include "bytestring.h" 30#include "bytestring.h"
30 31
diff --git a/src/lib/libcrypto/hidden/openssl/bio.h b/src/lib/libcrypto/hidden/openssl/bio.h
index f7e7cd3d8e..6166471306 100644
--- a/src/lib/libcrypto/hidden/openssl/bio.h
+++ b/src/lib/libcrypto/hidden/openssl/bio.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bio.h,v 1.4 2023/07/28 10:13:50 tb Exp $ */ 1/* $OpenBSD: bio.h,v 1.5 2024/03/02 09:18:28 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2023 Bob Beck <beck@openbsd.org> 3 * Copyright (c) 2023 Bob Beck <beck@openbsd.org>
4 * 4 *
@@ -138,9 +138,6 @@ LCRYPTO_USED(BIO_new_connect);
138LCRYPTO_USED(BIO_new_accept); 138LCRYPTO_USED(BIO_new_accept);
139LCRYPTO_USED(BIO_copy_next_retry); 139LCRYPTO_USED(BIO_copy_next_retry);
140LCRYPTO_USED(BIO_printf); 140LCRYPTO_USED(BIO_printf);
141LCRYPTO_USED(BIO_vprintf);
142LCRYPTO_USED(BIO_snprintf);
143LCRYPTO_USED(BIO_vsnprintf);
144LCRYPTO_USED(ERR_load_BIO_strings); 141LCRYPTO_USED(ERR_load_BIO_strings);
145 142
146#endif /* _LIBCRYPTO_BIO_H */ 143#endif /* _LIBCRYPTO_BIO_H */
diff --git a/src/lib/libcrypto/man/BIO_printf.3 b/src/lib/libcrypto/man/BIO_printf.3
index 838b771be7..32dec0a828 100644
--- a/src/lib/libcrypto/man/BIO_printf.3
+++ b/src/lib/libcrypto/man/BIO_printf.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: BIO_printf.3,v 1.3 2018/03/22 17:11:04 schwarze Exp $ 1.\" $OpenBSD: BIO_printf.3,v 1.4 2024/03/02 09:18:28 tb Exp $
2.\" OpenSSL 2ca2e917 Mon Mar 20 16:25:22 2017 -0400 2.\" OpenSSL 2ca2e917 Mon Mar 20 16:25:22 2017 -0400
3.\" 3.\"
4.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> 4.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -15,14 +15,11 @@
15.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17.\" 17.\"
18.Dd $Mdocdate: March 22 2018 $ 18.Dd $Mdocdate: March 2 2024 $
19.Dt BIO_PRINTF 3 19.Dt BIO_PRINTF 3
20.Os 20.Os
21.Sh NAME 21.Sh NAME
22.Nm BIO_printf , 22.Nm BIO_printf
23.Nm BIO_vprintf ,
24.Nm BIO_snprintf ,
25.Nm BIO_vsnprintf
26.Nd formatted output to a BIO 23.Nd formatted output to a BIO
27.Sh SYNOPSIS 24.Sh SYNOPSIS
28.In openssl/bio.h 25.In openssl/bio.h
@@ -32,66 +29,18 @@
32.Fa "const char *format" 29.Fa "const char *format"
33.Fa ... 30.Fa ...
34.Fc 31.Fc
35.Ft int
36.Fo BIO_vprintf
37.Fa "BIO *bio"
38.Fa "const char *format"
39.Fa "va_list args"
40.Fc
41.Ft int
42.Fo BIO_snprintf
43.Fa "char *buf"
44.Fa "size_t n"
45.Fa "const char *format"
46.Fa ...
47.Fc
48.Ft int
49.Fo BIO_vsnprintf
50.Fa "char *buf"
51.Fa "size_t n"
52.Fa "const char *format"
53.Fa "va_list args"
54.Fc
55.Sh DESCRIPTION 32.Sh DESCRIPTION
56.Fn BIO_vprintf 33.Fn BIO_printf
57is a wrapper around 34is a wrapper around
58.Xr vfprintf 3 , 35.Xr vfprintf 3 ,
59sending the output to the specified 36sending the output to the specified
60.Fa bio . 37.Fa bio .
61.Pp
62.Fn BIO_printf
63is a wrapper around
64.Fn BIO_vprintf .
65.Pp
66.Fn BIO_snprintf
67and
68.Fn BIO_vsnprintf
69are wrappers around
70.Xr vsnprintf 3 .
71.Sh RETURN VALUES 38.Sh RETURN VALUES
72These functions return the number of bytes written, 39These functions return the number of bytes written,
73or -1 if an error occurs. 40or -1 if an error occurs.
74.Pp
75In contrast to
76.Xr snprintf 3
77and
78.Xr vsnprintf 3 ,
79.Fn BIO_snprintf
80and
81.Fn BIO_vsnprintf
82also return -1 if
83.Fa n
84is too small to hold the complete output.
85.Sh SEE ALSO 41.Sh SEE ALSO
86.Xr BIO_new 3 42.Xr BIO_new 3
87.Sh HISTORY 43.Sh HISTORY
88.Fn BIO_printf 44.Fn BIO_printf
89first appeared in SSLeay 0.6.5 and has been available since 45first appeared in SSLeay 0.6.5 and has been available since
90.Ox 2.4 . 46.Ox 2.4 .
91.Pp
92.Fn BIO_vprintf ,
93.Fn BIO_snprintf ,
94and
95.Fn BIO_vsnprintf
96first appeared in OpenSSL 0.9.6 and have been available since
97.Ox 2.9 .