summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bio
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bio')
-rw-r--r--src/lib/libcrypto/bio/Makefile.ssl127
-rw-r--r--src/lib/libcrypto/bio/b_dump.c122
-rw-r--r--src/lib/libcrypto/bio/b_print.c346
-rw-r--r--src/lib/libcrypto/bio/b_sock.c37
-rw-r--r--src/lib/libcrypto/bio/bf_buff.c52
-rw-r--r--src/lib/libcrypto/bio/bf_lbuf.c397
-rw-r--r--src/lib/libcrypto/bio/bf_nbio.c20
-rw-r--r--src/lib/libcrypto/bio/bf_null.c20
-rw-r--r--src/lib/libcrypto/bio/bio.h66
-rw-r--r--src/lib/libcrypto/bio/bio_err.c7
-rw-r--r--src/lib/libcrypto/bio/bio_lib.c30
-rw-r--r--src/lib/libcrypto/bio/bss_acpt.c24
-rw-r--r--src/lib/libcrypto/bio/bss_bio.c20
-rw-r--r--src/lib/libcrypto/bio/bss_conn.c47
-rw-r--r--src/lib/libcrypto/bio/bss_file.c16
-rw-r--r--src/lib/libcrypto/bio/bss_log.c130
-rw-r--r--src/lib/libcrypto/bio/bss_mem.c33
-rw-r--r--src/lib/libcrypto/bio/bss_null.c16
-rw-r--r--src/lib/libcrypto/bio/bss_rtcp.c16
-rw-r--r--src/lib/libcrypto/bio/bss_sock.c28
20 files changed, 1034 insertions, 520 deletions
diff --git a/src/lib/libcrypto/bio/Makefile.ssl b/src/lib/libcrypto/bio/Makefile.ssl
index 755f255fe4..916d651d47 100644
--- a/src/lib/libcrypto/bio/Makefile.ssl
+++ b/src/lib/libcrypto/bio/Makefile.ssl
@@ -27,11 +27,13 @@ LIBSRC= bio_lib.c bio_cb.c bio_err.c \
27 bss_file.c bss_sock.c bss_conn.c \ 27 bss_file.c bss_sock.c bss_conn.c \
28 bf_null.c bf_buff.c b_print.c b_dump.c \ 28 bf_null.c bf_buff.c b_print.c b_dump.c \
29 b_sock.c bss_acpt.c bf_nbio.c bss_log.c bss_bio.c 29 b_sock.c bss_acpt.c bf_nbio.c bss_log.c bss_bio.c
30# bf_lbuf.c
30LIBOBJ= bio_lib.o bio_cb.o bio_err.o \ 31LIBOBJ= bio_lib.o bio_cb.o bio_err.o \
31 bss_mem.o bss_null.o bss_fd.o \ 32 bss_mem.o bss_null.o bss_fd.o \
32 bss_file.o bss_sock.o bss_conn.o \ 33 bss_file.o bss_sock.o bss_conn.o \
33 bf_null.o bf_buff.o b_print.o b_dump.o \ 34 bf_null.o bf_buff.o b_print.o b_dump.o \
34 b_sock.o bss_acpt.o bf_nbio.o bss_log.o bss_bio.o 35 b_sock.o bss_acpt.o bf_nbio.o bss_log.o bss_bio.o
36# bf_lbuf.o
35 37
36SRC= $(LIBSRC) 38SRC= $(LIBSRC)
37 39
@@ -89,20 +91,23 @@ clean:
89b_dump.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 91b_dump.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
90b_dump.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 92b_dump.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
91b_dump.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 93b_dump.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
92b_dump.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 94b_dump.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
93b_dump.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 95b_dump.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
96b_dump.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
94b_dump.o: ../cryptlib.h 97b_dump.o: ../cryptlib.h
95b_print.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 98b_print.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
96b_print.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 99b_print.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
97b_print.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 100b_print.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
98b_print.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 101b_print.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
99b_print.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 102b_print.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
103b_print.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
100b_print.o: ../cryptlib.h 104b_print.o: ../cryptlib.h
101b_sock.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 105b_sock.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
102b_sock.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 106b_sock.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
103b_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 107b_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
104b_sock.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 108b_sock.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
105b_sock.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 109b_sock.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
110b_sock.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
106b_sock.o: ../cryptlib.h 111b_sock.o: ../cryptlib.h
107bf_buff.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 112bf_buff.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
108bf_buff.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h 113bf_buff.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
@@ -111,14 +116,16 @@ bf_buff.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
111bf_buff.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h 116bf_buff.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
112bf_buff.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 117bf_buff.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
113bf_buff.o: ../../include/openssl/err.h ../../include/openssl/evp.h 118bf_buff.o: ../../include/openssl/err.h ../../include/openssl/evp.h
114bf_buff.o: ../../include/openssl/idea.h ../../include/openssl/md2.h 119bf_buff.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
120bf_buff.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
115bf_buff.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h 121bf_buff.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
116bf_buff.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h 122bf_buff.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
117bf_buff.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h 123bf_buff.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
118bf_buff.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h 124bf_buff.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
119bf_buff.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h 125bf_buff.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
120bf_buff.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h 126bf_buff.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
121bf_buff.o: ../../include/openssl/stack.h ../cryptlib.h 127bf_buff.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
128bf_buff.o: ../../include/openssl/symhacks.h ../cryptlib.h
122bf_nbio.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 129bf_nbio.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
123bf_nbio.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h 130bf_nbio.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
124bf_nbio.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h 131bf_nbio.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
@@ -126,14 +133,16 @@ bf_nbio.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
126bf_nbio.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h 133bf_nbio.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
127bf_nbio.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 134bf_nbio.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
128bf_nbio.o: ../../include/openssl/err.h ../../include/openssl/evp.h 135bf_nbio.o: ../../include/openssl/err.h ../../include/openssl/evp.h
129bf_nbio.o: ../../include/openssl/idea.h ../../include/openssl/md2.h 136bf_nbio.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
137bf_nbio.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
130bf_nbio.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h 138bf_nbio.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
131bf_nbio.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h 139bf_nbio.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
132bf_nbio.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h 140bf_nbio.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
133bf_nbio.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h 141bf_nbio.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
134bf_nbio.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h 142bf_nbio.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
135bf_nbio.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h 143bf_nbio.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
136bf_nbio.o: ../../include/openssl/sha.h ../../include/openssl/stack.h 144bf_nbio.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
145bf_nbio.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
137bf_nbio.o: ../cryptlib.h 146bf_nbio.o: ../cryptlib.h
138bf_null.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 147bf_null.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
139bf_null.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h 148bf_null.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
@@ -142,79 +151,93 @@ bf_null.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
142bf_null.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h 151bf_null.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
143bf_null.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 152bf_null.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
144bf_null.o: ../../include/openssl/err.h ../../include/openssl/evp.h 153bf_null.o: ../../include/openssl/err.h ../../include/openssl/evp.h
145bf_null.o: ../../include/openssl/idea.h ../../include/openssl/md2.h 154bf_null.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
155bf_null.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
146bf_null.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h 156bf_null.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
147bf_null.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h 157bf_null.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
148bf_null.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h 158bf_null.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
149bf_null.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h 159bf_null.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
150bf_null.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h 160bf_null.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
151bf_null.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h 161bf_null.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
152bf_null.o: ../../include/openssl/stack.h ../cryptlib.h 162bf_null.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
163bf_null.o: ../../include/openssl/symhacks.h ../cryptlib.h
153bio_cb.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 164bio_cb.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
154bio_cb.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 165bio_cb.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
155bio_cb.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 166bio_cb.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
156bio_cb.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 167bio_cb.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
157bio_cb.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 168bio_cb.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
169bio_cb.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
158bio_cb.o: ../cryptlib.h 170bio_cb.o: ../cryptlib.h
159bio_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h 171bio_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
160bio_err.o: ../../include/openssl/err.h ../../include/openssl/opensslv.h 172bio_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
161bio_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 173bio_err.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
174bio_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
162bio_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 175bio_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
163bio_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 176bio_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
164bio_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 177bio_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
165bio_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 178bio_lib.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
166bio_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 179bio_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
180bio_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
167bio_lib.o: ../cryptlib.h 181bio_lib.o: ../cryptlib.h
168bss_acpt.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 182bss_acpt.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
169bss_acpt.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 183bss_acpt.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
170bss_acpt.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 184bss_acpt.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
171bss_acpt.o: ../../include/openssl/opensslconf.h 185bss_acpt.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
172bss_acpt.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h 186bss_acpt.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
173bss_acpt.o: ../../include/openssl/stack.h ../cryptlib.h 187bss_acpt.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
188bss_acpt.o: ../cryptlib.h
174bss_bio.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h 189bss_bio.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
175bss_bio.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 190bss_bio.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
176bss_bio.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 191bss_bio.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
177bss_bio.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h 192bss_bio.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
178bss_bio.o: ../../include/openssl/stack.h 193bss_bio.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
194bss_bio.o: ../../include/openssl/symhacks.h
179bss_conn.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 195bss_conn.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
180bss_conn.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 196bss_conn.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
181bss_conn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 197bss_conn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
182bss_conn.o: ../../include/openssl/opensslconf.h 198bss_conn.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
183bss_conn.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h 199bss_conn.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
184bss_conn.o: ../../include/openssl/stack.h ../cryptlib.h 200bss_conn.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
201bss_conn.o: ../cryptlib.h
185bss_fd.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 202bss_fd.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
186bss_fd.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 203bss_fd.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
187bss_fd.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 204bss_fd.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
188bss_fd.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 205bss_fd.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
189bss_fd.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 206bss_fd.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
207bss_fd.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
190bss_fd.o: ../cryptlib.h bss_sock.c 208bss_fd.o: ../cryptlib.h bss_sock.c
191bss_file.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 209bss_file.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
192bss_file.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 210bss_file.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
193bss_file.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 211bss_file.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
194bss_file.o: ../../include/openssl/opensslconf.h 212bss_file.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
195bss_file.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h 213bss_file.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
196bss_file.o: ../../include/openssl/stack.h ../cryptlib.h 214bss_file.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
215bss_file.o: ../cryptlib.h
197bss_log.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 216bss_log.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
198bss_log.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 217bss_log.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
199bss_log.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 218bss_log.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
200bss_log.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 219bss_log.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
201bss_log.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 220bss_log.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
221bss_log.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
202bss_log.o: ../cryptlib.h 222bss_log.o: ../cryptlib.h
203bss_mem.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 223bss_mem.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
204bss_mem.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 224bss_mem.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
205bss_mem.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 225bss_mem.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
206bss_mem.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 226bss_mem.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
207bss_mem.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 227bss_mem.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
228bss_mem.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
208bss_mem.o: ../cryptlib.h 229bss_mem.o: ../cryptlib.h
209bss_null.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 230bss_null.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
210bss_null.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 231bss_null.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
211bss_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 232bss_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
212bss_null.o: ../../include/openssl/opensslconf.h 233bss_null.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
213bss_null.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h 234bss_null.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
214bss_null.o: ../../include/openssl/stack.h ../cryptlib.h 235bss_null.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
236bss_null.o: ../cryptlib.h
215bss_sock.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 237bss_sock.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
216bss_sock.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 238bss_sock.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
217bss_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 239bss_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
218bss_sock.o: ../../include/openssl/opensslconf.h 240bss_sock.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
219bss_sock.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h 241bss_sock.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
220bss_sock.o: ../../include/openssl/stack.h ../cryptlib.h 242bss_sock.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
243bss_sock.o: ../cryptlib.h
diff --git a/src/lib/libcrypto/bio/b_dump.c b/src/lib/libcrypto/bio/b_dump.c
index f5aeb237f5..8397cfab6a 100644
--- a/src/lib/libcrypto/bio/b_dump.c
+++ b/src/lib/libcrypto/bio/b_dump.c
@@ -66,63 +66,87 @@
66 66
67#define TRUNCATE 67#define TRUNCATE
68#define DUMP_WIDTH 16 68#define DUMP_WIDTH 16
69#define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH-((i-(i>6?6:i)+3)/4))
69 70
70int BIO_dump(BIO *bio, const char *s, int len) 71int BIO_dump(BIO *bio, const char *s, int len)
71{ 72 {
72 int ret=0; 73 return BIO_dump_indent(bio, s, len, 0);
73 char buf[160+1],tmp[20]; 74 }
74 int i,j,rows,trunc;
75 unsigned char ch;
76
77 trunc=0;
78 75
76int BIO_dump_indent(BIO *bio, const char *s, int len, int indent)
77 {
78 int ret=0;
79 char buf[288+1],tmp[20],str[128+1];
80 int i,j,rows,trunc;
81 unsigned char ch;
82 int dump_width;
83
84 trunc=0;
85
79#ifdef TRUNCATE 86#ifdef TRUNCATE
80 for(; (len > 0) && ((s[len-1] == ' ') || (s[len-1] == '\0')); len--) 87 for(; (len > 0) && ((s[len-1] == ' ') || (s[len-1] == '\0')); len--)
81 trunc++; 88 trunc++;
82#endif 89#endif
83 90
84 rows=(len/DUMP_WIDTH); 91 if (indent < 0)
85 if ((rows*DUMP_WIDTH)<len) 92 indent = 0;
86 rows++; 93 if (indent)
87 for(i=0;i<rows;i++) { 94 {
88 buf[0]='\0'; /* start with empty string */ 95 if (indent > 128) indent=128;
89 sprintf(tmp,"%04x - ",i*DUMP_WIDTH); 96 memset(str,' ',indent);
90 strcpy(buf,tmp); 97 }
91 for(j=0;j<DUMP_WIDTH;j++) { 98 str[indent]='\0';
92 if (((i*DUMP_WIDTH)+j)>=len) { 99
93 strcat(buf," "); 100 dump_width=DUMP_WIDTH_LESS_INDENT(indent);
94 } else { 101 rows=(len/dump_width);
95 ch=((unsigned char)*(s+i*DUMP_WIDTH+j)) & 0xff; 102 if ((rows*dump_width)<len)
96 sprintf(tmp,"%02x%c",ch,j==7?'-':' '); 103 rows++;
97 strcat(buf,tmp); 104 for(i=0;i<rows;i++)
98 } 105 {
99 } 106 buf[0]='\0'; /* start with empty string */
100 strcat(buf," "); 107 strcpy(buf,str);
101 for(j=0;j<DUMP_WIDTH;j++) { 108 sprintf(tmp,"%04x - ",i*dump_width);
102 if (((i*DUMP_WIDTH)+j)>=len) 109 strcat(buf,tmp);
103 break; 110 for(j=0;j<dump_width;j++)
104 ch=((unsigned char)*(s+i*DUMP_WIDTH+j)) & 0xff; 111 {
112 if (((i*dump_width)+j)>=len)
113 {
114 strcat(buf," ");
115 }
116 else
117 {
118 ch=((unsigned char)*(s+i*dump_width+j)) & 0xff;
119 sprintf(tmp,"%02x%c",ch,j==7?'-':' ');
120 strcat(buf,tmp);
121 }
122 }
123 strcat(buf," ");
124 for(j=0;j<dump_width;j++)
125 {
126 if (((i*dump_width)+j)>=len)
127 break;
128 ch=((unsigned char)*(s+i*dump_width+j)) & 0xff;
105#ifndef CHARSET_EBCDIC 129#ifndef CHARSET_EBCDIC
106 sprintf(tmp,"%c",((ch>=' ')&&(ch<='~'))?ch:'.'); 130 sprintf(tmp,"%c",((ch>=' ')&&(ch<='~'))?ch:'.');
107#else 131#else
108 sprintf(tmp,"%c",((ch>=os_toascii[' '])&&(ch<=os_toascii['~'])) 132 sprintf(tmp,"%c",((ch>=os_toascii[' '])&&(ch<=os_toascii['~']))
109 ? os_toebcdic[ch] 133 ? os_toebcdic[ch]
110 : '.'); 134 : '.');
111#endif 135#endif
112 strcat(buf,tmp); 136 strcat(buf,tmp);
113 } 137 }
114 strcat(buf,"\n"); 138 strcat(buf,"\n");
115 /* if this is the last call then update the ddt_dump thing so that 139 /* if this is the last call then update the ddt_dump thing so that
116 * we will move the selection point in the debug window 140 * we will move the selection point in the debug window
117 */ 141 */
118 ret+=BIO_write(bio,(char *)buf,strlen(buf)); 142 ret+=BIO_write(bio,(char *)buf,strlen(buf));
119 } 143 }
120#ifdef TRUNCATE 144#ifdef TRUNCATE
121 if (trunc > 0) { 145 if (trunc > 0)
122 sprintf(buf,"%04x - <SPACES/NULS>\n",len+trunc); 146 {
123 ret+=BIO_write(bio,(char *)buf,strlen(buf)); 147 sprintf(buf,"%s%04x - <SPACES/NULS>\n",str,len+trunc);
124 } 148 ret+=BIO_write(bio,(char *)buf,strlen(buf));
149 }
125#endif 150#endif
126 return(ret); 151 return(ret);
127} 152 }
128
diff --git a/src/lib/libcrypto/bio/b_print.c b/src/lib/libcrypto/bio/b_print.c
index b11b501512..a62f551635 100644
--- a/src/lib/libcrypto/bio/b_print.c
+++ b/src/lib/libcrypto/bio/b_print.c
@@ -61,7 +61,6 @@
61 */ 61 */
62 62
63#include <stdio.h> 63#include <stdio.h>
64#include <stdarg.h>
65#include <string.h> 64#include <string.h>
66#include <ctype.h> 65#include <ctype.h>
67#include <assert.h> 66#include <assert.h>
@@ -78,48 +77,7 @@
78# endif 77# endif
79#endif 78#endif
80 79
81static void dopr (char *buffer, size_t maxlen, size_t *retlen, 80/***************************************************************************/
82 const char *format, va_list args);
83#ifdef USE_ALLOCATING_PRINT
84static void doapr (char **buffer, size_t *retlen,
85 const char *format, va_list args);
86#endif
87
88int BIO_printf (BIO *bio, ...)
89 {
90 va_list args;
91 char *format;
92 int ret;
93 size_t retlen;
94#ifdef USE_ALLOCATING_PRINT
95 char *hugebuf;
96#else
97 MS_STATIC char hugebuf[1024*2]; /* 10k in one chunk is the limit */
98#endif
99
100 va_start(args, bio);
101 format=va_arg(args, char *);
102
103#ifndef USE_ALLOCATING_PRINT
104 hugebuf[0]='\0';
105 dopr(hugebuf, sizeof(hugebuf), &retlen, format, args);
106#else
107 hugebuf = NULL;
108 CRYPTO_push_info("doapr()");
109 doapr(&hugebuf, &retlen, format, args);
110 if (hugebuf)
111 {
112#endif
113 ret=BIO_write(bio, hugebuf, (int)retlen);
114
115#ifdef USE_ALLOCATING_PRINT
116 Free(hugebuf);
117 }
118 CRYPTO_pop_info();
119#endif
120 va_end(args);
121 return(ret);
122 }
123 81
124/* 82/*
125 * Copyright Patrick Powell 1995 83 * Copyright Patrick Powell 1995
@@ -140,6 +98,7 @@ int BIO_printf (BIO *bio, ...)
140 * o Andrew Tridgell <tridge@samba.org> (1998, for Samba) 98 * o Andrew Tridgell <tridge@samba.org> (1998, for Samba)
141 * o Luke Mewburn <lukem@netbsd.org> (1999, for LukemFTP) 99 * o Luke Mewburn <lukem@netbsd.org> (1999, for LukemFTP)
142 * o Ralf S. Engelschall <rse@engelschall.com> (1999, for Pth) 100 * o Ralf S. Engelschall <rse@engelschall.com> (1999, for Pth)
101 * o ... (for OpenSSL)
143 */ 102 */
144 103
145#if HAVE_LONG_DOUBLE 104#if HAVE_LONG_DOUBLE
@@ -154,25 +113,15 @@ int BIO_printf (BIO *bio, ...)
154#define LLONG long 113#define LLONG long
155#endif 114#endif
156 115
157static void fmtstr (void (*)(char **, size_t *, size_t *, int), 116static void fmtstr (char **, char **, size_t *, size_t *,
158 char **, size_t *, size_t *, const char *, int, int, 117 const char *, int, int, int);
159 int); 118static void fmtint (char **, char **, size_t *, size_t *,
160static void fmtint (void (*)(char **, size_t *, size_t *, int), 119 LLONG, int, int, int, int);
161 char **, size_t *, size_t *, LLONG, int, int, int, int); 120static void fmtfp (char **, char **, size_t *, size_t *,
162static void fmtfp (void (*)(char **, size_t *, size_t *, int), 121 LDOUBLE, int, int, int);
163 char **, size_t *, size_t *, LDOUBLE, int, int, int); 122static void doapr_outch (char **, char **, size_t *, size_t *, int);
164#ifndef USE_ALLOCATING_PRINT 123static void _dopr(char **sbuffer, char **buffer,
165static int dopr_isbig (size_t, size_t); 124 size_t *maxlen, size_t *retlen, int *truncated,
166static int dopr_copy (size_t);
167static void dopr_outch (char **, size_t *, size_t *, int);
168#else
169static int doapr_isbig (size_t, size_t);
170static int doapr_copy (size_t);
171static void doapr_outch (char **, size_t *, size_t *, int);
172#endif
173static void _dopr(void (*)(char **, size_t *, size_t *, int),
174 int (*)(size_t, size_t), int (*)(size_t),
175 char **buffer, size_t *maxlen, size_t *retlen,
176 const char *format, va_list args); 125 const char *format, va_list args);
177 126
178/* format read states */ 127/* format read states */
@@ -204,41 +153,13 @@ static void _dopr(void (*)(char **, size_t *, size_t *, int),
204#define char_to_int(p) (p - '0') 153#define char_to_int(p) (p - '0')
205#define MAX(p,q) ((p >= q) ? p : q) 154#define MAX(p,q) ((p >= q) ? p : q)
206 155
207#ifndef USE_ALLOCATING_PRINT
208static void
209dopr(
210 char *buffer,
211 size_t maxlen,
212 size_t *retlen,
213 const char *format,
214 va_list args)
215{
216 _dopr(dopr_outch, dopr_isbig, dopr_copy,
217 &buffer, &maxlen, retlen, format, args);
218}
219
220#else
221static void
222doapr(
223 char **buffer,
224 size_t *retlen,
225 const char *format,
226 va_list args)
227{
228 size_t dummy_maxlen = 0;
229 _dopr(doapr_outch, doapr_isbig, doapr_copy,
230 buffer, &dummy_maxlen, retlen, format, args);
231}
232#endif
233
234static void 156static void
235_dopr( 157_dopr(
236 void (*outch_fn)(char **, size_t *, size_t *, int), 158 char **sbuffer,
237 int (*isbig_fn)(size_t, size_t),
238 int (*copy_fn)(size_t),
239 char **buffer, 159 char **buffer,
240 size_t *maxlen, 160 size_t *maxlen,
241 size_t *retlen, 161 size_t *retlen,
162 int *truncated,
242 const char *format, 163 const char *format,
243 va_list args) 164 va_list args)
244{ 165{
@@ -259,7 +180,7 @@ _dopr(
259 ch = *format++; 180 ch = *format++;
260 181
261 while (state != DP_S_DONE) { 182 while (state != DP_S_DONE) {
262 if ((ch == '\0') || (*isbig_fn)(currlen, *maxlen)) 183 if (ch == '\0' || (buffer == NULL && currlen >= *maxlen))
263 state = DP_S_DONE; 184 state = DP_S_DONE;
264 185
265 switch (state) { 186 switch (state) {
@@ -267,7 +188,7 @@ _dopr(
267 if (ch == '%') 188 if (ch == '%')
268 state = DP_S_FLAGS; 189 state = DP_S_FLAGS;
269 else 190 else
270 (*outch_fn)(buffer, &currlen, maxlen, ch); 191 doapr_outch(sbuffer,buffer, &currlen, maxlen, ch);
271 ch = *format++; 192 ch = *format++;
272 break; 193 break;
273 case DP_S_FLAGS: 194 case DP_S_FLAGS:
@@ -373,8 +294,8 @@ _dopr(
373 value = va_arg(args, int); 294 value = va_arg(args, int);
374 break; 295 break;
375 } 296 }
376 fmtint(outch_fn, buffer, &currlen, maxlen, 297 fmtint(sbuffer, buffer, &currlen, maxlen,
377 value, 10, min, max, flags); 298 value, 10, min, max, flags);
378 break; 299 break;
379 case 'X': 300 case 'X':
380 flags |= DP_F_UP; 301 flags |= DP_F_UP;
@@ -399,7 +320,7 @@ _dopr(
399 unsigned int); 320 unsigned int);
400 break; 321 break;
401 } 322 }
402 fmtint(outch_fn, buffer, &currlen, maxlen, value, 323 fmtint(sbuffer, buffer, &currlen, maxlen, value,
403 ch == 'o' ? 8 : (ch == 'u' ? 10 : 16), 324 ch == 'o' ? 8 : (ch == 'u' ? 10 : 16),
404 min, max, flags); 325 min, max, flags);
405 break; 326 break;
@@ -408,8 +329,8 @@ _dopr(
408 fvalue = va_arg(args, LDOUBLE); 329 fvalue = va_arg(args, LDOUBLE);
409 else 330 else
410 fvalue = va_arg(args, double); 331 fvalue = va_arg(args, double);
411 fmtfp(outch_fn, buffer, &currlen, maxlen, 332 fmtfp(sbuffer, buffer, &currlen, maxlen,
412 fvalue, min, max, flags); 333 fvalue, min, max, flags);
413 break; 334 break;
414 case 'E': 335 case 'E':
415 flags |= DP_F_UP; 336 flags |= DP_F_UP;
@@ -428,19 +349,23 @@ _dopr(
428 fvalue = va_arg(args, double); 349 fvalue = va_arg(args, double);
429 break; 350 break;
430 case 'c': 351 case 'c':
431 (*outch_fn)(buffer, &currlen, maxlen, 352 doapr_outch(sbuffer, buffer, &currlen, maxlen,
432 va_arg(args, int)); 353 va_arg(args, int));
433 break; 354 break;
434 case 's': 355 case 's':
435 strvalue = va_arg(args, char *); 356 strvalue = va_arg(args, char *);
436 if (max < 0) 357 if (max < 0) {
437 max = (*copy_fn)(*maxlen); 358 if (buffer)
438 fmtstr(outch_fn, buffer, &currlen, maxlen, strvalue, 359 max = INT_MAX;
439 flags, min, max); 360 else
361 max = *maxlen;
362 }
363 fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue,
364 flags, min, max);
440 break; 365 break;
441 case 'p': 366 case 'p':
442 value = (long)va_arg(args, void *); 367 value = (long)va_arg(args, void *);
443 fmtint(outch_fn, buffer, &currlen, maxlen, 368 fmtint(sbuffer, buffer, &currlen, maxlen,
444 value, 16, min, max, flags); 369 value, 16, min, max, flags);
445 break; 370 break;
446 case 'n': /* XXX */ 371 case 'n': /* XXX */
@@ -463,7 +388,7 @@ _dopr(
463 } 388 }
464 break; 389 break;
465 case '%': 390 case '%':
466 (*outch_fn)(buffer, &currlen, maxlen, ch); 391 doapr_outch(sbuffer, buffer, &currlen, maxlen, ch);
467 break; 392 break;
468 case 'w': 393 case 'w':
469 /* not supported yet, treat as next char */ 394 /* not supported yet, treat as next char */
@@ -484,16 +409,17 @@ _dopr(
484 break; 409 break;
485 } 410 }
486 } 411 }
487 if (currlen >= *maxlen - 1) 412 *truncated = (currlen > *maxlen - 1);
413 if (*truncated)
488 currlen = *maxlen - 1; 414 currlen = *maxlen - 1;
489 (*buffer)[currlen] = '\0'; 415 doapr_outch(sbuffer, buffer, &currlen, maxlen, '\0');
490 *retlen = currlen; 416 *retlen = currlen - 1;
491 return; 417 return;
492} 418}
493 419
494static void 420static void
495fmtstr( 421fmtstr(
496 void (*outch_fn)(char **, size_t *, size_t *, int), 422 char **sbuffer,
497 char **buffer, 423 char **buffer,
498 size_t *currlen, 424 size_t *currlen,
499 size_t *maxlen, 425 size_t *maxlen,
@@ -516,16 +442,16 @@ fmtstr(
516 padlen = -padlen; 442 padlen = -padlen;
517 443
518 while ((padlen > 0) && (cnt < max)) { 444 while ((padlen > 0) && (cnt < max)) {
519 (*outch_fn)(buffer, currlen, maxlen, ' '); 445 doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
520 --padlen; 446 --padlen;
521 ++cnt; 447 ++cnt;
522 } 448 }
523 while (*value && (cnt < max)) { 449 while (*value && (cnt < max)) {
524 (*outch_fn)(buffer, currlen, maxlen, *value++); 450 doapr_outch(sbuffer, buffer, currlen, maxlen, *value++);
525 ++cnt; 451 ++cnt;
526 } 452 }
527 while ((padlen < 0) && (cnt < max)) { 453 while ((padlen < 0) && (cnt < max)) {
528 (*outch_fn)(buffer, currlen, maxlen, ' '); 454 doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
529 ++padlen; 455 ++padlen;
530 ++cnt; 456 ++cnt;
531 } 457 }
@@ -533,7 +459,7 @@ fmtstr(
533 459
534static void 460static void
535fmtint( 461fmtint(
536 void (*outch_fn)(char **, size_t *, size_t *, int), 462 char **sbuffer,
537 char **buffer, 463 char **buffer,
538 size_t *currlen, 464 size_t *currlen,
539 size_t *maxlen, 465 size_t *maxlen,
@@ -590,28 +516,28 @@ fmtint(
590 516
591 /* spaces */ 517 /* spaces */
592 while (spadlen > 0) { 518 while (spadlen > 0) {
593 (*outch_fn)(buffer, currlen, maxlen, ' '); 519 doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
594 --spadlen; 520 --spadlen;
595 } 521 }
596 522
597 /* sign */ 523 /* sign */
598 if (signvalue) 524 if (signvalue)
599 (*outch_fn)(buffer, currlen, maxlen, signvalue); 525 doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
600 526
601 /* zeros */ 527 /* zeros */
602 if (zpadlen > 0) { 528 if (zpadlen > 0) {
603 while (zpadlen > 0) { 529 while (zpadlen > 0) {
604 (*outch_fn)(buffer, currlen, maxlen, '0'); 530 doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
605 --zpadlen; 531 --zpadlen;
606 } 532 }
607 } 533 }
608 /* digits */ 534 /* digits */
609 while (place > 0) 535 while (place > 0)
610 (*outch_fn)(buffer, currlen, maxlen, convert[--place]); 536 doapr_outch(sbuffer, buffer, currlen, maxlen, convert[--place]);
611 537
612 /* left justified spaces */ 538 /* left justified spaces */
613 while (spadlen < 0) { 539 while (spadlen < 0) {
614 (*outch_fn)(buffer, currlen, maxlen, ' '); 540 doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
615 ++spadlen; 541 ++spadlen;
616 } 542 }
617 return; 543 return;
@@ -650,7 +576,7 @@ round(LDOUBLE value)
650 576
651static void 577static void
652fmtfp( 578fmtfp(
653 void (*outch_fn)(char **, size_t *, size_t *, int), 579 char **sbuffer,
654 char **buffer, 580 char **buffer,
655 size_t *currlen, 581 size_t *currlen,
656 size_t *maxlen, 582 size_t *maxlen,
@@ -731,114 +657,158 @@ fmtfp(
731 657
732 if ((flags & DP_F_ZERO) && (padlen > 0)) { 658 if ((flags & DP_F_ZERO) && (padlen > 0)) {
733 if (signvalue) { 659 if (signvalue) {
734 (*outch_fn)(buffer, currlen, maxlen, signvalue); 660 doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
735 --padlen; 661 --padlen;
736 signvalue = 0; 662 signvalue = 0;
737 } 663 }
738 while (padlen > 0) { 664 while (padlen > 0) {
739 (*outch_fn)(buffer, currlen, maxlen, '0'); 665 doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
740 --padlen; 666 --padlen;
741 } 667 }
742 } 668 }
743 while (padlen > 0) { 669 while (padlen > 0) {
744 (*outch_fn)(buffer, currlen, maxlen, ' '); 670 doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
745 --padlen; 671 --padlen;
746 } 672 }
747 if (signvalue) 673 if (signvalue)
748 (*outch_fn)(buffer, currlen, maxlen, signvalue); 674 doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
749 675
750 while (iplace > 0) 676 while (iplace > 0)
751 (*outch_fn)(buffer, currlen, maxlen, iconvert[--iplace]); 677 doapr_outch(sbuffer, buffer, currlen, maxlen, iconvert[--iplace]);
752 678
753 /* 679 /*
754 * Decimal point. This should probably use locale to find the correct 680 * Decimal point. This should probably use locale to find the correct
755 * char to print out. 681 * char to print out.
756 */ 682 */
757 if (max > 0) { 683 if (max > 0) {
758 (*outch_fn)(buffer, currlen, maxlen, '.'); 684 doapr_outch(sbuffer, buffer, currlen, maxlen, '.');
759 685
760 while (fplace > 0) 686 while (fplace > 0)
761 (*outch_fn)(buffer, currlen, maxlen, fconvert[--fplace]); 687 doapr_outch(sbuffer, buffer, currlen, maxlen, fconvert[--fplace]);
762 } 688 }
763 while (zpadlen > 0) { 689 while (zpadlen > 0) {
764 (*outch_fn)(buffer, currlen, maxlen, '0'); 690 doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
765 --zpadlen; 691 --zpadlen;
766 } 692 }
767 693
768 while (padlen < 0) { 694 while (padlen < 0) {
769 (*outch_fn)(buffer, currlen, maxlen, ' '); 695 doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
770 ++padlen; 696 ++padlen;
771 } 697 }
772} 698}
773 699
774static int
775dopr_copy(
776 size_t len)
777{
778 return len;
779}
780
781#ifdef USE_ALLOCATING_PRINT
782static int
783doapr_copy(
784 size_t len)
785{
786 /* Return as high an integer as possible */
787 return INT_MAX;
788}
789#endif
790
791static int
792dopr_isbig(
793 size_t currlen,
794 size_t maxlen)
795{
796 return currlen > maxlen;
797}
798
799#ifdef USE_ALLOCATING_PRINT
800static int
801doapr_isbig(
802 size_t currlen,
803 size_t maxlen)
804{
805 return 0;
806}
807#endif
808
809static void
810dopr_outch(
811 char **buffer,
812 size_t *currlen,
813 size_t *maxlen,
814 int c)
815{
816 if (*currlen < *maxlen)
817 (*buffer)[(*currlen)++] = (char)c;
818 return;
819}
820
821#ifdef USE_ALLOCATING_PRINT
822static void 700static void
823doapr_outch( 701doapr_outch(
702 char **sbuffer,
824 char **buffer, 703 char **buffer,
825 size_t *currlen, 704 size_t *currlen,
826 size_t *maxlen, 705 size_t *maxlen,
827 int c) 706 int c)
828{ 707{
829 if (*buffer == NULL) { 708 /* If we haven't at least one buffer, someone has doe a big booboo */
830 if (*maxlen == 0) 709 assert(*sbuffer != NULL || buffer != NULL);
831 *maxlen = 1024; 710
832 *buffer = Malloc(*maxlen); 711 if (buffer) {
712 while (*currlen >= *maxlen) {
713 if (*buffer == NULL) {
714 assert(*sbuffer != NULL);
715 if (*maxlen == 0)
716 *maxlen = 1024;
717 *buffer = OPENSSL_malloc(*maxlen);
718 if (*currlen > 0)
719 memcpy(*buffer, *sbuffer, *currlen);
720 *sbuffer = NULL;
721 } else {
722 *maxlen += 1024;
723 *buffer = OPENSSL_realloc(*buffer, *maxlen);
724 }
725 }
726 /* What to do if *buffer is NULL? */
727 assert(*sbuffer != NULL || *buffer != NULL);
833 } 728 }
834 while (*currlen >= *maxlen) { 729
835 *maxlen += 1024; 730 if (*currlen < *maxlen) {
836 *buffer = Realloc(*buffer, *maxlen); 731 if (*sbuffer)
732 (*sbuffer)[(*currlen)++] = (char)c;
733 else
734 (*buffer)[(*currlen)++] = (char)c;
837 } 735 }
838 /* What to do if *buffer is NULL? */
839 assert(*buffer != NULL);
840 736
841 (*buffer)[(*currlen)++] = (char)c;
842 return; 737 return;
843} 738}
844#endif 739
740/***************************************************************************/
741
742int BIO_printf (BIO *bio, const char *format, ...)
743 {
744 va_list args;
745 int ret;
746
747 va_start(args, format);
748
749 ret = BIO_vprintf(bio, format, args);
750
751 va_end(args);
752 return(ret);
753 }
754
755int BIO_vprintf (BIO *bio, const char *format, va_list args)
756 {
757 int ret;
758 size_t retlen;
759 MS_STATIC char hugebuf[1024*10];
760 char *hugebufp = hugebuf;
761 size_t hugebufsize = sizeof(hugebuf);
762 char *dynbuf = NULL;
763 int ignored;
764
765 dynbuf = NULL;
766 CRYPTO_push_info("doapr()");
767 _dopr(&hugebufp, &dynbuf, &hugebufsize,
768 &retlen, &ignored, format, args);
769 if (dynbuf)
770 {
771 ret=BIO_write(bio, dynbuf, (int)retlen);
772 OPENSSL_free(dynbuf);
773 }
774 else
775 {
776 ret=BIO_write(bio, hugebuf, (int)retlen);
777 }
778 CRYPTO_pop_info();
779 return(ret);
780 }
781
782/* As snprintf is not available everywhere, we provide our own implementation.
783 * This function has nothing to do with BIOs, but it's closely related
784 * to BIO_printf, and we need *some* name prefix ...
785 * (XXX the function should be renamed, but to what?) */
786int BIO_snprintf(char *buf, size_t n, const char *format, ...)
787 {
788 va_list args;
789 int ret;
790
791 va_start(args, format);
792
793 ret = BIO_vsnprintf(buf, n, format, args);
794
795 va_end(args);
796 return(ret);
797 }
798
799int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)
800 {
801 size_t retlen;
802 int truncated;
803
804 _dopr(&buf, NULL, &n, &retlen, &truncated, format, args);
805
806 if (truncated)
807 /* In case of truncation, return -1 like traditional snprintf.
808 * (Current drafts for ISO/IEC 9899 say snprintf should return
809 * the number of characters that would have been written,
810 * had the buffer been large enough.) */
811 return -1;
812 else
813 return (retlen <= INT_MAX) ? retlen : -1;
814 }
diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c
index 6409f98f57..64310058b4 100644
--- a/src/lib/libcrypto/bio/b_sock.c
+++ b/src/lib/libcrypto/bio/b_sock.c
@@ -105,17 +105,22 @@ int BIO_get_host_ip(const char *str, unsigned char *ip)
105 struct hostent *he; 105 struct hostent *he;
106 106
107 i=get_ip(str,ip); 107 i=get_ip(str,ip);
108 if (i > 0) return(1);
109 if (i < 0) 108 if (i < 0)
110 { 109 {
111 BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_INVALID_IP_ADDRESS); 110 BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_INVALID_IP_ADDRESS);
112 goto err; 111 goto err;
113 } 112 }
114 113
115 /* do a gethostbyname */ 114 /* At this point, we have something that is most probably correct
115 in some way, so let's init the socket. */
116 if (!BIO_sock_init()) 116 if (!BIO_sock_init())
117 return(0); /* don't generate another error code here */ 117 return(0); /* don't generate another error code here */
118 118
119 /* If the string actually contained an IP address, we need not do
120 anything more */
121 if (i > 0) return(1);
122
123 /* do a gethostbyname */
119 CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME); 124 CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME);
120 locked = 1; 125 locked = 1;
121 he=BIO_gethostbyname(str); 126 he=BIO_gethostbyname(str);
@@ -267,14 +272,14 @@ static struct hostent *ghbn_dup(struct hostent *a)
267 int i,j; 272 int i,j;
268 273
269 MemCheck_off(); 274 MemCheck_off();
270 ret=(struct hostent *)Malloc(sizeof(struct hostent)); 275 ret=(struct hostent *)OPENSSL_malloc(sizeof(struct hostent));
271 if (ret == NULL) return(NULL); 276 if (ret == NULL) return(NULL);
272 memset(ret,0,sizeof(struct hostent)); 277 memset(ret,0,sizeof(struct hostent));
273 278
274 for (i=0; a->h_aliases[i] != NULL; i++) 279 for (i=0; a->h_aliases[i] != NULL; i++)
275 ; 280 ;
276 i++; 281 i++;
277 ret->h_aliases = (char **)Malloc(i*sizeof(char *)); 282 ret->h_aliases = (char **)OPENSSL_malloc(i*sizeof(char *));
278 if (ret->h_aliases == NULL) 283 if (ret->h_aliases == NULL)
279 goto err; 284 goto err;
280 memset(ret->h_aliases, 0, i*sizeof(char *)); 285 memset(ret->h_aliases, 0, i*sizeof(char *));
@@ -282,25 +287,25 @@ static struct hostent *ghbn_dup(struct hostent *a)
282 for (i=0; a->h_addr_list[i] != NULL; i++) 287 for (i=0; a->h_addr_list[i] != NULL; i++)
283 ; 288 ;
284 i++; 289 i++;
285 ret->h_addr_list=(char **)Malloc(i*sizeof(char *)); 290 ret->h_addr_list=(char **)OPENSSL_malloc(i*sizeof(char *));
286 if (ret->h_addr_list == NULL) 291 if (ret->h_addr_list == NULL)
287 goto err; 292 goto err;
288 memset(ret->h_addr_list, 0, i*sizeof(char *)); 293 memset(ret->h_addr_list, 0, i*sizeof(char *));
289 294
290 j=strlen(a->h_name)+1; 295 j=strlen(a->h_name)+1;
291 if ((ret->h_name=Malloc(j)) == NULL) goto err; 296 if ((ret->h_name=OPENSSL_malloc(j)) == NULL) goto err;
292 memcpy((char *)ret->h_name,a->h_name,j); 297 memcpy((char *)ret->h_name,a->h_name,j);
293 for (i=0; a->h_aliases[i] != NULL; i++) 298 for (i=0; a->h_aliases[i] != NULL; i++)
294 { 299 {
295 j=strlen(a->h_aliases[i])+1; 300 j=strlen(a->h_aliases[i])+1;
296 if ((ret->h_aliases[i]=Malloc(j)) == NULL) goto err; 301 if ((ret->h_aliases[i]=OPENSSL_malloc(j)) == NULL) goto err;
297 memcpy(ret->h_aliases[i],a->h_aliases[i],j); 302 memcpy(ret->h_aliases[i],a->h_aliases[i],j);
298 } 303 }
299 ret->h_length=a->h_length; 304 ret->h_length=a->h_length;
300 ret->h_addrtype=a->h_addrtype; 305 ret->h_addrtype=a->h_addrtype;
301 for (i=0; a->h_addr_list[i] != NULL; i++) 306 for (i=0; a->h_addr_list[i] != NULL; i++)
302 { 307 {
303 if ((ret->h_addr_list[i]=Malloc(a->h_length)) == NULL) 308 if ((ret->h_addr_list[i]=OPENSSL_malloc(a->h_length)) == NULL)
304 goto err; 309 goto err;
305 memcpy(ret->h_addr_list[i],a->h_addr_list[i],a->h_length); 310 memcpy(ret->h_addr_list[i],a->h_addr_list[i],a->h_length);
306 } 311 }
@@ -325,17 +330,17 @@ static void ghbn_free(struct hostent *a)
325 if (a->h_aliases != NULL) 330 if (a->h_aliases != NULL)
326 { 331 {
327 for (i=0; a->h_aliases[i] != NULL; i++) 332 for (i=0; a->h_aliases[i] != NULL; i++)
328 Free(a->h_aliases[i]); 333 OPENSSL_free(a->h_aliases[i]);
329 Free(a->h_aliases); 334 OPENSSL_free(a->h_aliases);
330 } 335 }
331 if (a->h_addr_list != NULL) 336 if (a->h_addr_list != NULL)
332 { 337 {
333 for (i=0; a->h_addr_list[i] != NULL; i++) 338 for (i=0; a->h_addr_list[i] != NULL; i++)
334 Free(a->h_addr_list[i]); 339 OPENSSL_free(a->h_addr_list[i]);
335 Free(a->h_addr_list); 340 OPENSSL_free(a->h_addr_list);
336 } 341 }
337 if (a->h_name != NULL) Free(a->h_name); 342 if (a->h_name != NULL) OPENSSL_free(a->h_name);
338 Free(a); 343 OPENSSL_free(a);
339 } 344 }
340 345
341struct hostent *BIO_gethostbyname(const char *name) 346struct hostent *BIO_gethostbyname(const char *name)
@@ -628,7 +633,7 @@ again:
628 } 633 }
629 ret=1; 634 ret=1;
630err: 635err:
631 if (str != NULL) Free(str); 636 if (str != NULL) OPENSSL_free(str);
632 if ((ret == 0) && (s != INVALID_SOCKET)) 637 if ((ret == 0) && (s != INVALID_SOCKET))
633 { 638 {
634 closesocket(s); 639 closesocket(s);
@@ -667,7 +672,7 @@ int BIO_accept(int sock, char **addr)
667 port=ntohs(from.sin_port); 672 port=ntohs(from.sin_port);
668 if (*addr == NULL) 673 if (*addr == NULL)
669 { 674 {
670 if ((p=Malloc(24)) == NULL) 675 if ((p=OPENSSL_malloc(24)) == NULL)
671 { 676 {
672 BIOerr(BIO_F_BIO_ACCEPT,ERR_R_MALLOC_FAILURE); 677 BIOerr(BIO_F_BIO_ACCEPT,ERR_R_MALLOC_FAILURE);
673 goto end; 678 goto end;
diff --git a/src/lib/libcrypto/bio/bf_buff.c b/src/lib/libcrypto/bio/bf_buff.c
index ff0c9070ae..f50e8f98a3 100644
--- a/src/lib/libcrypto/bio/bf_buff.c
+++ b/src/lib/libcrypto/bio/bf_buff.c
@@ -62,14 +62,14 @@
62#include <openssl/bio.h> 62#include <openssl/bio.h>
63#include <openssl/evp.h> 63#include <openssl/evp.h>
64 64
65static int buffer_write(BIO *h,char *buf,int num); 65static int buffer_write(BIO *h, const char *buf,int num);
66static int buffer_read(BIO *h,char *buf,int size); 66static int buffer_read(BIO *h, char *buf, int size);
67static int buffer_puts(BIO *h,char *str); 67static int buffer_puts(BIO *h, const char *str);
68static int buffer_gets(BIO *h,char *str,int size); 68static int buffer_gets(BIO *h, char *str, int size);
69static long buffer_ctrl(BIO *h,int cmd,long arg1,char *arg2); 69static long buffer_ctrl(BIO *h, int cmd, long arg1, void *arg2);
70static int buffer_new(BIO *h); 70static int buffer_new(BIO *h);
71static int buffer_free(BIO *data); 71static int buffer_free(BIO *data);
72static long buffer_callback_ctrl(BIO *h,int cmd, void (*fp)()); 72static long buffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
73#define DEFAULT_BUFFER_SIZE 1024 73#define DEFAULT_BUFFER_SIZE 1024
74 74
75static BIO_METHOD methods_buffer= 75static BIO_METHOD methods_buffer=
@@ -95,12 +95,12 @@ static int buffer_new(BIO *bi)
95 { 95 {
96 BIO_F_BUFFER_CTX *ctx; 96 BIO_F_BUFFER_CTX *ctx;
97 97
98 ctx=(BIO_F_BUFFER_CTX *)Malloc(sizeof(BIO_F_BUFFER_CTX)); 98 ctx=(BIO_F_BUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_F_BUFFER_CTX));
99 if (ctx == NULL) return(0); 99 if (ctx == NULL) return(0);
100 ctx->ibuf=(char *)Malloc(DEFAULT_BUFFER_SIZE); 100 ctx->ibuf=(char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
101 if (ctx->ibuf == NULL) { Free(ctx); return(0); } 101 if (ctx->ibuf == NULL) { OPENSSL_free(ctx); return(0); }
102 ctx->obuf=(char *)Malloc(DEFAULT_BUFFER_SIZE); 102 ctx->obuf=(char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
103 if (ctx->obuf == NULL) { Free(ctx->ibuf); Free(ctx); return(0); } 103 if (ctx->obuf == NULL) { OPENSSL_free(ctx->ibuf); OPENSSL_free(ctx); return(0); }
104 ctx->ibuf_size=DEFAULT_BUFFER_SIZE; 104 ctx->ibuf_size=DEFAULT_BUFFER_SIZE;
105 ctx->obuf_size=DEFAULT_BUFFER_SIZE; 105 ctx->obuf_size=DEFAULT_BUFFER_SIZE;
106 ctx->ibuf_len=0; 106 ctx->ibuf_len=0;
@@ -120,9 +120,9 @@ static int buffer_free(BIO *a)
120 120
121 if (a == NULL) return(0); 121 if (a == NULL) return(0);
122 b=(BIO_F_BUFFER_CTX *)a->ptr; 122 b=(BIO_F_BUFFER_CTX *)a->ptr;
123 if (b->ibuf != NULL) Free(b->ibuf); 123 if (b->ibuf != NULL) OPENSSL_free(b->ibuf);
124 if (b->obuf != NULL) Free(b->obuf); 124 if (b->obuf != NULL) OPENSSL_free(b->obuf);
125 Free(a->ptr); 125 OPENSSL_free(a->ptr);
126 a->ptr=NULL; 126 a->ptr=NULL;
127 a->init=0; 127 a->init=0;
128 a->flags=0; 128 a->flags=0;
@@ -195,7 +195,7 @@ start:
195 goto start; 195 goto start;
196 } 196 }
197 197
198static int buffer_write(BIO *b, char *in, int inl) 198static int buffer_write(BIO *b, const char *in, int inl)
199 { 199 {
200 int i,num=0; 200 int i,num=0;
201 BIO_F_BUFFER_CTX *ctx; 201 BIO_F_BUFFER_CTX *ctx;
@@ -268,7 +268,7 @@ start:
268 goto start; 268 goto start;
269 } 269 }
270 270
271static long buffer_ctrl(BIO *b, int cmd, long num, char *ptr) 271static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
272 { 272 {
273 BIO *dbio; 273 BIO *dbio;
274 BIO_F_BUFFER_CTX *ctx; 274 BIO_F_BUFFER_CTX *ctx;
@@ -319,9 +319,9 @@ static long buffer_ctrl(BIO *b, int cmd, long num, char *ptr)
319 case BIO_C_SET_BUFF_READ_DATA: 319 case BIO_C_SET_BUFF_READ_DATA:
320 if (num > ctx->ibuf_size) 320 if (num > ctx->ibuf_size)
321 { 321 {
322 p1=Malloc((int)num); 322 p1=OPENSSL_malloc((int)num);
323 if (p1 == NULL) goto malloc_error; 323 if (p1 == NULL) goto malloc_error;
324 if (ctx->ibuf != NULL) Free(ctx->ibuf); 324 if (ctx->ibuf != NULL) OPENSSL_free(ctx->ibuf);
325 ctx->ibuf=p1; 325 ctx->ibuf=p1;
326 } 326 }
327 ctx->ibuf_off=0; 327 ctx->ibuf_off=0;
@@ -353,21 +353,21 @@ static long buffer_ctrl(BIO *b, int cmd, long num, char *ptr)
353 p2=ctx->obuf; 353 p2=ctx->obuf;
354 if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size)) 354 if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size))
355 { 355 {
356 p1=(char *)Malloc((int)num); 356 p1=(char *)OPENSSL_malloc((int)num);
357 if (p1 == NULL) goto malloc_error; 357 if (p1 == NULL) goto malloc_error;
358 } 358 }
359 if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size)) 359 if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size))
360 { 360 {
361 p2=(char *)Malloc((int)num); 361 p2=(char *)OPENSSL_malloc((int)num);
362 if (p2 == NULL) 362 if (p2 == NULL)
363 { 363 {
364 if (p1 != ctx->ibuf) Free(p1); 364 if (p1 != ctx->ibuf) OPENSSL_free(p1);
365 goto malloc_error; 365 goto malloc_error;
366 } 366 }
367 } 367 }
368 if (ctx->ibuf != p1) 368 if (ctx->ibuf != p1)
369 { 369 {
370 Free(ctx->ibuf); 370 OPENSSL_free(ctx->ibuf);
371 ctx->ibuf=p1; 371 ctx->ibuf=p1;
372 ctx->ibuf_off=0; 372 ctx->ibuf_off=0;
373 ctx->ibuf_len=0; 373 ctx->ibuf_len=0;
@@ -375,7 +375,7 @@ static long buffer_ctrl(BIO *b, int cmd, long num, char *ptr)
375 } 375 }
376 if (ctx->obuf != p2) 376 if (ctx->obuf != p2)
377 { 377 {
378 Free(ctx->obuf); 378 OPENSSL_free(ctx->obuf);
379 ctx->obuf=p2; 379 ctx->obuf=p2;
380 ctx->obuf_off=0; 380 ctx->obuf_off=0;
381 ctx->obuf_len=0; 381 ctx->obuf_len=0;
@@ -439,7 +439,7 @@ malloc_error:
439 return(0); 439 return(0);
440 } 440 }
441 441
442static long buffer_callback_ctrl(BIO *b, int cmd, void (*fp)()) 442static long buffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
443 { 443 {
444 long ret=1; 444 long ret=1;
445 445
@@ -504,8 +504,8 @@ static int buffer_gets(BIO *b, char *buf, int size)
504 } 504 }
505 } 505 }
506 506
507static int buffer_puts(BIO *b, char *str) 507static int buffer_puts(BIO *b, const char *str)
508 { 508 {
509 return(BIO_write(b,str,strlen(str))); 509 return(buffer_write(b,str,strlen(str)));
510 } 510 }
511 511
diff --git a/src/lib/libcrypto/bio/bf_lbuf.c b/src/lib/libcrypto/bio/bf_lbuf.c
new file mode 100644
index 0000000000..7bcf8ed941
--- /dev/null
+++ b/src/lib/libcrypto/bio/bf_lbuf.c
@@ -0,0 +1,397 @@
1/* crypto/bio/bf_buff.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include "cryptlib.h"
62#include <openssl/bio.h>
63#include <openssl/evp.h>
64
65static int linebuffer_write(BIO *h, const char *buf,int num);
66static int linebuffer_read(BIO *h, char *buf, int size);
67static int linebuffer_puts(BIO *h, const char *str);
68static int linebuffer_gets(BIO *h, char *str, int size);
69static long linebuffer_ctrl(BIO *h, int cmd, long arg1, void *arg2);
70static int linebuffer_new(BIO *h);
71static int linebuffer_free(BIO *data);
72static long linebuffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
73
74/* A 10k maximum should be enough for most purposes */
75#define DEFAULT_LINEBUFFER_SIZE 1024*10
76
77/* #define DEBUG */
78
79static BIO_METHOD methods_linebuffer=
80 {
81 BIO_TYPE_LINEBUFFER,
82 "linebuffer",
83 linebuffer_write,
84 linebuffer_read,
85 linebuffer_puts,
86 linebuffer_gets,
87 linebuffer_ctrl,
88 linebuffer_new,
89 linebuffer_free,
90 linebuffer_callback_ctrl,
91 };
92
93BIO_METHOD *BIO_f_linebuffer(void)
94 {
95 return(&methods_linebuffer);
96 }
97
98typedef struct bio_linebuffer_ctx_struct
99 {
100 char *obuf; /* the output char array */
101 int obuf_size; /* how big is the output buffer */
102 int obuf_len; /* how many bytes are in it */
103 } BIO_LINEBUFFER_CTX;
104
105static int linebuffer_new(BIO *bi)
106 {
107 BIO_LINEBUFFER_CTX *ctx;
108
109 ctx=(BIO_LINEBUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_LINEBUFFER_CTX));
110 if (ctx == NULL) return(0);
111 ctx->obuf=(char *)OPENSSL_malloc(DEFAULT_LINEBUFFER_SIZE);
112 if (ctx->obuf == NULL) { OPENSSL_free(ctx); return(0); }
113 ctx->obuf_size=DEFAULT_LINEBUFFER_SIZE;
114 ctx->obuf_len=0;
115
116 bi->init=1;
117 bi->ptr=(char *)ctx;
118 bi->flags=0;
119 return(1);
120 }
121
122static int linebuffer_free(BIO *a)
123 {
124 BIO_LINEBUFFER_CTX *b;
125
126 if (a == NULL) return(0);
127 b=(BIO_LINEBUFFER_CTX *)a->ptr;
128 if (b->obuf != NULL) OPENSSL_free(b->obuf);
129 OPENSSL_free(a->ptr);
130 a->ptr=NULL;
131 a->init=0;
132 a->flags=0;
133 return(1);
134 }
135
136static int linebuffer_read(BIO *b, char *out, int outl)
137 {
138 int ret=0;
139
140 if (out == NULL) return(0);
141 if (b->next_bio == NULL) return(0);
142 ret=BIO_read(b->next_bio,out,outl);
143 BIO_clear_retry_flags(b);
144 BIO_copy_next_retry(b);
145 return(ret);
146 }
147
148static int linebuffer_write(BIO *b, const char *in, int inl)
149 {
150 int i,num=0,foundnl;
151 BIO_LINEBUFFER_CTX *ctx;
152
153 if ((in == NULL) || (inl <= 0)) return(0);
154 ctx=(BIO_LINEBUFFER_CTX *)b->ptr;
155 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
156
157 BIO_clear_retry_flags(b);
158
159 do
160 {
161 const char *p;
162
163 for(p = in; p < in + inl && *p != '\n'; p++)
164 ;
165 if (*p == '\n')
166 {
167 p++;
168 foundnl = 1;
169 }
170 else
171 foundnl = 0;
172
173 /* If a NL was found and we already have text in the save
174 buffer, concatenate them and write */
175 while ((foundnl || p - in > ctx->obuf_size - ctx->obuf_len)
176 && ctx->obuf_len > 0)
177 {
178 int orig_olen = ctx->obuf_len;
179
180 i = ctx->obuf_size - ctx->obuf_len;
181 if (p - in > 0)
182 {
183 if (i >= p - in)
184 {
185 memcpy(&(ctx->obuf[ctx->obuf_len]),
186 in,p - in);
187 ctx->obuf_len += p - in;
188 inl -= p - in;
189 num += p - in;
190 in = p;
191 }
192 else
193 {
194 memcpy(&(ctx->obuf[ctx->obuf_len]),
195 in,i);
196 ctx->obuf_len += i;
197 inl -= i;
198 in += i;
199 num += i;
200 }
201 }
202
203#ifdef DEBUG
204BIO_write(b->next_bio, "<*<", 3);
205#endif
206 i=BIO_write(b->next_bio,
207 ctx->obuf, ctx->obuf_len);
208 if (i <= 0)
209 {
210 ctx->obuf_len = orig_olen;
211 BIO_copy_next_retry(b);
212
213#ifdef DEBUG
214BIO_write(b->next_bio, ">*>", 3);
215#endif
216 if (i < 0) return((num > 0)?num:i);
217 if (i == 0) return(num);
218 }
219#ifdef DEBUG
220BIO_write(b->next_bio, ">*>", 3);
221#endif
222 if (i < ctx->obuf_len)
223 memmove(ctx->obuf, ctx->obuf + i,
224 ctx->obuf_len - i);
225 ctx->obuf_len-=i;
226 }
227
228 /* Now that the save buffer is emptied, let's write the input
229 buffer if a NL was found and there is anything to write. */
230 if ((foundnl || p - in > ctx->obuf_size) && p - in > 0)
231 {
232#ifdef DEBUG
233BIO_write(b->next_bio, "<*<", 3);
234#endif
235 i=BIO_write(b->next_bio,in,p - in);
236 if (i <= 0)
237 {
238 BIO_copy_next_retry(b);
239#ifdef DEBUG
240BIO_write(b->next_bio, ">*>", 3);
241#endif
242 if (i < 0) return((num > 0)?num:i);
243 if (i == 0) return(num);
244 }
245#ifdef DEBUG
246BIO_write(b->next_bio, ">*>", 3);
247#endif
248 num+=i;
249 in+=i;
250 inl-=i;
251 }
252 }
253 while(foundnl && inl > 0);
254 /* We've written as much as we can. The rest of the input buffer, if
255 any, is text that doesn't and with a NL and therefore needs to be
256 saved for the next trip. */
257 if (inl > 0)
258 {
259 memcpy(&(ctx->obuf[ctx->obuf_len]), in, inl);
260 ctx->obuf_len += inl;
261 num += inl;
262 }
263 return num;
264 }
265
266static long linebuffer_ctrl(BIO *b, int cmd, long num, void *ptr)
267 {
268 BIO *dbio;
269 BIO_LINEBUFFER_CTX *ctx;
270 long ret=1;
271 char *p;
272 int r;
273 int obs;
274
275 ctx=(BIO_LINEBUFFER_CTX *)b->ptr;
276
277 switch (cmd)
278 {
279 case BIO_CTRL_RESET:
280 ctx->obuf_len=0;
281 if (b->next_bio == NULL) return(0);
282 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
283 break;
284 case BIO_CTRL_INFO:
285 ret=(long)ctx->obuf_len;
286 break;
287 case BIO_CTRL_WPENDING:
288 ret=(long)ctx->obuf_len;
289 if (ret == 0)
290 {
291 if (b->next_bio == NULL) return(0);
292 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
293 }
294 break;
295 case BIO_C_SET_BUFF_SIZE:
296 obs=(int)num;
297 p=ctx->obuf;
298 if ((obs > DEFAULT_LINEBUFFER_SIZE) && (obs != ctx->obuf_size))
299 {
300 p=(char *)OPENSSL_malloc((int)num);
301 if (p == NULL)
302 goto malloc_error;
303 }
304 if (ctx->obuf != p)
305 {
306 if (ctx->obuf_len > obs)
307 {
308 ctx->obuf_len = obs;
309 }
310 memcpy(p, ctx->obuf, ctx->obuf_len);
311 OPENSSL_free(ctx->obuf);
312 ctx->obuf=p;
313 ctx->obuf_size=obs;
314 }
315 break;
316 case BIO_C_DO_STATE_MACHINE:
317 if (b->next_bio == NULL) return(0);
318 BIO_clear_retry_flags(b);
319 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
320 BIO_copy_next_retry(b);
321 break;
322
323 case BIO_CTRL_FLUSH:
324 if (b->next_bio == NULL) return(0);
325 if (ctx->obuf_len <= 0)
326 {
327 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
328 break;
329 }
330
331 for (;;)
332 {
333 BIO_clear_retry_flags(b);
334 if (ctx->obuf_len > 0)
335 {
336 r=BIO_write(b->next_bio,
337 ctx->obuf, ctx->obuf_len);
338#if 0
339fprintf(stderr,"FLUSH %3d -> %3d\n",ctx->obuf_len,r);
340#endif
341 BIO_copy_next_retry(b);
342 if (r <= 0) return((long)r);
343 if (r < ctx->obuf_len)
344 memmove(ctx->obuf, ctx->obuf + r,
345 ctx->obuf_len - r);
346 ctx->obuf_len-=r;
347 }
348 else
349 {
350 ctx->obuf_len=0;
351 ret=1;
352 break;
353 }
354 }
355 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
356 break;
357 case BIO_CTRL_DUP:
358 dbio=(BIO *)ptr;
359 if ( !BIO_set_write_buffer_size(dbio,ctx->obuf_size))
360 ret=0;
361 break;
362 default:
363 if (b->next_bio == NULL) return(0);
364 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
365 break;
366 }
367 return(ret);
368malloc_error:
369 BIOerr(BIO_F_LINEBUFFER_CTRL,ERR_R_MALLOC_FAILURE);
370 return(0);
371 }
372
373static long linebuffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
374 {
375 long ret=1;
376
377 if (b->next_bio == NULL) return(0);
378 switch (cmd)
379 {
380 default:
381 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
382 break;
383 }
384 return(ret);
385 }
386
387static int linebuffer_gets(BIO *b, char *buf, int size)
388 {
389 if (b->next_bio == NULL) return(0);
390 return(BIO_gets(b->next_bio,buf,size));
391 }
392
393static int linebuffer_puts(BIO *b, const char *str)
394 {
395 return(linebuffer_write(b,str,strlen(str)));
396 }
397
diff --git a/src/lib/libcrypto/bio/bf_nbio.c b/src/lib/libcrypto/bio/bf_nbio.c
index 5e574b7231..413ef5c4c5 100644
--- a/src/lib/libcrypto/bio/bf_nbio.c
+++ b/src/lib/libcrypto/bio/bf_nbio.c
@@ -66,14 +66,14 @@
66/* BIO_put and BIO_get both add to the digest, 66/* BIO_put and BIO_get both add to the digest,
67 * BIO_gets returns the digest */ 67 * BIO_gets returns the digest */
68 68
69static int nbiof_write(BIO *h,char *buf,int num); 69static int nbiof_write(BIO *h,const char *buf,int num);
70static int nbiof_read(BIO *h,char *buf,int size); 70static int nbiof_read(BIO *h,char *buf,int size);
71static int nbiof_puts(BIO *h,char *str); 71static int nbiof_puts(BIO *h,const char *str);
72static int nbiof_gets(BIO *h,char *str,int size); 72static int nbiof_gets(BIO *h,char *str,int size);
73static long nbiof_ctrl(BIO *h,int cmd,long arg1,char *arg2); 73static long nbiof_ctrl(BIO *h,int cmd,long arg1,void *arg2);
74static int nbiof_new(BIO *h); 74static int nbiof_new(BIO *h);
75static int nbiof_free(BIO *data); 75static int nbiof_free(BIO *data);
76static long nbiof_callback_ctrl(BIO *h,int cmd,void (*fp)()); 76static long nbiof_callback_ctrl(BIO *h,int cmd,bio_info_cb *fp);
77typedef struct nbio_test_st 77typedef struct nbio_test_st
78 { 78 {
79 /* only set if we sent a 'should retry' error */ 79 /* only set if we sent a 'should retry' error */
@@ -104,7 +104,7 @@ static int nbiof_new(BIO *bi)
104 { 104 {
105 NBIO_TEST *nt; 105 NBIO_TEST *nt;
106 106
107 nt=(NBIO_TEST *)Malloc(sizeof(NBIO_TEST)); 107 nt=(NBIO_TEST *)OPENSSL_malloc(sizeof(NBIO_TEST));
108 nt->lrn= -1; 108 nt->lrn= -1;
109 nt->lwn= -1; 109 nt->lwn= -1;
110 bi->ptr=(char *)nt; 110 bi->ptr=(char *)nt;
@@ -117,7 +117,7 @@ static int nbiof_free(BIO *a)
117 { 117 {
118 if (a == NULL) return(0); 118 if (a == NULL) return(0);
119 if (a->ptr != NULL) 119 if (a->ptr != NULL)
120 Free(a->ptr); 120 OPENSSL_free(a->ptr);
121 a->ptr=NULL; 121 a->ptr=NULL;
122 a->init=0; 122 a->init=0;
123 a->flags=0; 123 a->flags=0;
@@ -159,7 +159,7 @@ static int nbiof_read(BIO *b, char *out, int outl)
159 return(ret); 159 return(ret);
160 } 160 }
161 161
162static int nbiof_write(BIO *b, char *in, int inl) 162static int nbiof_write(BIO *b, const char *in, int inl)
163 { 163 {
164 NBIO_TEST *nt; 164 NBIO_TEST *nt;
165 int ret=0; 165 int ret=0;
@@ -204,7 +204,7 @@ static int nbiof_write(BIO *b, char *in, int inl)
204 return(ret); 204 return(ret);
205 } 205 }
206 206
207static long nbiof_ctrl(BIO *b, int cmd, long num, char *ptr) 207static long nbiof_ctrl(BIO *b, int cmd, long num, void *ptr)
208 { 208 {
209 long ret; 209 long ret;
210 210
@@ -226,7 +226,7 @@ static long nbiof_ctrl(BIO *b, int cmd, long num, char *ptr)
226 return(ret); 226 return(ret);
227 } 227 }
228 228
229static long nbiof_callback_ctrl(BIO *b, int cmd, void (*fp)()) 229static long nbiof_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
230 { 230 {
231 long ret=1; 231 long ret=1;
232 232
@@ -247,7 +247,7 @@ static int nbiof_gets(BIO *bp, char *buf, int size)
247 } 247 }
248 248
249 249
250static int nbiof_puts(BIO *bp, char *str) 250static int nbiof_puts(BIO *bp, const char *str)
251 { 251 {
252 if (bp->next_bio == NULL) return(0); 252 if (bp->next_bio == NULL) return(0);
253 return(BIO_puts(bp->next_bio,str)); 253 return(BIO_puts(bp->next_bio,str));
diff --git a/src/lib/libcrypto/bio/bf_null.c b/src/lib/libcrypto/bio/bf_null.c
index 0d183a6d9a..2678a1a85d 100644
--- a/src/lib/libcrypto/bio/bf_null.c
+++ b/src/lib/libcrypto/bio/bf_null.c
@@ -65,14 +65,14 @@
65/* BIO_put and BIO_get both add to the digest, 65/* BIO_put and BIO_get both add to the digest,
66 * BIO_gets returns the digest */ 66 * BIO_gets returns the digest */
67 67
68static int nullf_write(BIO *h,char *buf,int num); 68static int nullf_write(BIO *h, const char *buf, int num);
69static int nullf_read(BIO *h,char *buf,int size); 69static int nullf_read(BIO *h, char *buf, int size);
70static int nullf_puts(BIO *h,char *str); 70static int nullf_puts(BIO *h, const char *str);
71static int nullf_gets(BIO *h,char *str,int size); 71static int nullf_gets(BIO *h, char *str, int size);
72static long nullf_ctrl(BIO *h,int cmd,long arg1,char *arg2); 72static long nullf_ctrl(BIO *h, int cmd, long arg1, void *arg2);
73static int nullf_new(BIO *h); 73static int nullf_new(BIO *h);
74static int nullf_free(BIO *data); 74static int nullf_free(BIO *data);
75static long nullf_callback_ctrl(BIO *h,int cmd,void (*fp)()); 75static long nullf_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
76static BIO_METHOD methods_nullf= 76static BIO_METHOD methods_nullf=
77 { 77 {
78 BIO_TYPE_NULL_FILTER, 78 BIO_TYPE_NULL_FILTER,
@@ -121,7 +121,7 @@ static int nullf_read(BIO *b, char *out, int outl)
121 return(ret); 121 return(ret);
122 } 122 }
123 123
124static int nullf_write(BIO *b, char *in, int inl) 124static int nullf_write(BIO *b, const char *in, int inl)
125 { 125 {
126 int ret=0; 126 int ret=0;
127 127
@@ -133,7 +133,7 @@ static int nullf_write(BIO *b, char *in, int inl)
133 return(ret); 133 return(ret);
134 } 134 }
135 135
136static long nullf_ctrl(BIO *b, int cmd, long num, char *ptr) 136static long nullf_ctrl(BIO *b, int cmd, long num, void *ptr)
137 { 137 {
138 long ret; 138 long ret;
139 139
@@ -154,7 +154,7 @@ static long nullf_ctrl(BIO *b, int cmd, long num, char *ptr)
154 return(ret); 154 return(ret);
155 } 155 }
156 156
157static long nullf_callback_ctrl(BIO *b, int cmd, void (*fp)()) 157static long nullf_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
158 { 158 {
159 long ret=1; 159 long ret=1;
160 160
@@ -175,7 +175,7 @@ static int nullf_gets(BIO *bp, char *buf, int size)
175 } 175 }
176 176
177 177
178static int nullf_puts(BIO *bp, char *str) 178static int nullf_puts(BIO *bp, const char *str)
179 { 179 {
180 if (bp->next_bio == NULL) return(0); 180 if (bp->next_bio == NULL) return(0);
181 return(BIO_puts(bp->next_bio,str)); 181 return(BIO_puts(bp->next_bio,str));
diff --git a/src/lib/libcrypto/bio/bio.h b/src/lib/libcrypto/bio/bio.h
index ebdb18170b..97003b503c 100644
--- a/src/lib/libcrypto/bio/bio.h
+++ b/src/lib/libcrypto/bio/bio.h
@@ -59,14 +59,17 @@
59#ifndef HEADER_BIO_H 59#ifndef HEADER_BIO_H
60#define HEADER_BIO_H 60#define HEADER_BIO_H
61 61
62#ifdef __cplusplus 62#ifndef NO_FP_API
63extern "C" { 63# include <stdio.h>
64#endif 64#endif
65#include <stdarg.h>
65 66
66#include <stdio.h>
67#include <stdlib.h>
68#include <openssl/crypto.h> 67#include <openssl/crypto.h>
69 68
69#ifdef __cplusplus
70extern "C" {
71#endif
72
70/* These are the 'types' of BIOs */ 73/* These are the 'types' of BIOs */
71#define BIO_TYPE_NONE 0 74#define BIO_TYPE_NONE 0
72#define BIO_TYPE_MEM (1|0x0400) 75#define BIO_TYPE_MEM (1|0x0400)
@@ -88,6 +91,7 @@ extern "C" {
88#define BIO_TYPE_NULL_FILTER (17|0x0200) 91#define BIO_TYPE_NULL_FILTER (17|0x0200)
89#define BIO_TYPE_BER (18|0x0200) /* BER -> bin filter */ 92#define BIO_TYPE_BER (18|0x0200) /* BER -> bin filter */
90#define BIO_TYPE_BIO (19|0x0400) /* (half a) BIO pair */ 93#define BIO_TYPE_BIO (19|0x0400) /* (half a) BIO pair */
94#define BIO_TYPE_LINEBUFFER (20|0x0200) /* filter */
91 95
92#define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */ 96#define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */
93#define BIO_TYPE_FILTER 0x0200 97#define BIO_TYPE_FILTER 0x0200
@@ -207,19 +211,23 @@ extern "C" {
207#define BIO_method_name(b) ((b)->method->name) 211#define BIO_method_name(b) ((b)->method->name)
208#define BIO_method_type(b) ((b)->method->type) 212#define BIO_method_type(b) ((b)->method->type)
209 213
214typedef struct bio_st BIO;
215
216typedef void bio_info_cb(struct bio_st *, int, const char *, int, long, long);
217
210#ifndef WIN16 218#ifndef WIN16
211typedef struct bio_method_st 219typedef struct bio_method_st
212 { 220 {
213 int type; 221 int type;
214 const char *name; 222 const char *name;
215 int (*bwrite)(); 223 int (*bwrite)(BIO *, const char *, int);
216 int (*bread)(); 224 int (*bread)(BIO *, char *, int);
217 int (*bputs)(); 225 int (*bputs)(BIO *, const char *);
218 int (*bgets)(); 226 int (*bgets)(BIO *, char *, int);
219 long (*ctrl)(); 227 long (*ctrl)(BIO *, int, long, void *);
220 int (*create)(); 228 int (*create)(BIO *);
221 int (*destroy)(); 229 int (*destroy)(BIO *);
222 long (*callback_ctrl)(); 230 long (*callback_ctrl)(BIO *, int, bio_info_cb *);
223 } BIO_METHOD; 231 } BIO_METHOD;
224#else 232#else
225typedef struct bio_method_st 233typedef struct bio_method_st
@@ -237,7 +245,7 @@ typedef struct bio_method_st
237 } BIO_METHOD; 245 } BIO_METHOD;
238#endif 246#endif
239 247
240typedef struct bio_st 248struct bio_st
241 { 249 {
242 BIO_METHOD *method; 250 BIO_METHOD *method;
243 /* bio, mode, argp, argi, argl, ret */ 251 /* bio, mode, argp, argi, argl, ret */
@@ -257,7 +265,9 @@ typedef struct bio_st
257 unsigned long num_write; 265 unsigned long num_write;
258 266
259 CRYPTO_EX_DATA ex_data; 267 CRYPTO_EX_DATA ex_data;
260 } BIO; 268 };
269
270DECLARE_STACK_OF(BIO)
261 271
262typedef struct bio_f_buffer_ctx_struct 272typedef struct bio_f_buffer_ctx_struct
263 { 273 {
@@ -454,8 +464,8 @@ int BIO_read_filename(BIO *b,const char *name);
454size_t BIO_ctrl_pending(BIO *b); 464size_t BIO_ctrl_pending(BIO *b);
455size_t BIO_ctrl_wpending(BIO *b); 465size_t BIO_ctrl_wpending(BIO *b);
456#define BIO_flush(b) (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL) 466#define BIO_flush(b) (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL)
457#define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0,(void (**)())(cbp)) 467#define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0,(bio_info_cb **)(cbp))
458#define BIO_set_info_callback(b,cb) (int)BIO_callback_ctrl(b,BIO_CTRL_SET_CALLBACK,(void (*)())(cb)) 468#define BIO_set_info_callback(b,cb) (int)BIO_callback_ctrl(b,BIO_CTRL_SET_CALLBACK,(bio_info_cb *)(cb))
459 469
460/* For the BIO_f_buffer() type */ 470/* For the BIO_f_buffer() type */
461#define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL) 471#define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL)
@@ -465,6 +475,7 @@ size_t BIO_ctrl_wpending(BIO *b);
465#define BIO_get_write_buf_size(b,size) (size_t)BIO_ctrl(b,BIO_C_GET_WRITE_BUF_SIZE,size,NULL) 475#define BIO_get_write_buf_size(b,size) (size_t)BIO_ctrl(b,BIO_C_GET_WRITE_BUF_SIZE,size,NULL)
466#define BIO_make_bio_pair(b1,b2) (int)BIO_ctrl(b1,BIO_C_MAKE_BIO_PAIR,0,b2) 476#define BIO_make_bio_pair(b1,b2) (int)BIO_ctrl(b1,BIO_C_MAKE_BIO_PAIR,0,b2)
467#define BIO_destroy_bio_pair(b) (int)BIO_ctrl(b,BIO_C_DESTROY_BIO_PAIR,0,NULL) 477#define BIO_destroy_bio_pair(b) (int)BIO_ctrl(b,BIO_C_DESTROY_BIO_PAIR,0,NULL)
478#define BIO_shutdown_wr(b) (int)BIO_ctrl(b, BIO_C_SHUTDOWN_WR, 0, NULL)
468/* macros with inappropriate type -- but ...pending macros use int too: */ 479/* macros with inappropriate type -- but ...pending macros use int too: */
469#define BIO_get_write_guarantee(b) (int)BIO_ctrl(b,BIO_C_GET_WRITE_GUARANTEE,0,NULL) 480#define BIO_get_write_guarantee(b) (int)BIO_ctrl(b,BIO_C_GET_WRITE_GUARANTEE,0,NULL)
470#define BIO_get_read_request(b) (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL) 481#define BIO_get_read_request(b) (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL)
@@ -472,11 +483,6 @@ size_t BIO_ctrl_get_write_guarantee(BIO *b);
472size_t BIO_ctrl_get_read_request(BIO *b); 483size_t BIO_ctrl_get_read_request(BIO *b);
473int BIO_ctrl_reset_read_request(BIO *b); 484int BIO_ctrl_reset_read_request(BIO *b);
474 485
475#ifdef NO_STDIO
476#define NO_FP_API
477#endif
478
479
480/* These two aren't currently implemented */ 486/* These two aren't currently implemented */
481/* int BIO_get_ex_num(BIO *bio); */ 487/* int BIO_get_ex_num(BIO *bio); */
482/* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */ 488/* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */
@@ -487,6 +493,7 @@ int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
487unsigned long BIO_number_read(BIO *bio); 493unsigned long BIO_number_read(BIO *bio);
488unsigned long BIO_number_written(BIO *bio); 494unsigned long BIO_number_written(BIO *bio);
489 495
496# ifndef NO_FP_API
490# if defined(WIN16) && defined(_WINDLL) 497# if defined(WIN16) && defined(_WINDLL)
491BIO_METHOD *BIO_s_file_internal(void); 498BIO_METHOD *BIO_s_file_internal(void);
492BIO *BIO_new_file_internal(char *filename, char *mode); 499BIO *BIO_new_file_internal(char *filename, char *mode);
@@ -502,21 +509,24 @@ BIO *BIO_new_fp(FILE *stream, int close_flag);
502# define BIO_new_file_internal BIO_new_file 509# define BIO_new_file_internal BIO_new_file
503# define BIO_new_fp_internal BIO_s_file 510# define BIO_new_fp_internal BIO_s_file
504# endif /* FP_API */ 511# endif /* FP_API */
512# endif
505BIO * BIO_new(BIO_METHOD *type); 513BIO * BIO_new(BIO_METHOD *type);
506int BIO_set(BIO *a,BIO_METHOD *type); 514int BIO_set(BIO *a,BIO_METHOD *type);
507int BIO_free(BIO *a); 515int BIO_free(BIO *a);
516void BIO_vfree(BIO *a);
508int BIO_read(BIO *b, void *data, int len); 517int BIO_read(BIO *b, void *data, int len);
509int BIO_gets(BIO *bp,char *buf, int size); 518int BIO_gets(BIO *bp,char *buf, int size);
510int BIO_write(BIO *b, const void *data, int len); 519int BIO_write(BIO *b, const void *data, int len);
511int BIO_puts(BIO *bp,const char *buf); 520int BIO_puts(BIO *bp,const char *buf);
512long BIO_ctrl(BIO *bp,int cmd,long larg,void *parg); 521long BIO_ctrl(BIO *bp,int cmd,long larg,void *parg);
513long BIO_callback_ctrl(BIO *bp,int cmd,void (*fp)()); 522long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long));
514char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg); 523char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg);
515long BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg); 524long BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg);
516BIO * BIO_push(BIO *b,BIO *append); 525BIO * BIO_push(BIO *b,BIO *append);
517BIO * BIO_pop(BIO *b); 526BIO * BIO_pop(BIO *b);
518void BIO_free_all(BIO *a); 527void BIO_free_all(BIO *a);
519BIO * BIO_find_type(BIO *b,int bio_type); 528BIO * BIO_find_type(BIO *b,int bio_type);
529BIO * BIO_next(BIO *b);
520BIO * BIO_get_retry_BIO(BIO *bio, int *reason); 530BIO * BIO_get_retry_BIO(BIO *bio, int *reason);
521int BIO_get_retry_reason(BIO *bio); 531int BIO_get_retry_reason(BIO *bio);
522BIO * BIO_dup_chain(BIO *in); 532BIO * BIO_dup_chain(BIO *in);
@@ -545,6 +555,9 @@ BIO_METHOD *BIO_s_bio(void);
545BIO_METHOD *BIO_s_null(void); 555BIO_METHOD *BIO_s_null(void);
546BIO_METHOD *BIO_f_null(void); 556BIO_METHOD *BIO_f_null(void);
547BIO_METHOD *BIO_f_buffer(void); 557BIO_METHOD *BIO_f_buffer(void);
558#ifdef VMS
559BIO_METHOD *BIO_f_linebuffer(void);
560#endif
548BIO_METHOD *BIO_f_nbio_test(void); 561BIO_METHOD *BIO_f_nbio_test(void);
549/* BIO_METHOD *BIO_f_ber(void); */ 562/* BIO_METHOD *BIO_f_ber(void); */
550 563
@@ -553,6 +566,7 @@ int BIO_sock_non_fatal_error(int error);
553int BIO_fd_should_retry(int i); 566int BIO_fd_should_retry(int i);
554int BIO_fd_non_fatal_error(int error); 567int BIO_fd_non_fatal_error(int error);
555int BIO_dump(BIO *b,const char *bytes,int len); 568int BIO_dump(BIO *b,const char *bytes,int len);
569int BIO_dump_indent(BIO *b,const char *bytes,int len,int indent);
556 570
557struct hostent *BIO_gethostbyname(const char *name); 571struct hostent *BIO_gethostbyname(const char *name);
558/* We might want a thread-safe interface too: 572/* We might want a thread-safe interface too:
@@ -592,7 +606,10 @@ void BIO_copy_next_retry(BIO *b);
592 606
593long BIO_ghbn_ctrl(int cmd,int iarg,char *parg); 607long BIO_ghbn_ctrl(int cmd,int iarg,char *parg);
594 608
595int BIO_printf(BIO *bio, ...); 609int BIO_printf(BIO *bio, const char *format, ...);
610int BIO_vprintf(BIO *bio, const char *format, va_list args);
611int BIO_snprintf(char *buf, size_t n, const char *format, ...);
612int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args);
596 613
597/* BEGIN ERROR CODES */ 614/* BEGIN ERROR CODES */
598/* The following lines are auto generated by the script mkerr.pl. Any changes 615/* The following lines are auto generated by the script mkerr.pl. Any changes
@@ -627,6 +644,8 @@ int BIO_printf(BIO *bio, ...);
627#define BIO_F_CONN_CTRL 127 644#define BIO_F_CONN_CTRL 127
628#define BIO_F_CONN_STATE 115 645#define BIO_F_CONN_STATE 115
629#define BIO_F_FILE_CTRL 116 646#define BIO_F_FILE_CTRL 116
647#define BIO_F_LINEBUFFER_CTRL 129
648#define BIO_F_MEM_READ 128
630#define BIO_F_MEM_WRITE 117 649#define BIO_F_MEM_WRITE 117
631#define BIO_F_SSL_NEW 118 650#define BIO_F_SSL_NEW 118
632#define BIO_F_WSASTARTUP 119 651#define BIO_F_WSASTARTUP 119
@@ -637,6 +656,7 @@ int BIO_printf(BIO *bio, ...);
637#define BIO_R_BAD_HOSTNAME_LOOKUP 102 656#define BIO_R_BAD_HOSTNAME_LOOKUP 102
638#define BIO_R_BROKEN_PIPE 124 657#define BIO_R_BROKEN_PIPE 124
639#define BIO_R_CONNECT_ERROR 103 658#define BIO_R_CONNECT_ERROR 103
659#define BIO_R_EOF_ON_MEMORY_BIO 127
640#define BIO_R_ERROR_SETTING_NBIO 104 660#define BIO_R_ERROR_SETTING_NBIO 104
641#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET 105 661#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET 105
642#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET 106 662#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET 106
diff --git a/src/lib/libcrypto/bio/bio_err.c b/src/lib/libcrypto/bio/bio_err.c
index f38e7b9178..bb815fb1e6 100644
--- a/src/lib/libcrypto/bio/bio_err.c
+++ b/src/lib/libcrypto/bio/bio_err.c
@@ -91,6 +91,8 @@ static ERR_STRING_DATA BIO_str_functs[]=
91{ERR_PACK(0,BIO_F_CONN_CTRL,0), "CONN_CTRL"}, 91{ERR_PACK(0,BIO_F_CONN_CTRL,0), "CONN_CTRL"},
92{ERR_PACK(0,BIO_F_CONN_STATE,0), "CONN_STATE"}, 92{ERR_PACK(0,BIO_F_CONN_STATE,0), "CONN_STATE"},
93{ERR_PACK(0,BIO_F_FILE_CTRL,0), "FILE_CTRL"}, 93{ERR_PACK(0,BIO_F_FILE_CTRL,0), "FILE_CTRL"},
94{ERR_PACK(0,BIO_F_LINEBUFFER_CTRL,0), "LINEBUFFER_CTRL"},
95{ERR_PACK(0,BIO_F_MEM_READ,0), "MEM_READ"},
94{ERR_PACK(0,BIO_F_MEM_WRITE,0), "MEM_WRITE"}, 96{ERR_PACK(0,BIO_F_MEM_WRITE,0), "MEM_WRITE"},
95{ERR_PACK(0,BIO_F_SSL_NEW,0), "SSL_new"}, 97{ERR_PACK(0,BIO_F_SSL_NEW,0), "SSL_new"},
96{ERR_PACK(0,BIO_F_WSASTARTUP,0), "WSASTARTUP"}, 98{ERR_PACK(0,BIO_F_WSASTARTUP,0), "WSASTARTUP"},
@@ -104,6 +106,7 @@ static ERR_STRING_DATA BIO_str_reasons[]=
104{BIO_R_BAD_HOSTNAME_LOOKUP ,"bad hostname lookup"}, 106{BIO_R_BAD_HOSTNAME_LOOKUP ,"bad hostname lookup"},
105{BIO_R_BROKEN_PIPE ,"broken pipe"}, 107{BIO_R_BROKEN_PIPE ,"broken pipe"},
106{BIO_R_CONNECT_ERROR ,"connect error"}, 108{BIO_R_CONNECT_ERROR ,"connect error"},
109{BIO_R_EOF_ON_MEMORY_BIO ,"EOF on memory BIO"},
107{BIO_R_ERROR_SETTING_NBIO ,"error setting nbio"}, 110{BIO_R_ERROR_SETTING_NBIO ,"error setting nbio"},
108{BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET,"error setting nbio on accepted socket"}, 111{BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET,"error setting nbio on accepted socket"},
109{BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET,"error setting nbio on accept socket"}, 112{BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET,"error setting nbio on accept socket"},
@@ -124,8 +127,8 @@ static ERR_STRING_DATA BIO_str_reasons[]=
124{BIO_R_UNABLE_TO_LISTEN_SOCKET ,"unable to listen socket"}, 127{BIO_R_UNABLE_TO_LISTEN_SOCKET ,"unable to listen socket"},
125{BIO_R_UNINITIALIZED ,"uninitialized"}, 128{BIO_R_UNINITIALIZED ,"uninitialized"},
126{BIO_R_UNSUPPORTED_METHOD ,"unsupported method"}, 129{BIO_R_UNSUPPORTED_METHOD ,"unsupported method"},
127{BIO_R_WRITE_TO_READ_ONLY_BIO ,"write to read only bio"}, 130{BIO_R_WRITE_TO_READ_ONLY_BIO ,"write to read only BIO"},
128{BIO_R_WSASTARTUP ,"wsastartup"}, 131{BIO_R_WSASTARTUP ,"WSAStartup"},
129{0,NULL} 132{0,NULL}
130 }; 133 };
131 134
diff --git a/src/lib/libcrypto/bio/bio_lib.c b/src/lib/libcrypto/bio/bio_lib.c
index e88dcc80f3..381afc9b8e 100644
--- a/src/lib/libcrypto/bio/bio_lib.c
+++ b/src/lib/libcrypto/bio/bio_lib.c
@@ -70,7 +70,7 @@ BIO *BIO_new(BIO_METHOD *method)
70 { 70 {
71 BIO *ret=NULL; 71 BIO *ret=NULL;
72 72
73 ret=(BIO *)Malloc(sizeof(BIO)); 73 ret=(BIO *)OPENSSL_malloc(sizeof(BIO));
74 if (ret == NULL) 74 if (ret == NULL)
75 { 75 {
76 BIOerr(BIO_F_BIO_NEW,ERR_R_MALLOC_FAILURE); 76 BIOerr(BIO_F_BIO_NEW,ERR_R_MALLOC_FAILURE);
@@ -78,7 +78,7 @@ BIO *BIO_new(BIO_METHOD *method)
78 } 78 }
79 if (!BIO_set(ret,method)) 79 if (!BIO_set(ret,method))
80 { 80 {
81 Free(ret); 81 OPENSSL_free(ret);
82 ret=NULL; 82 ret=NULL;
83 } 83 }
84 return(ret); 84 return(ret);
@@ -133,10 +133,13 @@ int BIO_free(BIO *a)
133 133
134 if ((a->method == NULL) || (a->method->destroy == NULL)) return(1); 134 if ((a->method == NULL) || (a->method->destroy == NULL)) return(1);
135 ret=a->method->destroy(a); 135 ret=a->method->destroy(a);
136 Free(a); 136 OPENSSL_free(a);
137 return(1); 137 return(1);
138 } 138 }
139 139
140void BIO_vfree(BIO *a)
141 { BIO_free(a); }
142
140int BIO_read(BIO *b, void *out, int outl) 143int BIO_read(BIO *b, void *out, int outl)
141 { 144 {
142 int i; 145 int i;
@@ -198,13 +201,7 @@ int BIO_write(BIO *b, const void *in, int inl)
198 201
199 if (i > 0) b->num_write+=(unsigned long)i; 202 if (i > 0) b->num_write+=(unsigned long)i;
200 203
201 /* This is evil and not thread safe. If the BIO has been freed, 204 if (cb != NULL)
202 * we must not call the callback. The only way to be able to
203 * determine this is the reference count which is now invalid since
204 * the memory has been free()ed.
205 */
206 if (b->references <= 0) abort();
207 if (cb != NULL) /* && (b->references >= 1)) */
208 i=(int)cb(b,BIO_CB_WRITE|BIO_CB_RETURN,in,inl, 205 i=(int)cb(b,BIO_CB_WRITE|BIO_CB_RETURN,in,inl,
209 0L,(long)i); 206 0L,(long)i);
210 return(i); 207 return(i);
@@ -235,6 +232,8 @@ int BIO_puts(BIO *b, const char *in)
235 232
236 i=b->method->bputs(b,in); 233 i=b->method->bputs(b,in);
237 234
235 if (i > 0) b->num_write+=(unsigned long)i;
236
238 if (cb != NULL) 237 if (cb != NULL)
239 i=(int)cb(b,BIO_CB_PUTS|BIO_CB_RETURN,in,0, 238 i=(int)cb(b,BIO_CB_PUTS|BIO_CB_RETURN,in,0,
240 0L,(long)i); 239 0L,(long)i);
@@ -317,7 +316,7 @@ long BIO_ctrl(BIO *b, int cmd, long larg, void *parg)
317 return(ret); 316 return(ret);
318 } 317 }
319 318
320long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)()) 319long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long))
321 { 320 {
322 long ret; 321 long ret;
323 long (*cb)(); 322 long (*cb)();
@@ -419,6 +418,7 @@ BIO *BIO_find_type(BIO *bio, int type)
419 { 418 {
420 int mt,mask; 419 int mt,mask;
421 420
421 if(!bio) return NULL;
422 mask=type&0xff; 422 mask=type&0xff;
423 do { 423 do {
424 if (bio->method != NULL) 424 if (bio->method != NULL)
@@ -437,6 +437,12 @@ BIO *BIO_find_type(BIO *bio, int type)
437 return(NULL); 437 return(NULL);
438 } 438 }
439 439
440BIO *BIO_next(BIO *b)
441 {
442 if(!b) return NULL;
443 return b->next_bio;
444 }
445
440void BIO_free_all(BIO *bio) 446void BIO_free_all(BIO *bio)
441 { 447 {
442 BIO *b; 448 BIO *b;
@@ -532,3 +538,5 @@ unsigned long BIO_number_written(BIO *bio)
532 if(bio) return bio->num_write; 538 if(bio) return bio->num_write;
533 return 0; 539 return 0;
534} 540}
541
542IMPLEMENT_STACK_OF(BIO)
diff --git a/src/lib/libcrypto/bio/bss_acpt.c b/src/lib/libcrypto/bio/bss_acpt.c
index 9afa636406..4da5822062 100644
--- a/src/lib/libcrypto/bio/bss_acpt.c
+++ b/src/lib/libcrypto/bio/bss_acpt.c
@@ -92,10 +92,10 @@ typedef struct bio_accept_st
92 BIO *bio_chain; 92 BIO *bio_chain;
93 } BIO_ACCEPT; 93 } BIO_ACCEPT;
94 94
95static int acpt_write(BIO *h,char *buf,int num); 95static int acpt_write(BIO *h, const char *buf, int num);
96static int acpt_read(BIO *h,char *buf,int size); 96static int acpt_read(BIO *h, char *buf, int size);
97static int acpt_puts(BIO *h,char *str); 97static int acpt_puts(BIO *h, const char *str);
98static long acpt_ctrl(BIO *h,int cmd,long arg1,char *arg2); 98static long acpt_ctrl(BIO *h, int cmd, long arg1, void *arg2);
99static int acpt_new(BIO *h); 99static int acpt_new(BIO *h);
100static int acpt_free(BIO *data); 100static int acpt_free(BIO *data);
101static int acpt_state(BIO *b, BIO_ACCEPT *c); 101static int acpt_state(BIO *b, BIO_ACCEPT *c);
@@ -145,7 +145,7 @@ BIO_ACCEPT *BIO_ACCEPT_new(void)
145 { 145 {
146 BIO_ACCEPT *ret; 146 BIO_ACCEPT *ret;
147 147
148 if ((ret=(BIO_ACCEPT *)Malloc(sizeof(BIO_ACCEPT))) == NULL) 148 if ((ret=(BIO_ACCEPT *)OPENSSL_malloc(sizeof(BIO_ACCEPT))) == NULL)
149 return(NULL); 149 return(NULL);
150 150
151 memset(ret,0,sizeof(BIO_ACCEPT)); 151 memset(ret,0,sizeof(BIO_ACCEPT));
@@ -159,10 +159,10 @@ void BIO_ACCEPT_free(BIO_ACCEPT *a)
159 if(a == NULL) 159 if(a == NULL)
160 return; 160 return;
161 161
162 if (a->param_addr != NULL) Free(a->param_addr); 162 if (a->param_addr != NULL) OPENSSL_free(a->param_addr);
163 if (a->addr != NULL) Free(a->addr); 163 if (a->addr != NULL) OPENSSL_free(a->addr);
164 if (a->bio_chain != NULL) BIO_free(a->bio_chain); 164 if (a->bio_chain != NULL) BIO_free(a->bio_chain);
165 Free(a); 165 OPENSSL_free(a);
166 } 166 }
167 167
168static void acpt_close_socket(BIO *bio) 168static void acpt_close_socket(BIO *bio)
@@ -307,7 +307,7 @@ static int acpt_read(BIO *b, char *out, int outl)
307 return(ret); 307 return(ret);
308 } 308 }
309 309
310static int acpt_write(BIO *b, char *in, int inl) 310static int acpt_write(BIO *b, const char *in, int inl)
311 { 311 {
312 int ret; 312 int ret;
313 BIO_ACCEPT *data; 313 BIO_ACCEPT *data;
@@ -326,7 +326,7 @@ static int acpt_write(BIO *b, char *in, int inl)
326 return(ret); 326 return(ret);
327 } 327 }
328 328
329static long acpt_ctrl(BIO *b, int cmd, long num, char *ptr) 329static long acpt_ctrl(BIO *b, int cmd, long num, void *ptr)
330 { 330 {
331 BIO *dbio; 331 BIO *dbio;
332 int *ip; 332 int *ip;
@@ -355,7 +355,7 @@ static long acpt_ctrl(BIO *b, int cmd, long num, char *ptr)
355 { 355 {
356 b->init=1; 356 b->init=1;
357 if (data->param_addr != NULL) 357 if (data->param_addr != NULL)
358 Free(data->param_addr); 358 OPENSSL_free(data->param_addr);
359 data->param_addr=BUF_strdup(ptr); 359 data->param_addr=BUF_strdup(ptr);
360 } 360 }
361 else if (num == 1) 361 else if (num == 1)
@@ -440,7 +440,7 @@ static long acpt_ctrl(BIO *b, int cmd, long num, char *ptr)
440 return(ret); 440 return(ret);
441 } 441 }
442 442
443static int acpt_puts(BIO *bp, char *str) 443static int acpt_puts(BIO *bp, const char *str)
444 { 444 {
445 int n,ret; 445 int n,ret;
446 446
diff --git a/src/lib/libcrypto/bio/bss_bio.c b/src/lib/libcrypto/bio/bss_bio.c
index 1e2d7491f2..78c6ab4fdd 100644
--- a/src/lib/libcrypto/bio/bss_bio.c
+++ b/src/lib/libcrypto/bio/bss_bio.c
@@ -30,9 +30,9 @@
30static int bio_new(BIO *bio); 30static int bio_new(BIO *bio);
31static int bio_free(BIO *bio); 31static int bio_free(BIO *bio);
32static int bio_read(BIO *bio, char *buf, int size); 32static int bio_read(BIO *bio, char *buf, int size);
33static int bio_write(BIO *bio, char *buf, int num); 33static int bio_write(BIO *bio, const char *buf, int num);
34static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr); 34static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr);
35static int bio_puts(BIO *bio, char *str); 35static int bio_puts(BIO *bio, const char *str);
36 36
37static int bio_make_pair(BIO *bio1, BIO *bio2); 37static int bio_make_pair(BIO *bio1, BIO *bio2);
38static void bio_destroy_pair(BIO *bio); 38static void bio_destroy_pair(BIO *bio);
@@ -80,7 +80,7 @@ static int bio_new(BIO *bio)
80 { 80 {
81 struct bio_bio_st *b; 81 struct bio_bio_st *b;
82 82
83 b = Malloc(sizeof *b); 83 b = OPENSSL_malloc(sizeof *b);
84 if (b == NULL) 84 if (b == NULL)
85 return 0; 85 return 0;
86 86
@@ -108,10 +108,10 @@ static int bio_free(BIO *bio)
108 108
109 if (b->buf != NULL) 109 if (b->buf != NULL)
110 { 110 {
111 Free(b->buf); 111 OPENSSL_free(b->buf);
112 } 112 }
113 113
114 Free(b); 114 OPENSSL_free(b);
115 115
116 return 1; 116 return 1;
117 } 117 }
@@ -283,7 +283,7 @@ static ssize_t bio_nread(BIO *bio, char **buf, size_t num_)
283 } 283 }
284 284
285 285
286static int bio_write(BIO *bio, char *buf, int num_) 286static int bio_write(BIO *bio, const char *buf, int num_)
287 { 287 {
288 size_t num = num_; 288 size_t num = num_;
289 size_t rest; 289 size_t rest;
@@ -464,7 +464,7 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr)
464 { 464 {
465 if (b->buf) 465 if (b->buf)
466 { 466 {
467 Free(b->buf); 467 OPENSSL_free(b->buf);
468 b->buf = NULL; 468 b->buf = NULL;
469 } 469 }
470 b->size = new_size; 470 b->size = new_size;
@@ -628,7 +628,7 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr)
628 return ret; 628 return ret;
629 } 629 }
630 630
631static int bio_puts(BIO *bio, char *str) 631static int bio_puts(BIO *bio, const char *str)
632 { 632 {
633 return bio_write(bio, str, strlen(str)); 633 return bio_write(bio, str, strlen(str));
634 } 634 }
@@ -652,7 +652,7 @@ static int bio_make_pair(BIO *bio1, BIO *bio2)
652 652
653 if (b1->buf == NULL) 653 if (b1->buf == NULL)
654 { 654 {
655 b1->buf = Malloc(b1->size); 655 b1->buf = OPENSSL_malloc(b1->size);
656 if (b1->buf == NULL) 656 if (b1->buf == NULL)
657 { 657 {
658 BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE); 658 BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE);
@@ -664,7 +664,7 @@ static int bio_make_pair(BIO *bio1, BIO *bio2)
664 664
665 if (b2->buf == NULL) 665 if (b2->buf == NULL)
666 { 666 {
667 b2->buf = Malloc(b2->size); 667 b2->buf = OPENSSL_malloc(b2->size);
668 if (b2->buf == NULL) 668 if (b2->buf == NULL)
669 { 669 {
670 BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE); 670 BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE);
diff --git a/src/lib/libcrypto/bio/bss_conn.c b/src/lib/libcrypto/bio/bss_conn.c
index 22d00b369e..a6b77a2cb9 100644
--- a/src/lib/libcrypto/bio/bss_conn.c
+++ b/src/lib/libcrypto/bio/bss_conn.c
@@ -98,13 +98,13 @@ typedef struct bio_connect_st
98 int (*info_callback)(); 98 int (*info_callback)();
99 } BIO_CONNECT; 99 } BIO_CONNECT;
100 100
101static int conn_write(BIO *h,char *buf,int num); 101static int conn_write(BIO *h, const char *buf, int num);
102static int conn_read(BIO *h,char *buf,int size); 102static int conn_read(BIO *h, char *buf, int size);
103static int conn_puts(BIO *h,char *str); 103static int conn_puts(BIO *h, const char *str);
104static long conn_ctrl(BIO *h,int cmd,long arg1,char *arg2); 104static long conn_ctrl(BIO *h, int cmd, long arg1, void *arg2);
105static int conn_new(BIO *h); 105static int conn_new(BIO *h);
106static int conn_free(BIO *data); 106static int conn_free(BIO *data);
107static long conn_callback_ctrl(BIO *h,int cmd,void *(*fp)()); 107static long conn_callback_ctrl(BIO *h, int cmd, bio_info_cb *);
108 108
109static int conn_state(BIO *b, BIO_CONNECT *c); 109static int conn_state(BIO *b, BIO_CONNECT *c);
110static void conn_close_socket(BIO *data); 110static void conn_close_socket(BIO *data);
@@ -165,7 +165,7 @@ static int conn_state(BIO *b, BIO_CONNECT *c)
165 break; 165 break;
166 } 166 }
167 if (c->param_port != NULL) 167 if (c->param_port != NULL)
168 Free(c->param_port); 168 OPENSSL_free(c->param_port);
169 c->param_port=BUF_strdup(p); 169 c->param_port=BUF_strdup(p);
170 } 170 }
171 } 171 }
@@ -188,7 +188,7 @@ static int conn_state(BIO *b, BIO_CONNECT *c)
188 case BIO_CONN_S_GET_PORT: 188 case BIO_CONN_S_GET_PORT:
189 if (c->param_port == NULL) 189 if (c->param_port == NULL)
190 { 190 {
191 abort(); 191 /* abort(); */
192 goto exit_loop; 192 goto exit_loop;
193 } 193 }
194 else if (BIO_get_port(c->param_port,&c->port) <= 0) 194 else if (BIO_get_port(c->param_port,&c->port) <= 0)
@@ -236,7 +236,7 @@ static int conn_state(BIO *b, BIO_CONNECT *c)
236 } 236 }
237 c->state=BIO_CONN_S_CONNECT; 237 c->state=BIO_CONN_S_CONNECT;
238 238
239#ifdef SO_KEEPALIVE 239#if defined(SO_KEEPALIVE) && !defined(MPE)
240 i=1; 240 i=1;
241 i=setsockopt(b->num,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i)); 241 i=setsockopt(b->num,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i));
242 if (i < 0) 242 if (i < 0)
@@ -299,7 +299,7 @@ static int conn_state(BIO *b, BIO_CONNECT *c)
299 ret=1; 299 ret=1;
300 goto exit_loop; 300 goto exit_loop;
301 default: 301 default:
302 abort(); 302 /* abort(); */
303 goto exit_loop; 303 goto exit_loop;
304 } 304 }
305 305
@@ -322,7 +322,7 @@ BIO_CONNECT *BIO_CONNECT_new(void)
322 { 322 {
323 BIO_CONNECT *ret; 323 BIO_CONNECT *ret;
324 324
325 if ((ret=(BIO_CONNECT *)Malloc(sizeof(BIO_CONNECT))) == NULL) 325 if ((ret=(BIO_CONNECT *)OPENSSL_malloc(sizeof(BIO_CONNECT))) == NULL)
326 return(NULL); 326 return(NULL);
327 ret->state=BIO_CONN_S_BEFORE; 327 ret->state=BIO_CONN_S_BEFORE;
328 ret->param_hostname=NULL; 328 ret->param_hostname=NULL;
@@ -344,10 +344,10 @@ void BIO_CONNECT_free(BIO_CONNECT *a)
344 return; 344 return;
345 345
346 if (a->param_hostname != NULL) 346 if (a->param_hostname != NULL)
347 Free(a->param_hostname); 347 OPENSSL_free(a->param_hostname);
348 if (a->param_port != NULL) 348 if (a->param_port != NULL)
349 Free(a->param_port); 349 OPENSSL_free(a->param_port);
350 Free(a); 350 OPENSSL_free(a);
351 } 351 }
352 352
353BIO_METHOD *BIO_s_connect(void) 353BIO_METHOD *BIO_s_connect(void)
@@ -426,7 +426,7 @@ static int conn_read(BIO *b, char *out, int outl)
426 return(ret); 426 return(ret);
427 } 427 }
428 428
429static int conn_write(BIO *b, char *in, int inl) 429static int conn_write(BIO *b, const char *in, int inl)
430 { 430 {
431 int ret; 431 int ret;
432 BIO_CONNECT *data; 432 BIO_CONNECT *data;
@@ -449,7 +449,7 @@ static int conn_write(BIO *b, char *in, int inl)
449 return(ret); 449 return(ret);
450 } 450 }
451 451
452static long conn_ctrl(BIO *b, int cmd, long num, char *ptr) 452static long conn_ctrl(BIO *b, int cmd, long num, void *ptr)
453 { 453 {
454 BIO *dbio; 454 BIO *dbio;
455 int *ip; 455 int *ip;
@@ -507,23 +507,24 @@ static long conn_ctrl(BIO *b, int cmd, long num, char *ptr)
507 if (num == 0) 507 if (num == 0)
508 { 508 {
509 if (data->param_hostname != NULL) 509 if (data->param_hostname != NULL)
510 Free(data->param_hostname); 510 OPENSSL_free(data->param_hostname);
511 data->param_hostname=BUF_strdup(ptr); 511 data->param_hostname=BUF_strdup(ptr);
512 } 512 }
513 else if (num == 1) 513 else if (num == 1)
514 { 514 {
515 if (data->param_port != NULL) 515 if (data->param_port != NULL)
516 Free(data->param_port); 516 OPENSSL_free(data->param_port);
517 data->param_port=BUF_strdup(ptr); 517 data->param_port=BUF_strdup(ptr);
518 } 518 }
519 else if (num == 2) 519 else if (num == 2)
520 { 520 {
521 char buf[16]; 521 char buf[16];
522 char *p = ptr;
522 523
523 sprintf(buf,"%d.%d.%d.%d", 524 sprintf(buf,"%d.%d.%d.%d",
524 ptr[0],ptr[1],ptr[2],ptr[3]); 525 p[0],p[1],p[2],p[3]);
525 if (data->param_hostname != NULL) 526 if (data->param_hostname != NULL)
526 Free(data->param_hostname); 527 OPENSSL_free(data->param_hostname);
527 data->param_hostname=BUF_strdup(buf); 528 data->param_hostname=BUF_strdup(buf);
528 memcpy(&(data->ip[0]),ptr,4); 529 memcpy(&(data->ip[0]),ptr,4);
529 } 530 }
@@ -533,7 +534,7 @@ static long conn_ctrl(BIO *b, int cmd, long num, char *ptr)
533 534
534 sprintf(buf,"%d",*(int *)ptr); 535 sprintf(buf,"%d",*(int *)ptr);
535 if (data->param_port != NULL) 536 if (data->param_port != NULL)
536 Free(data->param_port); 537 OPENSSL_free(data->param_port);
537 data->param_port=BUF_strdup(buf); 538 data->param_port=BUF_strdup(buf);
538 data->port= *(int *)ptr; 539 data->port= *(int *)ptr;
539 } 540 }
@@ -573,7 +574,7 @@ static long conn_ctrl(BIO *b, int cmd, long num, char *ptr)
573 if (data->param_hostname) 574 if (data->param_hostname)
574 BIO_set_conn_hostname(dbio,data->param_hostname); 575 BIO_set_conn_hostname(dbio,data->param_hostname);
575 BIO_set_nbio(dbio,data->nbio); 576 BIO_set_nbio(dbio,data->nbio);
576 (void)BIO_set_info_callback(dbio,(void *(*)())(data->info_callback)); 577 (void)BIO_set_info_callback(dbio,data->info_callback);
577 } 578 }
578 break; 579 break;
579 case BIO_CTRL_SET_CALLBACK: 580 case BIO_CTRL_SET_CALLBACK:
@@ -601,7 +602,7 @@ static long conn_ctrl(BIO *b, int cmd, long num, char *ptr)
601 return(ret); 602 return(ret);
602 } 603 }
603 604
604static long conn_callback_ctrl(BIO *b, int cmd, void *(*fp)()) 605static long conn_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
605 { 606 {
606 long ret=1; 607 long ret=1;
607 BIO_CONNECT *data; 608 BIO_CONNECT *data;
@@ -622,7 +623,7 @@ static long conn_callback_ctrl(BIO *b, int cmd, void *(*fp)())
622 return(ret); 623 return(ret);
623 } 624 }
624 625
625static int conn_puts(BIO *bp, char *str) 626static int conn_puts(BIO *bp, const char *str)
626 { 627 {
627 int n,ret; 628 int n,ret;
628 629
diff --git a/src/lib/libcrypto/bio/bss_file.c b/src/lib/libcrypto/bio/bss_file.c
index 0d44dc3889..1f770b390f 100644
--- a/src/lib/libcrypto/bio/bss_file.c
+++ b/src/lib/libcrypto/bio/bss_file.c
@@ -73,11 +73,11 @@
73 73
74#if !defined(NO_STDIO) 74#if !defined(NO_STDIO)
75 75
76static int MS_CALLBACK file_write(BIO *h,char *buf,int num); 76static int MS_CALLBACK file_write(BIO *h, const char *buf, int num);
77static int MS_CALLBACK file_read(BIO *h,char *buf,int size); 77static int MS_CALLBACK file_read(BIO *h, char *buf, int size);
78static int MS_CALLBACK file_puts(BIO *h,char *str); 78static int MS_CALLBACK file_puts(BIO *h, const char *str);
79static int MS_CALLBACK file_gets(BIO *h,char *str,int size); 79static int MS_CALLBACK file_gets(BIO *h, char *str, int size);
80static long MS_CALLBACK file_ctrl(BIO *h,int cmd,long arg1,char *arg2); 80static long MS_CALLBACK file_ctrl(BIO *h, int cmd, long arg1, void *arg2);
81static int MS_CALLBACK file_new(BIO *h); 81static int MS_CALLBACK file_new(BIO *h);
82static int MS_CALLBACK file_free(BIO *data); 82static int MS_CALLBACK file_free(BIO *data);
83static BIO_METHOD methods_filep= 83static BIO_METHOD methods_filep=
@@ -163,7 +163,7 @@ static int MS_CALLBACK file_read(BIO *b, char *out, int outl)
163 return(ret); 163 return(ret);
164 } 164 }
165 165
166static int MS_CALLBACK file_write(BIO *b, char *in, int inl) 166static int MS_CALLBACK file_write(BIO *b, const char *in, int inl)
167 { 167 {
168 int ret=0; 168 int ret=0;
169 169
@@ -179,7 +179,7 @@ static int MS_CALLBACK file_write(BIO *b, char *in, int inl)
179 return(ret); 179 return(ret);
180 } 180 }
181 181
182static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, char *ptr) 182static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr)
183 { 183 {
184 long ret=1; 184 long ret=1;
185 FILE *fp=(FILE *)b->ptr; 185 FILE *fp=(FILE *)b->ptr;
@@ -294,7 +294,7 @@ static int MS_CALLBACK file_gets(BIO *bp, char *buf, int size)
294 return(ret); 294 return(ret);
295 } 295 }
296 296
297static int MS_CALLBACK file_puts(BIO *bp, char *str) 297static int MS_CALLBACK file_puts(BIO *bp, const char *str)
298 { 298 {
299 int n,ret; 299 int n,ret;
300 300
diff --git a/src/lib/libcrypto/bio/bss_log.c b/src/lib/libcrypto/bio/bss_log.c
index 497eb1af72..1edf16a76f 100644
--- a/src/lib/libcrypto/bio/bss_log.c
+++ b/src/lib/libcrypto/bio/bss_log.c
@@ -110,14 +110,26 @@
110#define LOG_DAEMON OPC$M_NM_NTWORK 110#define LOG_DAEMON OPC$M_NM_NTWORK
111#endif 111#endif
112 112
113static int MS_CALLBACK slg_write(BIO *h,char *buf,int num); 113static int MS_CALLBACK slg_write(BIO *h, const char *buf, int num);
114static int MS_CALLBACK slg_puts(BIO *h,char *str); 114static int MS_CALLBACK slg_puts(BIO *h, const char *str);
115static long MS_CALLBACK slg_ctrl(BIO *h,int cmd,long arg1,char *arg2); 115static long MS_CALLBACK slg_ctrl(BIO *h, int cmd, long arg1, void *arg2);
116static int MS_CALLBACK slg_new(BIO *h); 116static int MS_CALLBACK slg_new(BIO *h);
117static int MS_CALLBACK slg_free(BIO *data); 117static int MS_CALLBACK slg_free(BIO *data);
118static void xopenlog(BIO* bp, const char* name, int level); 118static void xopenlog(BIO* bp, char* name, int level);
119static void xsyslog(BIO* bp, int priority, const char* string); 119static void xsyslog(BIO* bp, int priority, const char* string);
120static void xcloselog(BIO* bp); 120static void xcloselog(BIO* bp);
121#ifdef WIN32
122LONG (WINAPI *go_for_advapi)() = RegOpenKeyEx;
123HANDLE (WINAPI *register_event_source)() = NULL;
124BOOL (WINAPI *deregister_event_source)() = NULL;
125BOOL (WINAPI *report_event)() = NULL;
126#define DL_PROC(m,f) (GetProcAddress( m, f ))
127#ifdef UNICODE
128#define DL_PROC_X(m,f) DL_PROC( m, f "W" )
129#else
130#define DL_PROC_X(m,f) DL_PROC( m, f "A" )
131#endif
132#endif
121 133
122static BIO_METHOD methods_slg= 134static BIO_METHOD methods_slg=
123 { 135 {
@@ -153,40 +165,60 @@ static int MS_CALLBACK slg_free(BIO *a)
153 return(1); 165 return(1);
154 } 166 }
155 167
156static int MS_CALLBACK slg_write(BIO *b, char *in, int inl) 168static int MS_CALLBACK slg_write(BIO *b, const char *in, int inl)
157 { 169 {
158 int ret= inl; 170 int ret= inl;
159 char* buf= in; 171 char* buf;
160 char* pp; 172 char* pp;
161 int priority; 173 int priority, i;
162 174 static struct
163 if((buf= (char *)Malloc(inl+ 1)) == NULL){ 175 {
176 int strl;
177 char str[10];
178 int log_level;
179 }
180 mapping[] =
181 {
182 { 6, "PANIC ", LOG_EMERG },
183 { 6, "EMERG ", LOG_EMERG },
184 { 4, "EMR ", LOG_EMERG },
185 { 6, "ALERT ", LOG_ALERT },
186 { 4, "ALR ", LOG_ALERT },
187 { 5, "CRIT ", LOG_CRIT },
188 { 4, "CRI ", LOG_CRIT },
189 { 6, "ERROR ", LOG_ERR },
190 { 4, "ERR ", LOG_ERR },
191 { 8, "WARNING ", LOG_WARNING },
192 { 5, "WARN ", LOG_WARNING },
193 { 4, "WAR ", LOG_WARNING },
194 { 7, "NOTICE ", LOG_NOTICE },
195 { 5, "NOTE ", LOG_NOTICE },
196 { 4, "NOT ", LOG_NOTICE },
197 { 5, "INFO ", LOG_INFO },
198 { 4, "INF ", LOG_INFO },
199 { 6, "DEBUG ", LOG_DEBUG },
200 { 4, "DBG ", LOG_DEBUG },
201 { 0, "", LOG_ERR } /* The default */
202 };
203
204 if((buf= (char *)OPENSSL_malloc(inl+ 1)) == NULL){
164 return(0); 205 return(0);
165 } 206 }
166 strncpy(buf, in, inl); 207 strncpy(buf, in, inl);
167 buf[inl]= '\0'; 208 buf[inl]= '\0';
168 209
169 if(strncmp(buf, "ERR ", 4) == 0){ 210 i = 0;
170 priority= LOG_ERR; 211 while(strncmp(buf, mapping[i].str, mapping[i].strl) != 0) i++;
171 pp= buf+ 4; 212 priority = mapping[i].log_level;
172 }else if(strncmp(buf, "WAR ", 4) == 0){ 213 pp = buf + mapping[i].strl;
173 priority= LOG_WARNING;
174 pp= buf+ 4;
175 }else if(strncmp(buf, "INF ", 4) == 0){
176 priority= LOG_INFO;
177 pp= buf+ 4;
178 }else{
179 priority= LOG_ERR;
180 pp= buf;
181 }
182 214
183 xsyslog(b, priority, pp); 215 xsyslog(b, priority, pp);
184 216
185 Free(buf); 217 OPENSSL_free(buf);
186 return(ret); 218 return(ret);
187 } 219 }
188 220
189static long MS_CALLBACK slg_ctrl(BIO *b, int cmd, long num, char *ptr) 221static long MS_CALLBACK slg_ctrl(BIO *b, int cmd, long num, void *ptr)
190 { 222 {
191 switch (cmd) 223 switch (cmd)
192 { 224 {
@@ -200,7 +232,7 @@ static long MS_CALLBACK slg_ctrl(BIO *b, int cmd, long num, char *ptr)
200 return(0); 232 return(0);
201 } 233 }
202 234
203static int MS_CALLBACK slg_puts(BIO *bp, char *str) 235static int MS_CALLBACK slg_puts(BIO *bp, const char *str)
204 { 236 {
205 int n,ret; 237 int n,ret;
206 238
@@ -211,9 +243,29 @@ static int MS_CALLBACK slg_puts(BIO *bp, char *str)
211 243
212#if defined(WIN32) 244#if defined(WIN32)
213 245
214static void xopenlog(BIO* bp, const char* name, int level) 246static void xopenlog(BIO* bp, char* name, int level)
215{ 247{
216 bp->ptr= (char *)RegisterEventSource(NULL, name); 248 if ( !register_event_source )
249 {
250 HANDLE advapi;
251 if ( !(advapi = GetModuleHandle("advapi32")) )
252 return;
253 register_event_source = (HANDLE (WINAPI *)())DL_PROC_X(advapi,
254 "RegisterEventSource" );
255 deregister_event_source = (BOOL (WINAPI *)())DL_PROC(advapi,
256 "DeregisterEventSource");
257 report_event = (BOOL (WINAPI *)())DL_PROC_X(advapi,
258 "ReportEvent" );
259 if ( !(register_event_source && deregister_event_source &&
260 report_event) )
261 {
262 register_event_source = NULL;
263 deregister_event_source = NULL;
264 report_event = NULL;
265 return;
266 }
267 }
268 bp->ptr= (char *)register_event_source(NULL, name);
217} 269}
218 270
219static void xsyslog(BIO *bp, int priority, const char *string) 271static void xsyslog(BIO *bp, int priority, const char *string)
@@ -225,16 +277,22 @@ static void xsyslog(BIO *bp, int priority, const char *string)
225 277
226 switch (priority) 278 switch (priority)
227 { 279 {
280 case LOG_EMERG:
281 case LOG_ALERT:
282 case LOG_CRIT:
228 case LOG_ERR: 283 case LOG_ERR:
229 evtype = EVENTLOG_ERROR_TYPE; 284 evtype = EVENTLOG_ERROR_TYPE;
230 break; 285 break;
231 case LOG_WARNING: 286 case LOG_WARNING:
232 evtype = EVENTLOG_WARNING_TYPE; 287 evtype = EVENTLOG_WARNING_TYPE;
233 break; 288 break;
289 case LOG_NOTICE:
234 case LOG_INFO: 290 case LOG_INFO:
291 case LOG_DEBUG:
235 evtype = EVENTLOG_INFORMATION_TYPE; 292 evtype = EVENTLOG_INFORMATION_TYPE;
236 break; 293 break;
237 default: 294 default: /* Should never happen, but set it
295 as error anyway. */
238 evtype = EVENTLOG_ERROR_TYPE; 296 evtype = EVENTLOG_ERROR_TYPE;
239 break; 297 break;
240 } 298 }
@@ -243,15 +301,15 @@ static void xsyslog(BIO *bp, int priority, const char *string)
243 lpszStrings[0] = pidbuf; 301 lpszStrings[0] = pidbuf;
244 lpszStrings[1] = string; 302 lpszStrings[1] = string;
245 303
246 if(bp->ptr) 304 if(report_event && bp->ptr)
247 ReportEvent(bp->ptr, evtype, 0, 1024, NULL, 2, 0, 305 report_event(bp->ptr, evtype, 0, 1024, NULL, 2, 0,
248 lpszStrings, NULL); 306 lpszStrings, NULL);
249} 307}
250 308
251static void xcloselog(BIO* bp) 309static void xcloselog(BIO* bp)
252{ 310{
253 if(bp->ptr) 311 if(deregister_event_source && bp->ptr)
254 DeregisterEventSource((HANDLE)(bp->ptr)); 312 deregister_event_source((HANDLE)(bp->ptr));
255 bp->ptr= NULL; 313 bp->ptr= NULL;
256} 314}
257 315
@@ -259,7 +317,7 @@ static void xcloselog(BIO* bp)
259 317
260static int VMS_OPC_target = LOG_DAEMON; 318static int VMS_OPC_target = LOG_DAEMON;
261 319
262static void xopenlog(BIO* bp, const char* name, int level) 320static void xopenlog(BIO* bp, char* name, int level)
263{ 321{
264 VMS_OPC_target = level; 322 VMS_OPC_target = level;
265} 323}
@@ -294,7 +352,7 @@ static void xsyslog(BIO *bp, int priority, const char *string)
294 lib$sys_fao(&fao_cmd, &len, &buf_dsc, priority_tag, string); 352 lib$sys_fao(&fao_cmd, &len, &buf_dsc, priority_tag, string);
295 353
296 /* we know there's an 8 byte header. That's documented */ 354 /* we know there's an 8 byte header. That's documented */
297 opcdef_p = (struct opcdef *) Malloc(8 + len); 355 opcdef_p = (struct opcdef *) OPENSSL_malloc(8 + len);
298 opcdef_p->opc$b_ms_type = OPC$_RQ_RQST; 356 opcdef_p->opc$b_ms_type = OPC$_RQ_RQST;
299 memcpy(opcdef_p->opc$z_ms_target_classes, &VMS_OPC_target, 3); 357 memcpy(opcdef_p->opc$z_ms_target_classes, &VMS_OPC_target, 3);
300 opcdef_p->opc$l_ms_rqstid = 0; 358 opcdef_p->opc$l_ms_rqstid = 0;
@@ -307,7 +365,7 @@ static void xsyslog(BIO *bp, int priority, const char *string)
307 365
308 sys$sndopr(opc_dsc, 0); 366 sys$sndopr(opc_dsc, 0);
309 367
310 Free(opcdef_p); 368 OPENSSL_free(opcdef_p);
311} 369}
312 370
313static void xcloselog(BIO* bp) 371static void xcloselog(BIO* bp)
@@ -316,7 +374,7 @@ static void xcloselog(BIO* bp)
316 374
317#else /* Unix */ 375#else /* Unix */
318 376
319static void xopenlog(BIO* bp, const char* name, int level) 377static void xopenlog(BIO* bp, char* name, int level)
320{ 378{
321 openlog(name, LOG_PID|LOG_CONS, level); 379 openlog(name, LOG_PID|LOG_CONS, level);
322} 380}
diff --git a/src/lib/libcrypto/bio/bss_mem.c b/src/lib/libcrypto/bio/bss_mem.c
index 41eab92415..28ff7582bf 100644
--- a/src/lib/libcrypto/bio/bss_mem.c
+++ b/src/lib/libcrypto/bio/bss_mem.c
@@ -61,11 +61,11 @@
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include <openssl/bio.h> 62#include <openssl/bio.h>
63 63
64static int mem_write(BIO *h,char *buf,int num); 64static int mem_write(BIO *h, const char *buf, int num);
65static int mem_read(BIO *h,char *buf,int size); 65static int mem_read(BIO *h, char *buf, int size);
66static int mem_puts(BIO *h,char *str); 66static int mem_puts(BIO *h, const char *str);
67static int mem_gets(BIO *h,char *str,int size); 67static int mem_gets(BIO *h, char *str, int size);
68static long mem_ctrl(BIO *h,int cmd,long arg1,char *arg2); 68static long mem_ctrl(BIO *h, int cmd, long arg1, void *arg2);
69static int mem_new(BIO *h); 69static int mem_new(BIO *h);
70static int mem_free(BIO *data); 70static int mem_free(BIO *data);
71static BIO_METHOD mem_method= 71static BIO_METHOD mem_method=
@@ -163,14 +163,14 @@ static int mem_read(BIO *b, char *out, int outl)
163 } 163 }
164 } else if (bm->length == 0) 164 } else if (bm->length == 0)
165 { 165 {
166 if (b->num != 0) 166 ret = b->num;
167 if (ret != 0)
167 BIO_set_retry_read(b); 168 BIO_set_retry_read(b);
168 ret= b->num;
169 } 169 }
170 return(ret); 170 return(ret);
171 } 171 }
172 172
173static int mem_write(BIO *b, char *in, int inl) 173static int mem_write(BIO *b, const char *in, int inl)
174 { 174 {
175 int ret= -1; 175 int ret= -1;
176 int blen; 176 int blen;
@@ -198,7 +198,7 @@ end:
198 return(ret); 198 return(ret);
199 } 199 }
200 200
201static long mem_ctrl(BIO *b, int cmd, long num, char *ptr) 201static long mem_ctrl(BIO *b, int cmd, long num, void *ptr)
202 { 202 {
203 long ret=1; 203 long ret=1;
204 char **pptr; 204 char **pptr;
@@ -208,15 +208,20 @@ static long mem_ctrl(BIO *b, int cmd, long num, char *ptr)
208 switch (cmd) 208 switch (cmd)
209 { 209 {
210 case BIO_CTRL_RESET: 210 case BIO_CTRL_RESET:
211 if (bm->data != NULL) { 211 if (bm->data != NULL)
212 {
212 /* For read only case reset to the start again */ 213 /* For read only case reset to the start again */
213 if(b->flags & BIO_FLAGS_MEM_RDONLY) 214 if(b->flags & BIO_FLAGS_MEM_RDONLY)
214 bm->data -= bm->max - bm->length; 215 {
215 else { 216 bm->data -= bm->max - bm->length;
217 bm->length = bm->max;
218 }
219 else
220 {
216 memset(bm->data,0,bm->max); 221 memset(bm->data,0,bm->max);
217 bm->length=0; 222 bm->length=0;
223 }
218 } 224 }
219 }
220 break; 225 break;
221 case BIO_CTRL_EOF: 226 case BIO_CTRL_EOF:
222 ret=(long)(bm->length == 0); 227 ret=(long)(bm->length == 0);
@@ -300,7 +305,7 @@ static int mem_gets(BIO *bp, char *buf, int size)
300 return(ret); 305 return(ret);
301 } 306 }
302 307
303static int mem_puts(BIO *bp, char *str) 308static int mem_puts(BIO *bp, const char *str)
304 { 309 {
305 int n,ret; 310 int n,ret;
306 311
diff --git a/src/lib/libcrypto/bio/bss_null.c b/src/lib/libcrypto/bio/bss_null.c
index aee18e3ada..46b73339df 100644
--- a/src/lib/libcrypto/bio/bss_null.c
+++ b/src/lib/libcrypto/bio/bss_null.c
@@ -61,11 +61,11 @@
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include <openssl/bio.h> 62#include <openssl/bio.h>
63 63
64static int null_write(BIO *h,char *buf,int num); 64static int null_write(BIO *h, const char *buf, int num);
65static int null_read(BIO *h,char *buf,int size); 65static int null_read(BIO *h, char *buf, int size);
66static int null_puts(BIO *h,char *str); 66static int null_puts(BIO *h, const char *str);
67static int null_gets(BIO *h,char *str,int size); 67static int null_gets(BIO *h, char *str, int size);
68static long null_ctrl(BIO *h,int cmd,long arg1,char *arg2); 68static long null_ctrl(BIO *h, int cmd, long arg1, void *arg2);
69static int null_new(BIO *h); 69static int null_new(BIO *h);
70static int null_free(BIO *data); 70static int null_free(BIO *data);
71static BIO_METHOD null_method= 71static BIO_METHOD null_method=
@@ -106,12 +106,12 @@ static int null_read(BIO *b, char *out, int outl)
106 return(0); 106 return(0);
107 } 107 }
108 108
109static int null_write(BIO *b, char *in, int inl) 109static int null_write(BIO *b, const char *in, int inl)
110 { 110 {
111 return(inl); 111 return(inl);
112 } 112 }
113 113
114static long null_ctrl(BIO *b, int cmd, long num, char *ptr) 114static long null_ctrl(BIO *b, int cmd, long num, void *ptr)
115 { 115 {
116 long ret=1; 116 long ret=1;
117 117
@@ -142,7 +142,7 @@ static int null_gets(BIO *bp, char *buf, int size)
142 return(0); 142 return(0);
143 } 143 }
144 144
145static int null_puts(BIO *bp, char *str) 145static int null_puts(BIO *bp, const char *str)
146 { 146 {
147 if (str == NULL) return(0); 147 if (str == NULL) return(0);
148 return(strlen(str)); 148 return(strlen(str));
diff --git a/src/lib/libcrypto/bio/bss_rtcp.c b/src/lib/libcrypto/bio/bss_rtcp.c
index 4ad0739464..7dae485564 100644
--- a/src/lib/libcrypto/bio/bss_rtcp.c
+++ b/src/lib/libcrypto/bio/bss_rtcp.c
@@ -88,11 +88,11 @@ struct rpc_ctx {
88 struct rpc_msg msg; 88 struct rpc_msg msg;
89}; 89};
90 90
91static int rtcp_write(BIO *h,char *buf,int num); 91static int rtcp_write(BIO *h,const char *buf,int num);
92static int rtcp_read(BIO *h,char *buf,int size); 92static int rtcp_read(BIO *h,char *buf,int size);
93static int rtcp_puts(BIO *h,char *str); 93static int rtcp_puts(BIO *h,const char *str);
94static int rtcp_gets(BIO *h,char *str,int size); 94static int rtcp_gets(BIO *h,char *str,int size);
95static long rtcp_ctrl(BIO *h,int cmd,long arg1,char *arg2); 95static long rtcp_ctrl(BIO *h,int cmd,long arg1,void *arg2);
96static int rtcp_new(BIO *h); 96static int rtcp_new(BIO *h);
97static int rtcp_free(BIO *data); 97static int rtcp_free(BIO *data);
98 98
@@ -156,7 +156,7 @@ static int rtcp_new(BIO *bi)
156 bi->init=1; 156 bi->init=1;
157 bi->num=0; 157 bi->num=0;
158 bi->flags = 0; 158 bi->flags = 0;
159 bi->ptr=Malloc(sizeof(struct rpc_ctx)); 159 bi->ptr=OPENSSL_malloc(sizeof(struct rpc_ctx));
160 ctx = (struct rpc_ctx *) bi->ptr; 160 ctx = (struct rpc_ctx *) bi->ptr;
161 ctx->filled = 0; 161 ctx->filled = 0;
162 ctx->pos = 0; 162 ctx->pos = 0;
@@ -166,7 +166,7 @@ static int rtcp_new(BIO *bi)
166static int rtcp_free(BIO *a) 166static int rtcp_free(BIO *a)
167{ 167{
168 if (a == NULL) return(0); 168 if (a == NULL) return(0);
169 if ( a->ptr ) Free ( a->ptr ); 169 if ( a->ptr ) OPENSSL_free ( a->ptr );
170 a->ptr = NULL; 170 a->ptr = NULL;
171 return(1); 171 return(1);
172} 172}
@@ -218,7 +218,7 @@ static int rtcp_read(BIO *b, char *out, int outl)
218 return length; 218 return length;
219} 219}
220 220
221static int rtcp_write(BIO *b, char *in, int inl) 221static int rtcp_write(BIO *b, const char *in, int inl)
222{ 222{
223 int status, i, segment, length; 223 int status, i, segment, length;
224 struct rpc_ctx *ctx; 224 struct rpc_ctx *ctx;
@@ -247,7 +247,7 @@ static int rtcp_write(BIO *b, char *in, int inl)
247 return(i); 247 return(i);
248} 248}
249 249
250static long rtcp_ctrl(BIO *b, int cmd, long num, char *ptr) 250static long rtcp_ctrl(BIO *b, int cmd, long num, void *ptr)
251 { 251 {
252 long ret=1; 252 long ret=1;
253 253
@@ -283,7 +283,7 @@ static int rtcp_gets(BIO *bp, char *buf, int size)
283 return(0); 283 return(0);
284 } 284 }
285 285
286static int rtcp_puts(BIO *bp, char *str) 286static int rtcp_puts(BIO *bp, const char *str)
287{ 287{
288 int length; 288 int length;
289 if (str == NULL) return(0); 289 if (str == NULL) return(0);
diff --git a/src/lib/libcrypto/bio/bss_sock.c b/src/lib/libcrypto/bio/bss_sock.c
index 8ce80ef68d..50c6744c06 100644
--- a/src/lib/libcrypto/bio/bss_sock.c
+++ b/src/lib/libcrypto/bio/bss_sock.c
@@ -65,19 +65,19 @@
65#include <openssl/bio.h> 65#include <openssl/bio.h>
66 66
67#ifndef BIO_FD 67#ifndef BIO_FD
68static int sock_write(BIO *h,char *buf,int num); 68static int sock_write(BIO *h, const char *buf, int num);
69static int sock_read(BIO *h,char *buf,int size); 69static int sock_read(BIO *h, char *buf, int size);
70static int sock_puts(BIO *h,char *str); 70static int sock_puts(BIO *h, const char *str);
71static long sock_ctrl(BIO *h,int cmd,long arg1,char *arg2); 71static long sock_ctrl(BIO *h, int cmd, long arg1, void *arg2);
72static int sock_new(BIO *h); 72static int sock_new(BIO *h);
73static int sock_free(BIO *data); 73static int sock_free(BIO *data);
74int BIO_sock_should_retry(int s); 74int BIO_sock_should_retry(int s);
75#else 75#else
76 76
77static int fd_write(BIO *h,char *buf,int num); 77static int fd_write(BIO *h, const char *buf, int num);
78static int fd_read(BIO *h,char *buf,int size); 78static int fd_read(BIO *h, char *buf, int size);
79static int fd_puts(BIO *h,char *str); 79static int fd_puts(BIO *h, const char *str);
80static long fd_ctrl(BIO *h,int cmd,long arg1,char *arg2); 80static long fd_ctrl(BIO *h, int cmd, long arg1, void *arg2);
81static int fd_new(BIO *h); 81static int fd_new(BIO *h);
82static int fd_free(BIO *data); 82static int fd_free(BIO *data);
83int BIO_fd_should_retry(int s); 83int BIO_fd_should_retry(int s);
@@ -209,9 +209,9 @@ static int fd_read(BIO *b, char *out,int outl)
209 } 209 }
210 210
211#ifndef BIO_FD 211#ifndef BIO_FD
212static int sock_write(BIO *b, char *in, int inl) 212static int sock_write(BIO *b, const char *in, int inl)
213#else 213#else
214static int fd_write(BIO *b, char *in, int inl) 214static int fd_write(BIO *b, const char *in, int inl)
215#endif 215#endif
216 { 216 {
217 int ret; 217 int ret;
@@ -237,9 +237,9 @@ static int fd_write(BIO *b, char *in, int inl)
237 } 237 }
238 238
239#ifndef BIO_FD 239#ifndef BIO_FD
240static long sock_ctrl(BIO *b, int cmd, long num, char *ptr) 240static long sock_ctrl(BIO *b, int cmd, long num, void *ptr)
241#else 241#else
242static long fd_ctrl(BIO *b, int cmd, long num, char *ptr) 242static long fd_ctrl(BIO *b, int cmd, long num, void *ptr)
243#endif 243#endif
244 { 244 {
245 long ret=1; 245 long ret=1;
@@ -313,9 +313,9 @@ static int sock_gets(BIO *bp, char *buf,int size)
313#endif 313#endif
314 314
315#ifndef BIO_FD 315#ifndef BIO_FD
316static int sock_puts(BIO *bp, char *str) 316static int sock_puts(BIO *bp, const char *str)
317#else 317#else
318static int fd_puts(BIO *bp, char *str) 318static int fd_puts(BIO *bp, const char *str)
319#endif 319#endif
320 { 320 {
321 int n,ret; 321 int n,ret;