diff options
author | beck <> | 2000-03-19 11:13:58 +0000 |
---|---|---|
committer | beck <> | 2000-03-19 11:13:58 +0000 |
commit | 796d609550df3a33fc11468741c5d2f6d3df4c11 (patch) | |
tree | 6c6d539061caa20372dad0ac4ddb1dfae2fbe7fe /src/lib/libcrypto/bio | |
parent | 5be3114c1fd7e0dfea1e38d3abb4cbba75244419 (diff) | |
download | openbsd-796d609550df3a33fc11468741c5d2f6d3df4c11.tar.gz openbsd-796d609550df3a33fc11468741c5d2f6d3df4c11.tar.bz2 openbsd-796d609550df3a33fc11468741c5d2f6d3df4c11.zip |
OpenSSL 0.9.5 merge
*warning* this bumps shared lib minors for libssl and libcrypto from 2.1 to 2.2
if you are using the ssl26 packages for ssh and other things to work you will
need to get new ones (see ~beck/libsslsnap/<arch>) on cvs or ~beck/src-patent.tar.gz on cvs
Diffstat (limited to 'src/lib/libcrypto/bio')
-rw-r--r-- | src/lib/libcrypto/bio/Makefile.ssl | 48 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/b_dump.c | 4 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/b_print.c | 631 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/b_sock.c | 24 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bf_buff.c | 26 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bf_nbio.c | 20 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bf_null.c | 16 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bio.h | 54 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bio_err.c | 7 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bio_lib.c | 56 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_acpt.c | 1 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_bio.c | 256 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_conn.c | 42 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_file.c | 3 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_log.c | 14 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_mem.c | 58 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_null.c | 1 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_rtcp.c | 1 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_sock.c | 5 |
19 files changed, 1184 insertions, 83 deletions
diff --git a/src/lib/libcrypto/bio/Makefile.ssl b/src/lib/libcrypto/bio/Makefile.ssl index d9c381d263..2e7480ead9 100644 --- a/src/lib/libcrypto/bio/Makefile.ssl +++ b/src/lib/libcrypto/bio/Makefile.ssl | |||
@@ -90,17 +90,20 @@ b_dump.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | |||
90 | b_dump.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h | 90 | b_dump.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h |
91 | b_dump.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | 91 | b_dump.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h |
92 | b_dump.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | 92 | b_dump.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h |
93 | b_dump.o: ../../include/openssl/stack.h ../cryptlib.h | 93 | b_dump.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h |
94 | b_dump.o: ../cryptlib.h | ||
94 | b_print.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | 95 | b_print.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h |
95 | b_print.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h | 96 | b_print.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h |
96 | b_print.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | 97 | b_print.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h |
97 | b_print.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | 98 | b_print.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h |
98 | b_print.o: ../../include/openssl/stack.h ../cryptlib.h | 99 | b_print.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h |
100 | b_print.o: ../cryptlib.h | ||
99 | b_sock.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | 101 | b_sock.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h |
100 | b_sock.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h | 102 | b_sock.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h |
101 | b_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | 103 | b_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h |
102 | b_sock.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | 104 | b_sock.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h |
103 | b_sock.o: ../../include/openssl/stack.h ../cryptlib.h | 105 | b_sock.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h |
106 | b_sock.o: ../cryptlib.h | ||
104 | bf_buff.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | 107 | bf_buff.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h |
105 | bf_buff.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | 108 | bf_buff.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h |
106 | bf_buff.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | 109 | bf_buff.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h |
@@ -151,60 +154,65 @@ bio_cb.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | |||
151 | bio_cb.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h | 154 | bio_cb.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h |
152 | bio_cb.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | 155 | bio_cb.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h |
153 | bio_cb.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | 156 | bio_cb.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h |
154 | bio_cb.o: ../../include/openssl/stack.h ../cryptlib.h | 157 | bio_cb.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h |
158 | bio_cb.o: ../cryptlib.h | ||
155 | bio_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h | 159 | bio_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h |
156 | bio_err.o: ../../include/openssl/err.h ../../include/openssl/opensslv.h | 160 | bio_err.o: ../../include/openssl/err.h ../../include/openssl/opensslv.h |
157 | bio_err.o: ../../include/openssl/stack.h | 161 | bio_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h |
158 | bio_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | 162 | bio_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h |
159 | bio_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h | 163 | bio_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h |
160 | bio_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | 164 | bio_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h |
161 | bio_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | 165 | bio_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h |
162 | bio_lib.o: ../../include/openssl/stack.h ../cryptlib.h | 166 | bio_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h |
167 | bio_lib.o: ../cryptlib.h | ||
163 | bss_acpt.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | 168 | bss_acpt.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h |
164 | bss_acpt.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h | 169 | bss_acpt.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h |
165 | bss_acpt.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | 170 | bss_acpt.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h |
166 | bss_acpt.o: ../../include/openssl/opensslconf.h | 171 | bss_acpt.o: ../../include/openssl/opensslconf.h |
167 | bss_acpt.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h | 172 | bss_acpt.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h |
168 | bss_acpt.o: ../cryptlib.h | 173 | bss_acpt.o: ../../include/openssl/stack.h ../cryptlib.h |
169 | bss_bio.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h | 174 | bss_bio.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h |
170 | bss_bio.o: ../../include/openssl/err.h ../../include/openssl/opensslv.h | 175 | bss_bio.o: ../../include/openssl/err.h ../../include/openssl/opensslv.h |
171 | bss_bio.o: ../../include/openssl/stack.h | 176 | bss_bio.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h |
172 | bss_conn.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | 177 | bss_conn.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h |
173 | bss_conn.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h | 178 | bss_conn.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h |
174 | bss_conn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | 179 | bss_conn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h |
175 | bss_conn.o: ../../include/openssl/opensslconf.h | 180 | bss_conn.o: ../../include/openssl/opensslconf.h |
176 | bss_conn.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h | 181 | bss_conn.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h |
177 | bss_conn.o: ../cryptlib.h | 182 | bss_conn.o: ../../include/openssl/stack.h ../cryptlib.h |
178 | bss_fd.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | 183 | bss_fd.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h |
179 | bss_fd.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h | 184 | bss_fd.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h |
180 | bss_fd.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | 185 | bss_fd.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h |
181 | bss_fd.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | 186 | bss_fd.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h |
182 | bss_fd.o: ../../include/openssl/stack.h ../cryptlib.h bss_sock.c | 187 | bss_fd.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h |
188 | bss_fd.o: ../cryptlib.h bss_sock.c | ||
183 | bss_file.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | 189 | bss_file.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h |
184 | bss_file.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h | 190 | bss_file.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h |
185 | bss_file.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | 191 | bss_file.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h |
186 | bss_file.o: ../../include/openssl/opensslconf.h | 192 | bss_file.o: ../../include/openssl/opensslconf.h |
187 | bss_file.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h | 193 | bss_file.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h |
188 | bss_file.o: ../cryptlib.h | 194 | bss_file.o: ../../include/openssl/stack.h ../cryptlib.h |
189 | bss_log.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | 195 | bss_log.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h |
190 | bss_log.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h | 196 | bss_log.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h |
191 | bss_log.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | 197 | bss_log.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h |
192 | bss_log.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | 198 | bss_log.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h |
193 | bss_log.o: ../../include/openssl/stack.h ../cryptlib.h | 199 | bss_log.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h |
200 | bss_log.o: ../cryptlib.h | ||
194 | bss_mem.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | 201 | bss_mem.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h |
195 | bss_mem.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h | 202 | bss_mem.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h |
196 | bss_mem.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | 203 | bss_mem.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h |
197 | bss_mem.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | 204 | bss_mem.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h |
198 | bss_mem.o: ../../include/openssl/stack.h ../cryptlib.h | 205 | bss_mem.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h |
206 | bss_mem.o: ../cryptlib.h | ||
199 | bss_null.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | 207 | bss_null.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h |
200 | bss_null.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h | 208 | bss_null.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h |
201 | bss_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | 209 | bss_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h |
202 | bss_null.o: ../../include/openssl/opensslconf.h | 210 | bss_null.o: ../../include/openssl/opensslconf.h |
203 | bss_null.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h | 211 | bss_null.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h |
204 | bss_null.o: ../cryptlib.h | 212 | bss_null.o: ../../include/openssl/stack.h ../cryptlib.h |
205 | bss_sock.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | 213 | bss_sock.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h |
206 | bss_sock.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h | 214 | bss_sock.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h |
207 | bss_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | 215 | bss_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h |
208 | bss_sock.o: ../../include/openssl/opensslconf.h | 216 | bss_sock.o: ../../include/openssl/opensslconf.h |
209 | bss_sock.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h | 217 | bss_sock.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h |
210 | bss_sock.o: ../cryptlib.h | 218 | bss_sock.o: ../../include/openssl/stack.h ../cryptlib.h |
diff --git a/src/lib/libcrypto/bio/b_dump.c b/src/lib/libcrypto/bio/b_dump.c index a7cd828978..f5aeb237f5 100644 --- a/src/lib/libcrypto/bio/b_dump.c +++ b/src/lib/libcrypto/bio/b_dump.c | |||
@@ -92,7 +92,7 @@ int BIO_dump(BIO *bio, const char *s, int len) | |||
92 | if (((i*DUMP_WIDTH)+j)>=len) { | 92 | if (((i*DUMP_WIDTH)+j)>=len) { |
93 | strcat(buf," "); | 93 | strcat(buf," "); |
94 | } else { | 94 | } else { |
95 | ch=((unsigned char)*((char *)(s)+i*DUMP_WIDTH+j)) & 0xff; | 95 | ch=((unsigned char)*(s+i*DUMP_WIDTH+j)) & 0xff; |
96 | sprintf(tmp,"%02x%c",ch,j==7?'-':' '); | 96 | sprintf(tmp,"%02x%c",ch,j==7?'-':' '); |
97 | strcat(buf,tmp); | 97 | strcat(buf,tmp); |
98 | } | 98 | } |
@@ -101,7 +101,7 @@ int BIO_dump(BIO *bio, const char *s, int len) | |||
101 | for(j=0;j<DUMP_WIDTH;j++) { | 101 | for(j=0;j<DUMP_WIDTH;j++) { |
102 | if (((i*DUMP_WIDTH)+j)>=len) | 102 | if (((i*DUMP_WIDTH)+j)>=len) |
103 | break; | 103 | break; |
104 | ch=((unsigned char)*((char *)(s)+i*DUMP_WIDTH+j)) & 0xff; | 104 | ch=((unsigned char)*(s+i*DUMP_WIDTH+j)) & 0xff; |
105 | #ifndef CHARSET_EBCDIC | 105 | #ifndef CHARSET_EBCDIC |
106 | sprintf(tmp,"%c",((ch>=' ')&&(ch<='~'))?ch:'.'); | 106 | sprintf(tmp,"%c",((ch>=' ')&&(ch<='~'))?ch:'.'); |
107 | #else | 107 | #else |
diff --git a/src/lib/libcrypto/bio/b_print.c b/src/lib/libcrypto/bio/b_print.c index f448004298..2a5e8b58c9 100644 --- a/src/lib/libcrypto/bio/b_print.c +++ b/src/lib/libcrypto/bio/b_print.c | |||
@@ -62,26 +62,649 @@ | |||
62 | 62 | ||
63 | #include <stdio.h> | 63 | #include <stdio.h> |
64 | #include <stdarg.h> | 64 | #include <stdarg.h> |
65 | #include <string.h> | ||
66 | #include <ctype.h> | ||
65 | #include "cryptlib.h" | 67 | #include "cryptlib.h" |
68 | #ifndef NO_SYS_TYPES_H | ||
69 | #include <sys/types.h> | ||
70 | #endif | ||
66 | #include <openssl/bio.h> | 71 | #include <openssl/bio.h> |
67 | 72 | ||
73 | #ifdef BN_LLONG | ||
74 | # ifndef HAVE_LONG_LONG | ||
75 | # define HAVE_LONG_LONG | ||
76 | # endif | ||
77 | #endif | ||
78 | |||
79 | static void dopr (char *buffer, size_t maxlen, size_t *retlen, | ||
80 | const char *format, va_list args); | ||
81 | |||
68 | int BIO_printf (BIO *bio, ...) | 82 | int BIO_printf (BIO *bio, ...) |
69 | { | 83 | { |
70 | va_list args; | 84 | va_list args; |
71 | char *format; | 85 | char *format; |
72 | int ret; | 86 | int ret; |
87 | size_t retlen; | ||
73 | MS_STATIC char hugebuf[1024*2]; /* 10k in one chunk is the limit */ | 88 | MS_STATIC char hugebuf[1024*2]; /* 10k in one chunk is the limit */ |
74 | 89 | ||
75 | va_start(args, bio); | 90 | va_start(args, bio); |
76 | format=va_arg(args, char *); | 91 | format=va_arg(args, char *); |
77 | 92 | ||
78 | hugebuf[0]='\0'; | 93 | hugebuf[0]='\0'; |
79 | 94 | dopr(hugebuf, sizeof(hugebuf), &retlen, format, args); | |
80 | vsprintf(hugebuf,format,args); | 95 | ret=BIO_write(bio, hugebuf, (int)retlen); |
81 | |||
82 | ret=BIO_write(bio,hugebuf,strlen(hugebuf)); | ||
83 | 96 | ||
84 | va_end(args); | 97 | va_end(args); |
85 | return(ret); | 98 | return(ret); |
86 | } | 99 | } |
87 | 100 | ||
101 | /* | ||
102 | * Copyright Patrick Powell 1995 | ||
103 | * This code is based on code written by Patrick Powell <papowell@astart.com> | ||
104 | * It may be used for any purpose as long as this notice remains intact | ||
105 | * on all source code distributions. | ||
106 | */ | ||
107 | |||
108 | /* | ||
109 | * This code contains numerious changes and enhancements which were | ||
110 | * made by lots of contributors over the last years to Patrick Powell's | ||
111 | * original code: | ||
112 | * | ||
113 | * o Patrick Powell <papowell@astart.com> (1995) | ||
114 | * o Brandon Long <blong@fiction.net> (1996, for Mutt) | ||
115 | * o Thomas Roessler <roessler@guug.de> (1998, for Mutt) | ||
116 | * o Michael Elkins <me@cs.hmc.edu> (1998, for Mutt) | ||
117 | * o Andrew Tridgell <tridge@samba.org> (1998, for Samba) | ||
118 | * o Luke Mewburn <lukem@netbsd.org> (1999, for LukemFTP) | ||
119 | * o Ralf S. Engelschall <rse@engelschall.com> (1999, for Pth) | ||
120 | */ | ||
121 | |||
122 | #if HAVE_LONG_DOUBLE | ||
123 | #define LDOUBLE long double | ||
124 | #else | ||
125 | #define LDOUBLE double | ||
126 | #endif | ||
127 | |||
128 | #if HAVE_LONG_LONG | ||
129 | #define LLONG long long | ||
130 | #else | ||
131 | #define LLONG long | ||
132 | #endif | ||
133 | |||
134 | static void fmtstr (char *, size_t *, size_t, char *, int, int, int); | ||
135 | static void fmtint (char *, size_t *, size_t, LLONG, int, int, int, int); | ||
136 | static void fmtfp (char *, size_t *, size_t, LDOUBLE, int, int, int); | ||
137 | static void dopr_outch (char *, size_t *, size_t, int); | ||
138 | |||
139 | /* format read states */ | ||
140 | #define DP_S_DEFAULT 0 | ||
141 | #define DP_S_FLAGS 1 | ||
142 | #define DP_S_MIN 2 | ||
143 | #define DP_S_DOT 3 | ||
144 | #define DP_S_MAX 4 | ||
145 | #define DP_S_MOD 5 | ||
146 | #define DP_S_CONV 6 | ||
147 | #define DP_S_DONE 7 | ||
148 | |||
149 | /* format flags - Bits */ | ||
150 | #define DP_F_MINUS (1 << 0) | ||
151 | #define DP_F_PLUS (1 << 1) | ||
152 | #define DP_F_SPACE (1 << 2) | ||
153 | #define DP_F_NUM (1 << 3) | ||
154 | #define DP_F_ZERO (1 << 4) | ||
155 | #define DP_F_UP (1 << 5) | ||
156 | #define DP_F_UNSIGNED (1 << 6) | ||
157 | |||
158 | /* conversion flags */ | ||
159 | #define DP_C_SHORT 1 | ||
160 | #define DP_C_LONG 2 | ||
161 | #define DP_C_LDOUBLE 3 | ||
162 | #define DP_C_LLONG 4 | ||
163 | |||
164 | /* some handy macros */ | ||
165 | #define char_to_int(p) (p - '0') | ||
166 | #define MAX(p,q) ((p >= q) ? p : q) | ||
167 | |||
168 | static void | ||
169 | dopr( | ||
170 | char *buffer, | ||
171 | size_t maxlen, | ||
172 | size_t *retlen, | ||
173 | const char *format, | ||
174 | va_list args) | ||
175 | { | ||
176 | char ch; | ||
177 | LLONG value; | ||
178 | LDOUBLE fvalue; | ||
179 | char *strvalue; | ||
180 | int min; | ||
181 | int max; | ||
182 | int state; | ||
183 | int flags; | ||
184 | int cflags; | ||
185 | size_t currlen; | ||
186 | |||
187 | state = DP_S_DEFAULT; | ||
188 | flags = currlen = cflags = min = 0; | ||
189 | max = -1; | ||
190 | ch = *format++; | ||
191 | |||
192 | while (state != DP_S_DONE) { | ||
193 | if ((ch == '\0') || (currlen >= maxlen)) | ||
194 | state = DP_S_DONE; | ||
195 | |||
196 | switch (state) { | ||
197 | case DP_S_DEFAULT: | ||
198 | if (ch == '%') | ||
199 | state = DP_S_FLAGS; | ||
200 | else | ||
201 | dopr_outch(buffer, &currlen, maxlen, ch); | ||
202 | ch = *format++; | ||
203 | break; | ||
204 | case DP_S_FLAGS: | ||
205 | switch (ch) { | ||
206 | case '-': | ||
207 | flags |= DP_F_MINUS; | ||
208 | ch = *format++; | ||
209 | break; | ||
210 | case '+': | ||
211 | flags |= DP_F_PLUS; | ||
212 | ch = *format++; | ||
213 | break; | ||
214 | case ' ': | ||
215 | flags |= DP_F_SPACE; | ||
216 | ch = *format++; | ||
217 | break; | ||
218 | case '#': | ||
219 | flags |= DP_F_NUM; | ||
220 | ch = *format++; | ||
221 | break; | ||
222 | case '0': | ||
223 | flags |= DP_F_ZERO; | ||
224 | ch = *format++; | ||
225 | break; | ||
226 | default: | ||
227 | state = DP_S_MIN; | ||
228 | break; | ||
229 | } | ||
230 | break; | ||
231 | case DP_S_MIN: | ||
232 | if (isdigit((unsigned char)ch)) { | ||
233 | min = 10 * min + char_to_int(ch); | ||
234 | ch = *format++; | ||
235 | } else if (ch == '*') { | ||
236 | min = va_arg(args, int); | ||
237 | ch = *format++; | ||
238 | state = DP_S_DOT; | ||
239 | } else | ||
240 | state = DP_S_DOT; | ||
241 | break; | ||
242 | case DP_S_DOT: | ||
243 | if (ch == '.') { | ||
244 | state = DP_S_MAX; | ||
245 | ch = *format++; | ||
246 | } else | ||
247 | state = DP_S_MOD; | ||
248 | break; | ||
249 | case DP_S_MAX: | ||
250 | if (isdigit((unsigned char)ch)) { | ||
251 | if (max < 0) | ||
252 | max = 0; | ||
253 | max = 10 * max + char_to_int(ch); | ||
254 | ch = *format++; | ||
255 | } else if (ch == '*') { | ||
256 | max = va_arg(args, int); | ||
257 | ch = *format++; | ||
258 | state = DP_S_MOD; | ||
259 | } else | ||
260 | state = DP_S_MOD; | ||
261 | break; | ||
262 | case DP_S_MOD: | ||
263 | switch (ch) { | ||
264 | case 'h': | ||
265 | cflags = DP_C_SHORT; | ||
266 | ch = *format++; | ||
267 | break; | ||
268 | case 'l': | ||
269 | if (*format == 'l') { | ||
270 | cflags = DP_C_LLONG; | ||
271 | format++; | ||
272 | } else | ||
273 | cflags = DP_C_LONG; | ||
274 | ch = *format++; | ||
275 | break; | ||
276 | case 'q': | ||
277 | cflags = DP_C_LLONG; | ||
278 | ch = *format++; | ||
279 | break; | ||
280 | case 'L': | ||
281 | cflags = DP_C_LDOUBLE; | ||
282 | ch = *format++; | ||
283 | break; | ||
284 | default: | ||
285 | break; | ||
286 | } | ||
287 | state = DP_S_CONV; | ||
288 | break; | ||
289 | case DP_S_CONV: | ||
290 | switch (ch) { | ||
291 | case 'd': | ||
292 | case 'i': | ||
293 | switch (cflags) { | ||
294 | case DP_C_SHORT: | ||
295 | value = (short int)va_arg(args, int); | ||
296 | break; | ||
297 | case DP_C_LONG: | ||
298 | value = va_arg(args, long int); | ||
299 | break; | ||
300 | case DP_C_LLONG: | ||
301 | value = va_arg(args, LLONG); | ||
302 | break; | ||
303 | default: | ||
304 | value = va_arg(args, int); | ||
305 | break; | ||
306 | } | ||
307 | fmtint(buffer, &currlen, maxlen, value, 10, min, max, flags); | ||
308 | break; | ||
309 | case 'X': | ||
310 | flags |= DP_F_UP; | ||
311 | /* FALLTHROUGH */ | ||
312 | case 'x': | ||
313 | case 'o': | ||
314 | case 'u': | ||
315 | flags |= DP_F_UNSIGNED; | ||
316 | switch (cflags) { | ||
317 | case DP_C_SHORT: | ||
318 | value = (unsigned short int)va_arg(args, unsigned int); | ||
319 | break; | ||
320 | case DP_C_LONG: | ||
321 | value = (LLONG) va_arg(args, | ||
322 | unsigned long int); | ||
323 | break; | ||
324 | case DP_C_LLONG: | ||
325 | value = va_arg(args, unsigned LLONG); | ||
326 | break; | ||
327 | default: | ||
328 | value = (LLONG) va_arg(args, | ||
329 | unsigned int); | ||
330 | break; | ||
331 | } | ||
332 | fmtint(buffer, &currlen, maxlen, value, | ||
333 | ch == 'o' ? 8 : (ch == 'u' ? 10 : 16), | ||
334 | min, max, flags); | ||
335 | break; | ||
336 | case 'f': | ||
337 | if (cflags == DP_C_LDOUBLE) | ||
338 | fvalue = va_arg(args, LDOUBLE); | ||
339 | else | ||
340 | fvalue = va_arg(args, double); | ||
341 | fmtfp(buffer, &currlen, maxlen, fvalue, min, max, flags); | ||
342 | break; | ||
343 | case 'E': | ||
344 | flags |= DP_F_UP; | ||
345 | case 'e': | ||
346 | if (cflags == DP_C_LDOUBLE) | ||
347 | fvalue = va_arg(args, LDOUBLE); | ||
348 | else | ||
349 | fvalue = va_arg(args, double); | ||
350 | break; | ||
351 | case 'G': | ||
352 | flags |= DP_F_UP; | ||
353 | case 'g': | ||
354 | if (cflags == DP_C_LDOUBLE) | ||
355 | fvalue = va_arg(args, LDOUBLE); | ||
356 | else | ||
357 | fvalue = va_arg(args, double); | ||
358 | break; | ||
359 | case 'c': | ||
360 | dopr_outch(buffer, &currlen, maxlen, | ||
361 | va_arg(args, int)); | ||
362 | break; | ||
363 | case 's': | ||
364 | strvalue = va_arg(args, char *); | ||
365 | if (max < 0) | ||
366 | max = maxlen; | ||
367 | fmtstr(buffer, &currlen, maxlen, strvalue, | ||
368 | flags, min, max); | ||
369 | break; | ||
370 | case 'p': | ||
371 | value = (long)va_arg(args, void *); | ||
372 | fmtint(buffer, &currlen, maxlen, | ||
373 | value, 16, min, max, flags); | ||
374 | break; | ||
375 | case 'n': /* XXX */ | ||
376 | if (cflags == DP_C_SHORT) { | ||
377 | short int *num; | ||
378 | num = va_arg(args, short int *); | ||
379 | *num = currlen; | ||
380 | } else if (cflags == DP_C_LONG) { /* XXX */ | ||
381 | long int *num; | ||
382 | num = va_arg(args, long int *); | ||
383 | *num = (long int) currlen; | ||
384 | } else if (cflags == DP_C_LLONG) { /* XXX */ | ||
385 | LLONG *num; | ||
386 | num = va_arg(args, LLONG *); | ||
387 | *num = (LLONG) currlen; | ||
388 | } else { | ||
389 | int *num; | ||
390 | num = va_arg(args, int *); | ||
391 | *num = currlen; | ||
392 | } | ||
393 | break; | ||
394 | case '%': | ||
395 | dopr_outch(buffer, &currlen, maxlen, ch); | ||
396 | break; | ||
397 | case 'w': | ||
398 | /* not supported yet, treat as next char */ | ||
399 | ch = *format++; | ||
400 | break; | ||
401 | default: | ||
402 | /* unknown, skip */ | ||
403 | break; | ||
404 | } | ||
405 | ch = *format++; | ||
406 | state = DP_S_DEFAULT; | ||
407 | flags = cflags = min = 0; | ||
408 | max = -1; | ||
409 | break; | ||
410 | case DP_S_DONE: | ||
411 | break; | ||
412 | default: | ||
413 | break; | ||
414 | } | ||
415 | } | ||
416 | if (currlen >= maxlen - 1) | ||
417 | currlen = maxlen - 1; | ||
418 | buffer[currlen] = '\0'; | ||
419 | *retlen = currlen; | ||
420 | return; | ||
421 | } | ||
422 | |||
423 | static void | ||
424 | fmtstr( | ||
425 | char *buffer, | ||
426 | size_t *currlen, | ||
427 | size_t maxlen, | ||
428 | char *value, | ||
429 | int flags, | ||
430 | int min, | ||
431 | int max) | ||
432 | { | ||
433 | int padlen, strln; | ||
434 | int cnt = 0; | ||
435 | |||
436 | if (value == 0) | ||
437 | value = "<NULL>"; | ||
438 | for (strln = 0; value[strln]; ++strln) | ||
439 | ; | ||
440 | padlen = min - strln; | ||
441 | if (padlen < 0) | ||
442 | padlen = 0; | ||
443 | if (flags & DP_F_MINUS) | ||
444 | padlen = -padlen; | ||
445 | |||
446 | while ((padlen > 0) && (cnt < max)) { | ||
447 | dopr_outch(buffer, currlen, maxlen, ' '); | ||
448 | --padlen; | ||
449 | ++cnt; | ||
450 | } | ||
451 | while (*value && (cnt < max)) { | ||
452 | dopr_outch(buffer, currlen, maxlen, *value++); | ||
453 | ++cnt; | ||
454 | } | ||
455 | while ((padlen < 0) && (cnt < max)) { | ||
456 | dopr_outch(buffer, currlen, maxlen, ' '); | ||
457 | ++padlen; | ||
458 | ++cnt; | ||
459 | } | ||
460 | } | ||
461 | |||
462 | static void | ||
463 | fmtint( | ||
464 | char *buffer, | ||
465 | size_t *currlen, | ||
466 | size_t maxlen, | ||
467 | LLONG value, | ||
468 | int base, | ||
469 | int min, | ||
470 | int max, | ||
471 | int flags) | ||
472 | { | ||
473 | int signvalue = 0; | ||
474 | unsigned LLONG uvalue; | ||
475 | char convert[20]; | ||
476 | int place = 0; | ||
477 | int spadlen = 0; | ||
478 | int zpadlen = 0; | ||
479 | int caps = 0; | ||
480 | |||
481 | if (max < 0) | ||
482 | max = 0; | ||
483 | uvalue = value; | ||
484 | if (!(flags & DP_F_UNSIGNED)) { | ||
485 | if (value < 0) { | ||
486 | signvalue = '-'; | ||
487 | uvalue = -value; | ||
488 | } else if (flags & DP_F_PLUS) | ||
489 | signvalue = '+'; | ||
490 | else if (flags & DP_F_SPACE) | ||
491 | signvalue = ' '; | ||
492 | } | ||
493 | if (flags & DP_F_UP) | ||
494 | caps = 1; | ||
495 | do { | ||
496 | convert[place++] = | ||
497 | (caps ? "0123456789ABCDEF" : "0123456789abcdef") | ||
498 | [uvalue % (unsigned) base]; | ||
499 | uvalue = (uvalue / (unsigned) base); | ||
500 | } while (uvalue && (place < 20)); | ||
501 | if (place == 20) | ||
502 | place--; | ||
503 | convert[place] = 0; | ||
504 | |||
505 | zpadlen = max - place; | ||
506 | spadlen = min - MAX(max, place) - (signvalue ? 1 : 0); | ||
507 | if (zpadlen < 0) | ||
508 | zpadlen = 0; | ||
509 | if (spadlen < 0) | ||
510 | spadlen = 0; | ||
511 | if (flags & DP_F_ZERO) { | ||
512 | zpadlen = MAX(zpadlen, spadlen); | ||
513 | spadlen = 0; | ||
514 | } | ||
515 | if (flags & DP_F_MINUS) | ||
516 | spadlen = -spadlen; | ||
517 | |||
518 | /* spaces */ | ||
519 | while (spadlen > 0) { | ||
520 | dopr_outch(buffer, currlen, maxlen, ' '); | ||
521 | --spadlen; | ||
522 | } | ||
523 | |||
524 | /* sign */ | ||
525 | if (signvalue) | ||
526 | dopr_outch(buffer, currlen, maxlen, signvalue); | ||
527 | |||
528 | /* zeros */ | ||
529 | if (zpadlen > 0) { | ||
530 | while (zpadlen > 0) { | ||
531 | dopr_outch(buffer, currlen, maxlen, '0'); | ||
532 | --zpadlen; | ||
533 | } | ||
534 | } | ||
535 | /* digits */ | ||
536 | while (place > 0) | ||
537 | dopr_outch(buffer, currlen, maxlen, convert[--place]); | ||
538 | |||
539 | /* left justified spaces */ | ||
540 | while (spadlen < 0) { | ||
541 | dopr_outch(buffer, currlen, maxlen, ' '); | ||
542 | ++spadlen; | ||
543 | } | ||
544 | return; | ||
545 | } | ||
546 | |||
547 | static LDOUBLE | ||
548 | abs_val(LDOUBLE value) | ||
549 | { | ||
550 | LDOUBLE result = value; | ||
551 | if (value < 0) | ||
552 | result = -value; | ||
553 | return result; | ||
554 | } | ||
555 | |||
556 | static LDOUBLE | ||
557 | pow10(int exp) | ||
558 | { | ||
559 | LDOUBLE result = 1; | ||
560 | while (exp) { | ||
561 | result *= 10; | ||
562 | exp--; | ||
563 | } | ||
564 | return result; | ||
565 | } | ||
566 | |||
567 | static long | ||
568 | round(LDOUBLE value) | ||
569 | { | ||
570 | long intpart; | ||
571 | intpart = (long) value; | ||
572 | value = value - intpart; | ||
573 | if (value >= 0.5) | ||
574 | intpart++; | ||
575 | return intpart; | ||
576 | } | ||
577 | |||
578 | static void | ||
579 | fmtfp( | ||
580 | char *buffer, | ||
581 | size_t *currlen, | ||
582 | size_t maxlen, | ||
583 | LDOUBLE fvalue, | ||
584 | int min, | ||
585 | int max, | ||
586 | int flags) | ||
587 | { | ||
588 | int signvalue = 0; | ||
589 | LDOUBLE ufvalue; | ||
590 | char iconvert[20]; | ||
591 | char fconvert[20]; | ||
592 | int iplace = 0; | ||
593 | int fplace = 0; | ||
594 | int padlen = 0; | ||
595 | int zpadlen = 0; | ||
596 | int caps = 0; | ||
597 | long intpart; | ||
598 | long fracpart; | ||
599 | |||
600 | if (max < 0) | ||
601 | max = 6; | ||
602 | ufvalue = abs_val(fvalue); | ||
603 | if (fvalue < 0) | ||
604 | signvalue = '-'; | ||
605 | else if (flags & DP_F_PLUS) | ||
606 | signvalue = '+'; | ||
607 | else if (flags & DP_F_SPACE) | ||
608 | signvalue = ' '; | ||
609 | |||
610 | intpart = (long)ufvalue; | ||
611 | |||
612 | /* sorry, we only support 9 digits past the decimal because of our | ||
613 | conversion method */ | ||
614 | if (max > 9) | ||
615 | max = 9; | ||
616 | |||
617 | /* we "cheat" by converting the fractional part to integer by | ||
618 | multiplying by a factor of 10 */ | ||
619 | fracpart = round((pow10(max)) * (ufvalue - intpart)); | ||
620 | |||
621 | if (fracpart >= pow10(max)) { | ||
622 | intpart++; | ||
623 | fracpart -= (long)pow10(max); | ||
624 | } | ||
625 | |||
626 | /* convert integer part */ | ||
627 | do { | ||
628 | iconvert[iplace++] = | ||
629 | (caps ? "0123456789ABCDEF" | ||
630 | : "0123456789abcdef")[intpart % 10]; | ||
631 | intpart = (intpart / 10); | ||
632 | } while (intpart && (iplace < 20)); | ||
633 | if (iplace == 20) | ||
634 | iplace--; | ||
635 | iconvert[iplace] = 0; | ||
636 | |||
637 | /* convert fractional part */ | ||
638 | do { | ||
639 | fconvert[fplace++] = | ||
640 | (caps ? "0123456789ABCDEF" | ||
641 | : "0123456789abcdef")[fracpart % 10]; | ||
642 | fracpart = (fracpart / 10); | ||
643 | } while (fracpart && (fplace < 20)); | ||
644 | if (fplace == 20) | ||
645 | fplace--; | ||
646 | fconvert[fplace] = 0; | ||
647 | |||
648 | /* -1 for decimal point, another -1 if we are printing a sign */ | ||
649 | padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0); | ||
650 | zpadlen = max - fplace; | ||
651 | if (zpadlen < 0) | ||
652 | zpadlen = 0; | ||
653 | if (padlen < 0) | ||
654 | padlen = 0; | ||
655 | if (flags & DP_F_MINUS) | ||
656 | padlen = -padlen; | ||
657 | |||
658 | if ((flags & DP_F_ZERO) && (padlen > 0)) { | ||
659 | if (signvalue) { | ||
660 | dopr_outch(buffer, currlen, maxlen, signvalue); | ||
661 | --padlen; | ||
662 | signvalue = 0; | ||
663 | } | ||
664 | while (padlen > 0) { | ||
665 | dopr_outch(buffer, currlen, maxlen, '0'); | ||
666 | --padlen; | ||
667 | } | ||
668 | } | ||
669 | while (padlen > 0) { | ||
670 | dopr_outch(buffer, currlen, maxlen, ' '); | ||
671 | --padlen; | ||
672 | } | ||
673 | if (signvalue) | ||
674 | dopr_outch(buffer, currlen, maxlen, signvalue); | ||
675 | |||
676 | while (iplace > 0) | ||
677 | dopr_outch(buffer, currlen, maxlen, iconvert[--iplace]); | ||
678 | |||
679 | /* | ||
680 | * Decimal point. This should probably use locale to find the correct | ||
681 | * char to print out. | ||
682 | */ | ||
683 | if (max > 0) { | ||
684 | dopr_outch(buffer, currlen, maxlen, '.'); | ||
685 | |||
686 | while (fplace > 0) | ||
687 | dopr_outch(buffer, currlen, maxlen, fconvert[--fplace]); | ||
688 | } | ||
689 | while (zpadlen > 0) { | ||
690 | dopr_outch(buffer, currlen, maxlen, '0'); | ||
691 | --zpadlen; | ||
692 | } | ||
693 | |||
694 | while (padlen < 0) { | ||
695 | dopr_outch(buffer, currlen, maxlen, ' '); | ||
696 | ++padlen; | ||
697 | } | ||
698 | } | ||
699 | |||
700 | static void | ||
701 | dopr_outch( | ||
702 | char *buffer, | ||
703 | size_t *currlen, | ||
704 | size_t maxlen, | ||
705 | int c) | ||
706 | { | ||
707 | if (*currlen < maxlen) | ||
708 | buffer[(*currlen)++] = (char)c; | ||
709 | return; | ||
710 | } | ||
diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c index d29b29ff8b..6409f98f57 100644 --- a/src/lib/libcrypto/bio/b_sock.c +++ b/src/lib/libcrypto/bio/b_sock.c | |||
@@ -163,7 +163,14 @@ int BIO_get_port(const char *str, unsigned short *port_ptr) | |||
163 | else | 163 | else |
164 | { | 164 | { |
165 | CRYPTO_w_lock(CRYPTO_LOCK_GETSERVBYNAME); | 165 | CRYPTO_w_lock(CRYPTO_LOCK_GETSERVBYNAME); |
166 | s=getservbyname(str,"tcp"); | 166 | /* Note: under VMS with SOCKETSHR, it seems like the first |
167 | * parameter is 'char *', instead of 'const char *' | ||
168 | */ | ||
169 | s=getservbyname( | ||
170 | #ifndef CONST_STRICT | ||
171 | (char *) | ||
172 | #endif | ||
173 | str,"tcp"); | ||
167 | if(s != NULL) | 174 | if(s != NULL) |
168 | *port_ptr=ntohs((unsigned short)s->s_port); | 175 | *port_ptr=ntohs((unsigned short)s->s_port); |
169 | CRYPTO_w_unlock(CRYPTO_LOCK_GETSERVBYNAME); | 176 | CRYPTO_w_unlock(CRYPTO_LOCK_GETSERVBYNAME); |
@@ -282,12 +289,12 @@ static struct hostent *ghbn_dup(struct hostent *a) | |||
282 | 289 | ||
283 | j=strlen(a->h_name)+1; | 290 | j=strlen(a->h_name)+1; |
284 | if ((ret->h_name=Malloc(j)) == NULL) goto err; | 291 | if ((ret->h_name=Malloc(j)) == NULL) goto err; |
285 | memcpy((char *)ret->h_name,a->h_name,j+1); | 292 | memcpy((char *)ret->h_name,a->h_name,j); |
286 | for (i=0; a->h_aliases[i] != NULL; i++) | 293 | for (i=0; a->h_aliases[i] != NULL; i++) |
287 | { | 294 | { |
288 | j=strlen(a->h_aliases[i])+1; | 295 | j=strlen(a->h_aliases[i])+1; |
289 | if ((ret->h_aliases[i]=Malloc(j)) == NULL) goto err; | 296 | if ((ret->h_aliases[i]=Malloc(j)) == NULL) goto err; |
290 | memcpy(ret->h_aliases[i],a->h_aliases[i],j+1); | 297 | memcpy(ret->h_aliases[i],a->h_aliases[i],j); |
291 | } | 298 | } |
292 | ret->h_length=a->h_length; | 299 | ret->h_length=a->h_length; |
293 | ret->h_addrtype=a->h_addrtype; | 300 | ret->h_addrtype=a->h_addrtype; |
@@ -327,7 +334,7 @@ static void ghbn_free(struct hostent *a) | |||
327 | Free(a->h_addr_list[i]); | 334 | Free(a->h_addr_list[i]); |
328 | Free(a->h_addr_list); | 335 | Free(a->h_addr_list); |
329 | } | 336 | } |
330 | if (a->h_name != NULL) Free((char *)a->h_name); | 337 | if (a->h_name != NULL) Free(a->h_name); |
331 | Free(a); | 338 | Free(a); |
332 | } | 339 | } |
333 | 340 | ||
@@ -368,7 +375,14 @@ struct hostent *BIO_gethostbyname(const char *name) | |||
368 | if (i == GHBN_NUM) /* no hit*/ | 375 | if (i == GHBN_NUM) /* no hit*/ |
369 | { | 376 | { |
370 | BIO_ghbn_miss++; | 377 | BIO_ghbn_miss++; |
371 | ret=gethostbyname(name); | 378 | /* Note: under VMS with SOCKETSHR, it seems like the first |
379 | * parameter is 'char *', instead of 'const char *' | ||
380 | */ | ||
381 | ret=gethostbyname( | ||
382 | #ifndef CONST_STRICT | ||
383 | (char *) | ||
384 | #endif | ||
385 | name); | ||
372 | 386 | ||
373 | if (ret == NULL) | 387 | if (ret == NULL) |
374 | goto end; | 388 | goto end; |
diff --git a/src/lib/libcrypto/bio/bf_buff.c b/src/lib/libcrypto/bio/bf_buff.c index acd8148138..ff0c9070ae 100644 --- a/src/lib/libcrypto/bio/bf_buff.c +++ b/src/lib/libcrypto/bio/bf_buff.c | |||
@@ -69,6 +69,7 @@ static int buffer_gets(BIO *h,char *str,int size); | |||
69 | static long buffer_ctrl(BIO *h,int cmd,long arg1,char *arg2); | 69 | static long buffer_ctrl(BIO *h,int cmd,long arg1,char *arg2); |
70 | static int buffer_new(BIO *h); | 70 | static int buffer_new(BIO *h); |
71 | static int buffer_free(BIO *data); | 71 | static int buffer_free(BIO *data); |
72 | static long buffer_callback_ctrl(BIO *h,int cmd, void (*fp)()); | ||
72 | #define DEFAULT_BUFFER_SIZE 1024 | 73 | #define DEFAULT_BUFFER_SIZE 1024 |
73 | 74 | ||
74 | static BIO_METHOD methods_buffer= | 75 | static BIO_METHOD methods_buffer= |
@@ -82,6 +83,7 @@ static BIO_METHOD methods_buffer= | |||
82 | buffer_ctrl, | 83 | buffer_ctrl, |
83 | buffer_new, | 84 | buffer_new, |
84 | buffer_free, | 85 | buffer_free, |
86 | buffer_callback_ctrl, | ||
85 | }; | 87 | }; |
86 | 88 | ||
87 | BIO_METHOD *BIO_f_buffer(void) | 89 | BIO_METHOD *BIO_f_buffer(void) |
@@ -284,6 +286,7 @@ static long buffer_ctrl(BIO *b, int cmd, long num, char *ptr) | |||
284 | ctx->ibuf_len=0; | 286 | ctx->ibuf_len=0; |
285 | ctx->obuf_off=0; | 287 | ctx->obuf_off=0; |
286 | ctx->obuf_len=0; | 288 | ctx->obuf_len=0; |
289 | if (b->next_bio == NULL) return(0); | ||
287 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 290 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); |
288 | break; | 291 | break; |
289 | case BIO_CTRL_INFO: | 292 | case BIO_CTRL_INFO: |
@@ -300,12 +303,18 @@ static long buffer_ctrl(BIO *b, int cmd, long num, char *ptr) | |||
300 | case BIO_CTRL_WPENDING: | 303 | case BIO_CTRL_WPENDING: |
301 | ret=(long)ctx->obuf_len; | 304 | ret=(long)ctx->obuf_len; |
302 | if (ret == 0) | 305 | if (ret == 0) |
306 | { | ||
307 | if (b->next_bio == NULL) return(0); | ||
303 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 308 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); |
309 | } | ||
304 | break; | 310 | break; |
305 | case BIO_CTRL_PENDING: | 311 | case BIO_CTRL_PENDING: |
306 | ret=(long)ctx->ibuf_len; | 312 | ret=(long)ctx->ibuf_len; |
307 | if (ret == 0) | 313 | if (ret == 0) |
314 | { | ||
315 | if (b->next_bio == NULL) return(0); | ||
308 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 316 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); |
317 | } | ||
309 | break; | 318 | break; |
310 | case BIO_C_SET_BUFF_READ_DATA: | 319 | case BIO_C_SET_BUFF_READ_DATA: |
311 | if (num > ctx->ibuf_size) | 320 | if (num > ctx->ibuf_size) |
@@ -374,12 +383,14 @@ static long buffer_ctrl(BIO *b, int cmd, long num, char *ptr) | |||
374 | } | 383 | } |
375 | break; | 384 | break; |
376 | case BIO_C_DO_STATE_MACHINE: | 385 | case BIO_C_DO_STATE_MACHINE: |
386 | if (b->next_bio == NULL) return(0); | ||
377 | BIO_clear_retry_flags(b); | 387 | BIO_clear_retry_flags(b); |
378 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 388 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); |
379 | BIO_copy_next_retry(b); | 389 | BIO_copy_next_retry(b); |
380 | break; | 390 | break; |
381 | 391 | ||
382 | case BIO_CTRL_FLUSH: | 392 | case BIO_CTRL_FLUSH: |
393 | if (b->next_bio == NULL) return(0); | ||
383 | if (ctx->obuf_len <= 0) | 394 | if (ctx->obuf_len <= 0) |
384 | { | 395 | { |
385 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 396 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); |
@@ -418,6 +429,7 @@ fprintf(stderr,"FLUSH [%3d] %3d -> %3d\n",ctx->obuf_off,ctx->obuf_len-ctx->obuf_ | |||
418 | ret=0; | 429 | ret=0; |
419 | break; | 430 | break; |
420 | default: | 431 | default: |
432 | if (b->next_bio == NULL) return(0); | ||
421 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 433 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); |
422 | break; | 434 | break; |
423 | } | 435 | } |
@@ -427,6 +439,20 @@ malloc_error: | |||
427 | return(0); | 439 | return(0); |
428 | } | 440 | } |
429 | 441 | ||
442 | static long buffer_callback_ctrl(BIO *b, int cmd, void (*fp)()) | ||
443 | { | ||
444 | long ret=1; | ||
445 | |||
446 | if (b->next_bio == NULL) return(0); | ||
447 | switch (cmd) | ||
448 | { | ||
449 | default: | ||
450 | ret=BIO_callback_ctrl(b->next_bio,cmd,fp); | ||
451 | break; | ||
452 | } | ||
453 | return(ret); | ||
454 | } | ||
455 | |||
430 | static int buffer_gets(BIO *b, char *buf, int size) | 456 | static int buffer_gets(BIO *b, char *buf, int size) |
431 | { | 457 | { |
432 | BIO_F_BUFFER_CTX *ctx; | 458 | BIO_F_BUFFER_CTX *ctx; |
diff --git a/src/lib/libcrypto/bio/bf_nbio.c b/src/lib/libcrypto/bio/bf_nbio.c index cbec2bae29..5e574b7231 100644 --- a/src/lib/libcrypto/bio/bf_nbio.c +++ b/src/lib/libcrypto/bio/bf_nbio.c | |||
@@ -73,6 +73,7 @@ static int nbiof_gets(BIO *h,char *str,int size); | |||
73 | static long nbiof_ctrl(BIO *h,int cmd,long arg1,char *arg2); | 73 | static long nbiof_ctrl(BIO *h,int cmd,long arg1,char *arg2); |
74 | static int nbiof_new(BIO *h); | 74 | static int nbiof_new(BIO *h); |
75 | static int nbiof_free(BIO *data); | 75 | static int nbiof_free(BIO *data); |
76 | static long nbiof_callback_ctrl(BIO *h,int cmd,void (*fp)()); | ||
76 | typedef struct nbio_test_st | 77 | typedef struct nbio_test_st |
77 | { | 78 | { |
78 | /* only set if we sent a 'should retry' error */ | 79 | /* only set if we sent a 'should retry' error */ |
@@ -91,6 +92,7 @@ static BIO_METHOD methods_nbiof= | |||
91 | nbiof_ctrl, | 92 | nbiof_ctrl, |
92 | nbiof_new, | 93 | nbiof_new, |
93 | nbiof_free, | 94 | nbiof_free, |
95 | nbiof_callback_ctrl, | ||
94 | }; | 96 | }; |
95 | 97 | ||
96 | BIO_METHOD *BIO_f_nbio_test(void) | 98 | BIO_METHOD *BIO_f_nbio_test(void) |
@@ -137,7 +139,7 @@ static int nbiof_read(BIO *b, char *out, int outl) | |||
137 | 139 | ||
138 | BIO_clear_retry_flags(b); | 140 | BIO_clear_retry_flags(b); |
139 | #if 0 | 141 | #if 0 |
140 | RAND_bytes(&n,1); | 142 | RAND_pseudo_bytes(&n,1); |
141 | num=(n&0x07); | 143 | num=(n&0x07); |
142 | 144 | ||
143 | if (outl > num) outl=num; | 145 | if (outl > num) outl=num; |
@@ -178,7 +180,7 @@ static int nbiof_write(BIO *b, char *in, int inl) | |||
178 | } | 180 | } |
179 | else | 181 | else |
180 | { | 182 | { |
181 | RAND_bytes(&n,1); | 183 | RAND_pseudo_bytes(&n,1); |
182 | num=(n&7); | 184 | num=(n&7); |
183 | } | 185 | } |
184 | 186 | ||
@@ -224,6 +226,20 @@ static long nbiof_ctrl(BIO *b, int cmd, long num, char *ptr) | |||
224 | return(ret); | 226 | return(ret); |
225 | } | 227 | } |
226 | 228 | ||
229 | static long nbiof_callback_ctrl(BIO *b, int cmd, void (*fp)()) | ||
230 | { | ||
231 | long ret=1; | ||
232 | |||
233 | if (b->next_bio == NULL) return(0); | ||
234 | switch (cmd) | ||
235 | { | ||
236 | default: | ||
237 | ret=BIO_callback_ctrl(b->next_bio,cmd,fp); | ||
238 | break; | ||
239 | } | ||
240 | return(ret); | ||
241 | } | ||
242 | |||
227 | static int nbiof_gets(BIO *bp, char *buf, int size) | 243 | static int nbiof_gets(BIO *bp, char *buf, int size) |
228 | { | 244 | { |
229 | if (bp->next_bio == NULL) return(0); | 245 | if (bp->next_bio == NULL) return(0); |
diff --git a/src/lib/libcrypto/bio/bf_null.c b/src/lib/libcrypto/bio/bf_null.c index 3254a55dce..0d183a6d9a 100644 --- a/src/lib/libcrypto/bio/bf_null.c +++ b/src/lib/libcrypto/bio/bf_null.c | |||
@@ -72,6 +72,7 @@ static int nullf_gets(BIO *h,char *str,int size); | |||
72 | static long nullf_ctrl(BIO *h,int cmd,long arg1,char *arg2); | 72 | static long nullf_ctrl(BIO *h,int cmd,long arg1,char *arg2); |
73 | static int nullf_new(BIO *h); | 73 | static int nullf_new(BIO *h); |
74 | static int nullf_free(BIO *data); | 74 | static int nullf_free(BIO *data); |
75 | static long nullf_callback_ctrl(BIO *h,int cmd,void (*fp)()); | ||
75 | static BIO_METHOD methods_nullf= | 76 | static BIO_METHOD methods_nullf= |
76 | { | 77 | { |
77 | BIO_TYPE_NULL_FILTER, | 78 | BIO_TYPE_NULL_FILTER, |
@@ -83,6 +84,7 @@ static BIO_METHOD methods_nullf= | |||
83 | nullf_ctrl, | 84 | nullf_ctrl, |
84 | nullf_new, | 85 | nullf_new, |
85 | nullf_free, | 86 | nullf_free, |
87 | nullf_callback_ctrl, | ||
86 | }; | 88 | }; |
87 | 89 | ||
88 | BIO_METHOD *BIO_f_null(void) | 90 | BIO_METHOD *BIO_f_null(void) |
@@ -152,6 +154,20 @@ static long nullf_ctrl(BIO *b, int cmd, long num, char *ptr) | |||
152 | return(ret); | 154 | return(ret); |
153 | } | 155 | } |
154 | 156 | ||
157 | static long nullf_callback_ctrl(BIO *b, int cmd, void (*fp)()) | ||
158 | { | ||
159 | long ret=1; | ||
160 | |||
161 | if (b->next_bio == NULL) return(0); | ||
162 | switch (cmd) | ||
163 | { | ||
164 | default: | ||
165 | ret=BIO_callback_ctrl(b->next_bio,cmd,fp); | ||
166 | break; | ||
167 | } | ||
168 | return(ret); | ||
169 | } | ||
170 | |||
155 | static int nullf_gets(BIO *bp, char *buf, int size) | 171 | static int nullf_gets(BIO *bp, char *buf, int size) |
156 | { | 172 | { |
157 | if (bp->next_bio == NULL) return(0); | 173 | if (bp->next_bio == NULL) return(0); |
diff --git a/src/lib/libcrypto/bio/bio.h b/src/lib/libcrypto/bio/bio.h index 54bf622a3b..bc08401eeb 100644 --- a/src/lib/libcrypto/bio/bio.h +++ b/src/lib/libcrypto/bio/bio.h | |||
@@ -76,7 +76,7 @@ extern "C" { | |||
76 | #define BIO_TYPE_SOCKET (5|0x0400|0x0100) | 76 | #define BIO_TYPE_SOCKET (5|0x0400|0x0100) |
77 | #define BIO_TYPE_NULL (6|0x0400) | 77 | #define BIO_TYPE_NULL (6|0x0400) |
78 | #define BIO_TYPE_SSL (7|0x0200) | 78 | #define BIO_TYPE_SSL (7|0x0200) |
79 | #define BIO_TYPE_MD (8|0x0200) /* pasive filter */ | 79 | #define BIO_TYPE_MD (8|0x0200) /* passive filter */ |
80 | #define BIO_TYPE_BUFFER (9|0x0200) /* filter */ | 80 | #define BIO_TYPE_BUFFER (9|0x0200) /* filter */ |
81 | #define BIO_TYPE_CIPHER (10|0x0200) /* filter */ | 81 | #define BIO_TYPE_CIPHER (10|0x0200) /* filter */ |
82 | #define BIO_TYPE_BASE64 (11|0x0200) /* filter */ | 82 | #define BIO_TYPE_BASE64 (11|0x0200) /* filter */ |
@@ -147,6 +147,11 @@ extern "C" { | |||
147 | 147 | ||
148 | #define BIO_FLAGS_BASE64_NO_NL 0x100 | 148 | #define BIO_FLAGS_BASE64_NO_NL 0x100 |
149 | 149 | ||
150 | /* This is used with memory BIOs: it means we shouldn't free up or change the | ||
151 | * data in any way. | ||
152 | */ | ||
153 | #define BIO_FLAGS_MEM_RDONLY 0x200 | ||
154 | |||
150 | #define BIO_set_flags(b,f) ((b)->flags|=(f)) | 155 | #define BIO_set_flags(b,f) ((b)->flags|=(f)) |
151 | #define BIO_get_flags(b) ((b)->flags) | 156 | #define BIO_get_flags(b) ((b)->flags) |
152 | #define BIO_set_retry_special(b) \ | 157 | #define BIO_set_retry_special(b) \ |
@@ -163,7 +168,7 @@ extern "C" { | |||
163 | #define BIO_get_retry_flags(b) \ | 168 | #define BIO_get_retry_flags(b) \ |
164 | ((b)->flags&(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY)) | 169 | ((b)->flags&(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY)) |
165 | 170 | ||
166 | /* These shouldbe used by the application to tell why we should retry */ | 171 | /* These should be used by the application to tell why we should retry */ |
167 | #define BIO_should_read(a) ((a)->flags & BIO_FLAGS_READ) | 172 | #define BIO_should_read(a) ((a)->flags & BIO_FLAGS_READ) |
168 | #define BIO_should_write(a) ((a)->flags & BIO_FLAGS_WRITE) | 173 | #define BIO_should_write(a) ((a)->flags & BIO_FLAGS_WRITE) |
169 | #define BIO_should_io_special(a) ((a)->flags & BIO_FLAGS_IO_SPECIAL) | 174 | #define BIO_should_io_special(a) ((a)->flags & BIO_FLAGS_IO_SPECIAL) |
@@ -214,6 +219,7 @@ typedef struct bio_method_st | |||
214 | long (*ctrl)(); | 219 | long (*ctrl)(); |
215 | int (*create)(); | 220 | int (*create)(); |
216 | int (*destroy)(); | 221 | int (*destroy)(); |
222 | long (*callback_ctrl)(); | ||
217 | } BIO_METHOD; | 223 | } BIO_METHOD; |
218 | #else | 224 | #else |
219 | typedef struct bio_method_st | 225 | typedef struct bio_method_st |
@@ -227,6 +233,7 @@ typedef struct bio_method_st | |||
227 | long (_far *ctrl)(); | 233 | long (_far *ctrl)(); |
228 | int (_far *create)(); | 234 | int (_far *create)(); |
229 | int (_far *destroy)(); | 235 | int (_far *destroy)(); |
236 | long (_fat *callback_ctrl)(); | ||
230 | } BIO_METHOD; | 237 | } BIO_METHOD; |
231 | #endif | 238 | #endif |
232 | 239 | ||
@@ -278,9 +285,6 @@ typedef struct bio_f_buffer_ctx_struct | |||
278 | #define BIO_CONN_S_NBIO 8 | 285 | #define BIO_CONN_S_NBIO 8 |
279 | /*#define BIO_CONN_get_param_hostname BIO_ctrl */ | 286 | /*#define BIO_CONN_get_param_hostname BIO_ctrl */ |
280 | 287 | ||
281 | #define BIO_number_read(b) ((b)->num_read) | ||
282 | #define BIO_number_written(b) ((b)->num_write) | ||
283 | |||
284 | #define BIO_C_SET_CONNECT 100 | 288 | #define BIO_C_SET_CONNECT 100 |
285 | #define BIO_C_DO_STATE_MACHINE 101 | 289 | #define BIO_C_DO_STATE_MACHINE 101 |
286 | #define BIO_C_SET_NBIO 102 | 290 | #define BIO_C_SET_NBIO 102 |
@@ -325,9 +329,14 @@ typedef struct bio_f_buffer_ctx_struct | |||
325 | #define BIO_C_GET_WRITE_GUARANTEE 140 | 329 | #define BIO_C_GET_WRITE_GUARANTEE 140 |
326 | #define BIO_C_GET_READ_REQUEST 141 | 330 | #define BIO_C_GET_READ_REQUEST 141 |
327 | #define BIO_C_SHUTDOWN_WR 142 | 331 | #define BIO_C_SHUTDOWN_WR 142 |
332 | #define BIO_C_NREAD0 143 | ||
333 | #define BIO_C_NREAD 144 | ||
334 | #define BIO_C_NWRITE0 145 | ||
335 | #define BIO_C_NWRITE 146 | ||
336 | #define BIO_C_RESET_READ_REQUEST 147 | ||
328 | 337 | ||
329 | 338 | ||
330 | #define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,(char *)arg) | 339 | #define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,arg) |
331 | #define BIO_get_app_data(s) BIO_get_ex_data(s,0) | 340 | #define BIO_get_app_data(s) BIO_get_ex_data(s,0) |
332 | 341 | ||
333 | /* BIO_s_connect() and BIO_s_socks4a_connect() */ | 342 | /* BIO_s_connect() and BIO_s_socks4a_connect() */ |
@@ -366,7 +375,7 @@ typedef struct bio_f_buffer_ctx_struct | |||
366 | /* BIO_set_nbio(b,n) */ | 375 | /* BIO_set_nbio(b,n) */ |
367 | #define BIO_set_filter_bio(b,s) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,2,(char *)(s)) | 376 | #define BIO_set_filter_bio(b,s) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,2,(char *)(s)) |
368 | /* BIO *BIO_get_filter_bio(BIO *bio); */ | 377 | /* BIO *BIO_get_filter_bio(BIO *bio); */ |
369 | #define BIO_set_proxy_cb(b,cb) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,3,(char *)(cb)) | 378 | #define BIO_set_proxy_cb(b,cb) BIO_callback_ctrl(b,BIO_C_SET_PROXY_PARAM,3,(void *(*cb)())) |
370 | #define BIO_set_proxy_header(b,sk) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,4,(char *)sk) | 379 | #define BIO_set_proxy_header(b,sk) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,4,(char *)sk) |
371 | #define BIO_set_no_connect_return(b,bool) BIO_int_ctrl(b,BIO_C_SET_PROXY_PARAM,5,bool) | 380 | #define BIO_set_no_connect_return(b,bool) BIO_int_ctrl(b,BIO_C_SET_PROXY_PARAM,5,bool) |
372 | 381 | ||
@@ -445,8 +454,8 @@ int BIO_read_filename(BIO *b,const char *name); | |||
445 | size_t BIO_ctrl_pending(BIO *b); | 454 | size_t BIO_ctrl_pending(BIO *b); |
446 | size_t BIO_ctrl_wpending(BIO *b); | 455 | size_t BIO_ctrl_wpending(BIO *b); |
447 | #define BIO_flush(b) (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL) | 456 | #define BIO_flush(b) (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL) |
448 | #define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0,(char *)cbp) | 457 | #define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0,(void (**)())(cbp)) |
449 | #define BIO_set_info_callback(b,cb) (int)BIO_ctrl(b,BIO_CTRL_SET_CALLBACK,0,(char *)cb) | 458 | #define BIO_set_info_callback(b,cb) (int)BIO_callback_ctrl(b,BIO_CTRL_SET_CALLBACK,(void (*)())(cb)) |
450 | 459 | ||
451 | /* For the BIO_f_buffer() type */ | 460 | /* For the BIO_f_buffer() type */ |
452 | #define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL) | 461 | #define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL) |
@@ -461,8 +470,7 @@ size_t BIO_ctrl_wpending(BIO *b); | |||
461 | #define BIO_get_read_request(b) (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL) | 470 | #define BIO_get_read_request(b) (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL) |
462 | size_t BIO_ctrl_get_write_guarantee(BIO *b); | 471 | size_t BIO_ctrl_get_write_guarantee(BIO *b); |
463 | size_t BIO_ctrl_get_read_request(BIO *b); | 472 | size_t BIO_ctrl_get_read_request(BIO *b); |
464 | 473 | int BIO_ctrl_reset_read_request(BIO *b); | |
465 | |||
466 | 474 | ||
467 | #ifdef NO_STDIO | 475 | #ifdef NO_STDIO |
468 | #define NO_FP_API | 476 | #define NO_FP_API |
@@ -472,10 +480,12 @@ size_t BIO_ctrl_get_read_request(BIO *b); | |||
472 | /* These two aren't currently implemented */ | 480 | /* These two aren't currently implemented */ |
473 | /* int BIO_get_ex_num(BIO *bio); */ | 481 | /* int BIO_get_ex_num(BIO *bio); */ |
474 | /* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */ | 482 | /* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */ |
475 | int BIO_set_ex_data(BIO *bio,int idx,char *data); | 483 | int BIO_set_ex_data(BIO *bio,int idx,void *data); |
476 | char *BIO_get_ex_data(BIO *bio,int idx); | 484 | void *BIO_get_ex_data(BIO *bio,int idx); |
477 | int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), | 485 | int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, |
478 | int (*dup_func)(), void (*free_func)()); | 486 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); |
487 | unsigned long BIO_number_read(BIO *bio); | ||
488 | unsigned long BIO_number_written(BIO *bio); | ||
479 | 489 | ||
480 | # if defined(WIN16) && defined(_WINDLL) | 490 | # if defined(WIN16) && defined(_WINDLL) |
481 | BIO_METHOD *BIO_s_file_internal(void); | 491 | BIO_METHOD *BIO_s_file_internal(void); |
@@ -500,6 +510,7 @@ int BIO_gets(BIO *bp,char *buf, int size); | |||
500 | int BIO_write(BIO *b, const char *data, int len); | 510 | int BIO_write(BIO *b, const char *data, int len); |
501 | int BIO_puts(BIO *bp,const char *buf); | 511 | int BIO_puts(BIO *bp,const char *buf); |
502 | long BIO_ctrl(BIO *bp,int cmd,long larg,void *parg); | 512 | long BIO_ctrl(BIO *bp,int cmd,long larg,void *parg); |
513 | long BIO_callback_ctrl(BIO *bp,int cmd,void (*fp)()); | ||
503 | char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg); | 514 | char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg); |
504 | long BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg); | 515 | long BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg); |
505 | BIO * BIO_push(BIO *b,BIO *append); | 516 | BIO * BIO_push(BIO *b,BIO *append); |
@@ -510,6 +521,11 @@ BIO * BIO_get_retry_BIO(BIO *bio, int *reason); | |||
510 | int BIO_get_retry_reason(BIO *bio); | 521 | int BIO_get_retry_reason(BIO *bio); |
511 | BIO * BIO_dup_chain(BIO *in); | 522 | BIO * BIO_dup_chain(BIO *in); |
512 | 523 | ||
524 | int BIO_nread0(BIO *bio, char **buf); | ||
525 | int BIO_nread(BIO *bio, char **buf, int num); | ||
526 | int BIO_nwrite0(BIO *bio, char **buf); | ||
527 | int BIO_nwrite(BIO *bio, char **buf, int num); | ||
528 | |||
513 | #ifndef WIN16 | 529 | #ifndef WIN16 |
514 | long BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi, | 530 | long BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi, |
515 | long argl,long ret); | 531 | long argl,long ret); |
@@ -519,6 +535,7 @@ long _far _loadds BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi, | |||
519 | #endif | 535 | #endif |
520 | 536 | ||
521 | BIO_METHOD *BIO_s_mem(void); | 537 | BIO_METHOD *BIO_s_mem(void); |
538 | BIO *BIO_new_mem_buf(void *buf, int len); | ||
522 | BIO_METHOD *BIO_s_socket(void); | 539 | BIO_METHOD *BIO_s_socket(void); |
523 | BIO_METHOD *BIO_s_connect(void); | 540 | BIO_METHOD *BIO_s_connect(void); |
524 | BIO_METHOD *BIO_s_accept(void); | 541 | BIO_METHOD *BIO_s_accept(void); |
@@ -597,11 +614,17 @@ int BIO_printf(BIO *bio, ...); | |||
597 | #define BIO_F_BIO_MAKE_PAIR 121 | 614 | #define BIO_F_BIO_MAKE_PAIR 121 |
598 | #define BIO_F_BIO_NEW 108 | 615 | #define BIO_F_BIO_NEW 108 |
599 | #define BIO_F_BIO_NEW_FILE 109 | 616 | #define BIO_F_BIO_NEW_FILE 109 |
617 | #define BIO_F_BIO_NEW_MEM_BUF 126 | ||
618 | #define BIO_F_BIO_NREAD 123 | ||
619 | #define BIO_F_BIO_NREAD0 124 | ||
620 | #define BIO_F_BIO_NWRITE 125 | ||
621 | #define BIO_F_BIO_NWRITE0 122 | ||
600 | #define BIO_F_BIO_PUTS 110 | 622 | #define BIO_F_BIO_PUTS 110 |
601 | #define BIO_F_BIO_READ 111 | 623 | #define BIO_F_BIO_READ 111 |
602 | #define BIO_F_BIO_SOCK_INIT 112 | 624 | #define BIO_F_BIO_SOCK_INIT 112 |
603 | #define BIO_F_BIO_WRITE 113 | 625 | #define BIO_F_BIO_WRITE 113 |
604 | #define BIO_F_BUFFER_CTRL 114 | 626 | #define BIO_F_BUFFER_CTRL 114 |
627 | #define BIO_F_CONN_CTRL 127 | ||
605 | #define BIO_F_CONN_STATE 115 | 628 | #define BIO_F_CONN_STATE 115 |
606 | #define BIO_F_FILE_CTRL 116 | 629 | #define BIO_F_FILE_CTRL 116 |
607 | #define BIO_F_MEM_WRITE 117 | 630 | #define BIO_F_MEM_WRITE 117 |
@@ -634,6 +657,7 @@ int BIO_printf(BIO *bio, ...); | |||
634 | #define BIO_R_UNABLE_TO_LISTEN_SOCKET 119 | 657 | #define BIO_R_UNABLE_TO_LISTEN_SOCKET 119 |
635 | #define BIO_R_UNINITIALIZED 120 | 658 | #define BIO_R_UNINITIALIZED 120 |
636 | #define BIO_R_UNSUPPORTED_METHOD 121 | 659 | #define BIO_R_UNSUPPORTED_METHOD 121 |
660 | #define BIO_R_WRITE_TO_READ_ONLY_BIO 126 | ||
637 | #define BIO_R_WSASTARTUP 122 | 661 | #define BIO_R_WSASTARTUP 122 |
638 | 662 | ||
639 | #ifdef __cplusplus | 663 | #ifdef __cplusplus |
diff --git a/src/lib/libcrypto/bio/bio_err.c b/src/lib/libcrypto/bio/bio_err.c index 712d98a3a1..b5f07de5a0 100644 --- a/src/lib/libcrypto/bio/bio_err.c +++ b/src/lib/libcrypto/bio/bio_err.c | |||
@@ -77,11 +77,17 @@ static ERR_STRING_DATA BIO_str_functs[]= | |||
77 | {ERR_PACK(0,BIO_F_BIO_MAKE_PAIR,0), "BIO_MAKE_PAIR"}, | 77 | {ERR_PACK(0,BIO_F_BIO_MAKE_PAIR,0), "BIO_MAKE_PAIR"}, |
78 | {ERR_PACK(0,BIO_F_BIO_NEW,0), "BIO_new"}, | 78 | {ERR_PACK(0,BIO_F_BIO_NEW,0), "BIO_new"}, |
79 | {ERR_PACK(0,BIO_F_BIO_NEW_FILE,0), "BIO_new_file"}, | 79 | {ERR_PACK(0,BIO_F_BIO_NEW_FILE,0), "BIO_new_file"}, |
80 | {ERR_PACK(0,BIO_F_BIO_NEW_MEM_BUF,0), "BIO_new_mem_buf"}, | ||
81 | {ERR_PACK(0,BIO_F_BIO_NREAD,0), "BIO_nread"}, | ||
82 | {ERR_PACK(0,BIO_F_BIO_NREAD0,0), "BIO_nread0"}, | ||
83 | {ERR_PACK(0,BIO_F_BIO_NWRITE,0), "BIO_nwrite"}, | ||
84 | {ERR_PACK(0,BIO_F_BIO_NWRITE0,0), "BIO_nwrite0"}, | ||
80 | {ERR_PACK(0,BIO_F_BIO_PUTS,0), "BIO_puts"}, | 85 | {ERR_PACK(0,BIO_F_BIO_PUTS,0), "BIO_puts"}, |
81 | {ERR_PACK(0,BIO_F_BIO_READ,0), "BIO_read"}, | 86 | {ERR_PACK(0,BIO_F_BIO_READ,0), "BIO_read"}, |
82 | {ERR_PACK(0,BIO_F_BIO_SOCK_INIT,0), "BIO_sock_init"}, | 87 | {ERR_PACK(0,BIO_F_BIO_SOCK_INIT,0), "BIO_sock_init"}, |
83 | {ERR_PACK(0,BIO_F_BIO_WRITE,0), "BIO_write"}, | 88 | {ERR_PACK(0,BIO_F_BIO_WRITE,0), "BIO_write"}, |
84 | {ERR_PACK(0,BIO_F_BUFFER_CTRL,0), "BUFFER_CTRL"}, | 89 | {ERR_PACK(0,BIO_F_BUFFER_CTRL,0), "BUFFER_CTRL"}, |
90 | {ERR_PACK(0,BIO_F_CONN_CTRL,0), "CONN_CTRL"}, | ||
85 | {ERR_PACK(0,BIO_F_CONN_STATE,0), "CONN_STATE"}, | 91 | {ERR_PACK(0,BIO_F_CONN_STATE,0), "CONN_STATE"}, |
86 | {ERR_PACK(0,BIO_F_FILE_CTRL,0), "FILE_CTRL"}, | 92 | {ERR_PACK(0,BIO_F_FILE_CTRL,0), "FILE_CTRL"}, |
87 | {ERR_PACK(0,BIO_F_MEM_WRITE,0), "MEM_WRITE"}, | 93 | {ERR_PACK(0,BIO_F_MEM_WRITE,0), "MEM_WRITE"}, |
@@ -117,6 +123,7 @@ static ERR_STRING_DATA BIO_str_reasons[]= | |||
117 | {BIO_R_UNABLE_TO_LISTEN_SOCKET ,"unable to listen socket"}, | 123 | {BIO_R_UNABLE_TO_LISTEN_SOCKET ,"unable to listen socket"}, |
118 | {BIO_R_UNINITIALIZED ,"uninitialized"}, | 124 | {BIO_R_UNINITIALIZED ,"uninitialized"}, |
119 | {BIO_R_UNSUPPORTED_METHOD ,"unsupported method"}, | 125 | {BIO_R_UNSUPPORTED_METHOD ,"unsupported method"}, |
126 | {BIO_R_WRITE_TO_READ_ONLY_BIO ,"write to read only bio"}, | ||
120 | {BIO_R_WSASTARTUP ,"wsastartup"}, | 127 | {BIO_R_WSASTARTUP ,"wsastartup"}, |
121 | {0,NULL} | 128 | {0,NULL} |
122 | }; | 129 | }; |
diff --git a/src/lib/libcrypto/bio/bio_lib.c b/src/lib/libcrypto/bio/bio_lib.c index b72688ea90..cf8e6150fd 100644 --- a/src/lib/libcrypto/bio/bio_lib.c +++ b/src/lib/libcrypto/bio/bio_lib.c | |||
@@ -63,7 +63,7 @@ | |||
63 | #include <openssl/bio.h> | 63 | #include <openssl/bio.h> |
64 | #include <openssl/stack.h> | 64 | #include <openssl/stack.h> |
65 | 65 | ||
66 | static STACK *bio_meth=NULL; | 66 | static STACK_OF(CRYPTO_EX_DATA_FUNCS) *bio_meth=NULL; |
67 | static int bio_meth_num=0; | 67 | static int bio_meth_num=0; |
68 | 68 | ||
69 | BIO *BIO_new(BIO_METHOD *method) | 69 | BIO *BIO_new(BIO_METHOD *method) |
@@ -100,7 +100,7 @@ int BIO_set(BIO *bio, BIO_METHOD *method) | |||
100 | bio->references=1; | 100 | bio->references=1; |
101 | bio->num_read=0L; | 101 | bio->num_read=0L; |
102 | bio->num_write=0L; | 102 | bio->num_write=0L; |
103 | CRYPTO_new_ex_data(bio_meth,(char *)bio,&bio->ex_data); | 103 | CRYPTO_new_ex_data(bio_meth,bio,&bio->ex_data); |
104 | if (method->create != NULL) | 104 | if (method->create != NULL) |
105 | if (!method->create(bio)) | 105 | if (!method->create(bio)) |
106 | return(0); | 106 | return(0); |
@@ -129,7 +129,7 @@ int BIO_free(BIO *a) | |||
129 | ((i=(int)a->callback(a,BIO_CB_FREE,NULL,0,0L,1L)) <= 0)) | 129 | ((i=(int)a->callback(a,BIO_CB_FREE,NULL,0,0L,1L)) <= 0)) |
130 | return(i); | 130 | return(i); |
131 | 131 | ||
132 | CRYPTO_free_ex_data(bio_meth,(char *)a,&a->ex_data); | 132 | CRYPTO_free_ex_data(bio_meth,a,&a->ex_data); |
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); |
@@ -317,16 +317,43 @@ long BIO_ctrl(BIO *b, int cmd, long larg, void *parg) | |||
317 | return(ret); | 317 | return(ret); |
318 | } | 318 | } |
319 | 319 | ||
320 | long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)()) | ||
321 | { | ||
322 | long ret; | ||
323 | long (*cb)(); | ||
324 | |||
325 | if (b == NULL) return(0); | ||
326 | |||
327 | if ((b->method == NULL) || (b->method->callback_ctrl == NULL)) | ||
328 | { | ||
329 | BIOerr(BIO_F_BIO_CTRL,BIO_R_UNSUPPORTED_METHOD); | ||
330 | return(-2); | ||
331 | } | ||
332 | |||
333 | cb=b->callback; | ||
334 | |||
335 | if ((cb != NULL) && | ||
336 | ((ret=cb(b,BIO_CB_CTRL,(void *)&fp,cmd,0,1L)) <= 0)) | ||
337 | return(ret); | ||
338 | |||
339 | ret=b->method->callback_ctrl(b,cmd,fp); | ||
340 | |||
341 | if (cb != NULL) | ||
342 | ret=cb(b,BIO_CB_CTRL|BIO_CB_RETURN,(void *)&fp,cmd, | ||
343 | 0,ret); | ||
344 | return(ret); | ||
345 | } | ||
346 | |||
320 | /* It is unfortunate to duplicate in functions what the BIO_(w)pending macros | 347 | /* It is unfortunate to duplicate in functions what the BIO_(w)pending macros |
321 | * do; but those macros have inappropriate return type, and for interfacing | 348 | * do; but those macros have inappropriate return type, and for interfacing |
322 | * from other programming languages, C macros aren't much of a help anyway. */ | 349 | * from other programming languages, C macros aren't much of a help anyway. */ |
323 | size_t BIO_ctrl_pending(BIO *bio) | 350 | size_t BIO_ctrl_pending(BIO *bio) |
324 | { | 351 | { |
325 | return BIO_ctrl(bio, BIO_CTRL_PENDING, 0, NULL); | 352 | return BIO_ctrl(bio, BIO_CTRL_PENDING, 0, NULL); |
326 | } | 353 | } |
327 | 354 | ||
328 | size_t BIO_ctrl_wpending(BIO *bio) | 355 | size_t BIO_ctrl_wpending(BIO *bio) |
329 | { | 356 | { |
330 | return BIO_ctrl(bio, BIO_CTRL_WPENDING, 0, NULL); | 357 | return BIO_ctrl(bio, BIO_CTRL_WPENDING, 0, NULL); |
331 | } | 358 | } |
332 | 359 | ||
@@ -476,21 +503,32 @@ void BIO_copy_next_retry(BIO *b) | |||
476 | b->retry_reason=b->next_bio->retry_reason; | 503 | b->retry_reason=b->next_bio->retry_reason; |
477 | } | 504 | } |
478 | 505 | ||
479 | int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), | 506 | int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, |
480 | int (*dup_func)(), void (*free_func)()) | 507 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) |
481 | { | 508 | { |
482 | bio_meth_num++; | 509 | bio_meth_num++; |
483 | return(CRYPTO_get_ex_new_index(bio_meth_num-1,&bio_meth, | 510 | return(CRYPTO_get_ex_new_index(bio_meth_num-1,&bio_meth, |
484 | argl,argp,new_func,dup_func,free_func)); | 511 | argl,argp,new_func,dup_func,free_func)); |
485 | } | 512 | } |
486 | 513 | ||
487 | int BIO_set_ex_data(BIO *bio, int idx, char *data) | 514 | int BIO_set_ex_data(BIO *bio, int idx, void *data) |
488 | { | 515 | { |
489 | return(CRYPTO_set_ex_data(&(bio->ex_data),idx,data)); | 516 | return(CRYPTO_set_ex_data(&(bio->ex_data),idx,data)); |
490 | } | 517 | } |
491 | 518 | ||
492 | char *BIO_get_ex_data(BIO *bio, int idx) | 519 | void *BIO_get_ex_data(BIO *bio, int idx) |
493 | { | 520 | { |
494 | return(CRYPTO_get_ex_data(&(bio->ex_data),idx)); | 521 | return(CRYPTO_get_ex_data(&(bio->ex_data),idx)); |
495 | } | 522 | } |
496 | 523 | ||
524 | unsigned long BIO_number_read(BIO *bio) | ||
525 | { | ||
526 | if(bio) return bio->num_read; | ||
527 | return 0; | ||
528 | } | ||
529 | |||
530 | unsigned long BIO_number_written(BIO *bio) | ||
531 | { | ||
532 | if(bio) return bio->num_write; | ||
533 | return 0; | ||
534 | } | ||
diff --git a/src/lib/libcrypto/bio/bss_acpt.c b/src/lib/libcrypto/bio/bss_acpt.c index 47af80f76d..9afa636406 100644 --- a/src/lib/libcrypto/bio/bss_acpt.c +++ b/src/lib/libcrypto/bio/bss_acpt.c | |||
@@ -118,6 +118,7 @@ static BIO_METHOD methods_acceptp= | |||
118 | acpt_ctrl, | 118 | acpt_ctrl, |
119 | acpt_new, | 119 | acpt_new, |
120 | acpt_free, | 120 | acpt_free, |
121 | NULL, | ||
121 | }; | 122 | }; |
122 | 123 | ||
123 | BIO_METHOD *BIO_s_accept(void) | 124 | BIO_METHOD *BIO_s_accept(void) |
diff --git a/src/lib/libcrypto/bio/bss_bio.c b/src/lib/libcrypto/bio/bss_bio.c index 562e9d8de2..0d0f9356f7 100644 --- a/src/lib/libcrypto/bio/bss_bio.c +++ b/src/lib/libcrypto/bio/bss_bio.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #endif | 13 | #endif |
14 | 14 | ||
15 | #include <assert.h> | 15 | #include <assert.h> |
16 | #include <limits.h> | ||
16 | #include <stdlib.h> | 17 | #include <stdlib.h> |
17 | #include <string.h> | 18 | #include <string.h> |
18 | 19 | ||
@@ -40,7 +41,8 @@ static BIO_METHOD methods_biop = | |||
40 | NULL /* no bio_gets */, | 41 | NULL /* no bio_gets */, |
41 | bio_ctrl, | 42 | bio_ctrl, |
42 | bio_new, | 43 | bio_new, |
43 | bio_free | 44 | bio_free, |
45 | NULL /* no bio_callback_ctrl */ | ||
44 | }; | 46 | }; |
45 | 47 | ||
46 | BIO_METHOD *BIO_s_bio(void) | 48 | BIO_METHOD *BIO_s_bio(void) |
@@ -64,7 +66,7 @@ struct bio_bio_st | |||
64 | 66 | ||
65 | size_t request; /* valid iff peer != NULL; 0 if len != 0, | 67 | size_t request; /* valid iff peer != NULL; 0 if len != 0, |
66 | * otherwise set by peer to number of bytes | 68 | * otherwise set by peer to number of bytes |
67 | * it (unsuccesfully) tried to read, | 69 | * it (unsuccessfully) tried to read, |
68 | * never more than buffer space (size-len) warrants. */ | 70 | * never more than buffer space (size-len) warrants. */ |
69 | }; | 71 | }; |
70 | 72 | ||
@@ -195,6 +197,81 @@ static int bio_read(BIO *bio, char *buf, int size_) | |||
195 | return size; | 197 | return size; |
196 | } | 198 | } |
197 | 199 | ||
200 | /* non-copying interface: provide pointer to available data in buffer | ||
201 | * bio_nread0: return number of available bytes | ||
202 | * bio_nread: also advance index | ||
203 | * (example usage: bio_nread0(), read from buffer, bio_nread() | ||
204 | * or just bio_nread(), read from buffer) | ||
205 | */ | ||
206 | /* WARNING: The non-copying interface is largely untested as of yet | ||
207 | * and may contain bugs. */ | ||
208 | static size_t bio_nread0(BIO *bio, char **buf) | ||
209 | { | ||
210 | struct bio_bio_st *b, *peer_b; | ||
211 | size_t num; | ||
212 | |||
213 | BIO_clear_retry_flags(bio); | ||
214 | |||
215 | if (!bio->init) | ||
216 | return 0; | ||
217 | |||
218 | b = bio->ptr; | ||
219 | assert(b != NULL); | ||
220 | assert(b->peer != NULL); | ||
221 | peer_b = b->peer->ptr; | ||
222 | assert(peer_b != NULL); | ||
223 | assert(peer_b->buf != NULL); | ||
224 | |||
225 | peer_b->request = 0; | ||
226 | |||
227 | if (peer_b->len == 0) | ||
228 | { | ||
229 | char dummy; | ||
230 | |||
231 | /* avoid code duplication -- nothing available for reading */ | ||
232 | return bio_read(bio, &dummy, 1); /* returns 0 or -1 */ | ||
233 | } | ||
234 | |||
235 | num = peer_b->len; | ||
236 | if (peer_b->size < peer_b->offset + num) | ||
237 | /* no ring buffer wrap-around for non-copying interface */ | ||
238 | num = peer_b->size - peer_b->offset; | ||
239 | assert(num > 0); | ||
240 | |||
241 | if (buf != NULL) | ||
242 | *buf = peer_b->buf + peer_b->offset; | ||
243 | return num; | ||
244 | } | ||
245 | |||
246 | static size_t bio_nread(BIO *bio, char **buf, size_t num) | ||
247 | { | ||
248 | struct bio_bio_st *b, *peer_b; | ||
249 | size_t available; | ||
250 | |||
251 | available = bio_nread0(bio, buf); | ||
252 | if (num > available) | ||
253 | num = available; | ||
254 | if (num == 0) | ||
255 | return num; | ||
256 | |||
257 | b = bio->ptr; | ||
258 | peer_b = b->peer->ptr; | ||
259 | |||
260 | peer_b->len -= num; | ||
261 | if (peer_b->len) | ||
262 | { | ||
263 | peer_b->offset += num; | ||
264 | assert(peer_b->offset <= peer_b->size); | ||
265 | if (peer_b->offset == peer_b->size) | ||
266 | peer_b->offset = 0; | ||
267 | } | ||
268 | else | ||
269 | peer_b->offset = 0; | ||
270 | |||
271 | return num; | ||
272 | } | ||
273 | |||
274 | |||
198 | static int bio_write(BIO *bio, char *buf, int num_) | 275 | static int bio_write(BIO *bio, char *buf, int num_) |
199 | { | 276 | { |
200 | size_t num = num_; | 277 | size_t num = num_; |
@@ -268,6 +345,78 @@ static int bio_write(BIO *bio, char *buf, int num_) | |||
268 | return num; | 345 | return num; |
269 | } | 346 | } |
270 | 347 | ||
348 | /* non-copying interface: provide pointer to region to write to | ||
349 | * bio_nwrite0: check how much space is available | ||
350 | * bio_nwrite: also increase length | ||
351 | * (example usage: bio_nwrite0(), write to buffer, bio_nwrite() | ||
352 | * or just bio_nwrite(), write to buffer) | ||
353 | */ | ||
354 | static size_t bio_nwrite0(BIO *bio, char **buf) | ||
355 | { | ||
356 | struct bio_bio_st *b; | ||
357 | size_t num; | ||
358 | size_t write_offset; | ||
359 | |||
360 | BIO_clear_retry_flags(bio); | ||
361 | |||
362 | if (!bio->init) | ||
363 | return 0; | ||
364 | |||
365 | b = bio->ptr; | ||
366 | assert(b != NULL); | ||
367 | assert(b->peer != NULL); | ||
368 | assert(b->buf != NULL); | ||
369 | |||
370 | b->request = 0; | ||
371 | if (b->closed) | ||
372 | { | ||
373 | BIOerr(BIO_F_BIO_NWRITE0, BIO_R_BROKEN_PIPE); | ||
374 | return -1; | ||
375 | } | ||
376 | |||
377 | assert(b->len <= b->size); | ||
378 | |||
379 | if (b->len == b->size) | ||
380 | { | ||
381 | BIO_set_retry_write(bio); | ||
382 | return -1; | ||
383 | } | ||
384 | |||
385 | num = b->size - b->len; | ||
386 | write_offset = b->offset + b->len; | ||
387 | if (write_offset >= b->size) | ||
388 | write_offset -= b->size; | ||
389 | if (write_offset + num > b->size) | ||
390 | /* no ring buffer wrap-around for non-copying interface | ||
391 | * (to fulfil the promise by BIO_ctrl_get_write_guarantee, | ||
392 | * BIO_nwrite may have to be called twice) */ | ||
393 | num = b->size - write_offset; | ||
394 | |||
395 | if (buf != NULL) | ||
396 | *buf = b->buf + write_offset; | ||
397 | assert(write_offset + num <= b->size); | ||
398 | |||
399 | return num; | ||
400 | } | ||
401 | |||
402 | static size_t bio_nwrite(BIO *bio, char **buf, size_t num) | ||
403 | { | ||
404 | struct bio_bio_st *b; | ||
405 | size_t space; | ||
406 | |||
407 | space = bio_nwrite0(bio, buf); | ||
408 | if (num > space) | ||
409 | num = space; | ||
410 | if (num == 0) | ||
411 | return num; | ||
412 | b = bio->ptr; | ||
413 | assert(b != NULL); | ||
414 | b->len += num; | ||
415 | assert(b->len <= b->size); | ||
416 | |||
417 | return num; | ||
418 | } | ||
419 | |||
271 | 420 | ||
272 | static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) | 421 | static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) |
273 | { | 422 | { |
@@ -331,7 +480,7 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) | |||
331 | 480 | ||
332 | case BIO_C_GET_WRITE_GUARANTEE: | 481 | case BIO_C_GET_WRITE_GUARANTEE: |
333 | /* How many bytes can the caller feed to the next write | 482 | /* How many bytes can the caller feed to the next write |
334 | * withouth having to keep any? */ | 483 | * without having to keep any? */ |
335 | if (b->peer == NULL || b->closed) | 484 | if (b->peer == NULL || b->closed) |
336 | ret = 0; | 485 | ret = 0; |
337 | else | 486 | else |
@@ -339,18 +488,42 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) | |||
339 | break; | 488 | break; |
340 | 489 | ||
341 | case BIO_C_GET_READ_REQUEST: | 490 | case BIO_C_GET_READ_REQUEST: |
342 | /* If the peer unsuccesfully tried to read, how many bytes | 491 | /* If the peer unsuccessfully tried to read, how many bytes |
343 | * were requested? (As with BIO_CTRL_PENDING, that number | 492 | * were requested? (As with BIO_CTRL_PENDING, that number |
344 | * can usually be treated as boolean.) */ | 493 | * can usually be treated as boolean.) */ |
345 | ret = (long) b->request; | 494 | ret = (long) b->request; |
346 | break; | 495 | break; |
347 | 496 | ||
497 | case BIO_C_RESET_READ_REQUEST: | ||
498 | /* Reset request. (Can be useful after read attempts | ||
499 | * at the other side that are meant to be non-blocking, | ||
500 | * e.g. when probing SSL_read to see if any data is | ||
501 | * available.) */ | ||
502 | b->request = 0; | ||
503 | ret = 1; | ||
504 | break; | ||
505 | |||
348 | case BIO_C_SHUTDOWN_WR: | 506 | case BIO_C_SHUTDOWN_WR: |
349 | /* similar to shutdown(..., SHUT_WR) */ | 507 | /* similar to shutdown(..., SHUT_WR) */ |
350 | b->closed = 1; | 508 | b->closed = 1; |
351 | ret = 1; | 509 | ret = 1; |
352 | break; | 510 | break; |
353 | 511 | ||
512 | case BIO_C_NREAD: | ||
513 | /* non-copying read */ | ||
514 | ret = (long) bio_nread(bio, ptr, (size_t) num); | ||
515 | break; | ||
516 | |||
517 | case BIO_C_NWRITE0: | ||
518 | /* prepare for non-copying write */ | ||
519 | ret = (long) bio_nwrite0(bio, ptr); | ||
520 | break; | ||
521 | |||
522 | case BIO_C_NWRITE: | ||
523 | /* non-copying write */ | ||
524 | ret = (long) bio_nwrite(bio, ptr, (size_t) num); | ||
525 | break; | ||
526 | |||
354 | 527 | ||
355 | /* standard CTRL codes follow */ | 528 | /* standard CTRL codes follow */ |
356 | 529 | ||
@@ -586,3 +759,78 @@ size_t BIO_ctrl_get_read_request(BIO *bio) | |||
586 | { | 759 | { |
587 | return BIO_ctrl(bio, BIO_C_GET_READ_REQUEST, 0, NULL); | 760 | return BIO_ctrl(bio, BIO_C_GET_READ_REQUEST, 0, NULL); |
588 | } | 761 | } |
762 | |||
763 | int BIO_ctrl_reset_read_request(BIO *bio) | ||
764 | { | ||
765 | return (BIO_ctrl(bio, BIO_C_RESET_READ_REQUEST, 0, NULL) != 0); | ||
766 | } | ||
767 | |||
768 | |||
769 | /* BIO_nread0/nread/nwrite0/nwrite are available only for BIO pairs for now | ||
770 | * (conceivably some other BIOs could allow non-copying reads and writes too.) | ||
771 | */ | ||
772 | int BIO_nread0(BIO *bio, char **buf) | ||
773 | { | ||
774 | long ret; | ||
775 | |||
776 | if (!bio->init) | ||
777 | { | ||
778 | BIOerr(BIO_F_BIO_NREAD0, BIO_R_UNINITIALIZED); | ||
779 | return -2; | ||
780 | } | ||
781 | |||
782 | ret = BIO_ctrl(bio, BIO_C_NREAD0, 0, buf); | ||
783 | if (ret > INT_MAX) | ||
784 | return INT_MAX; | ||
785 | else | ||
786 | return (int) ret; | ||
787 | } | ||
788 | |||
789 | int BIO_nread(BIO *bio, char **buf, int num) | ||
790 | { | ||
791 | int ret; | ||
792 | |||
793 | if (!bio->init) | ||
794 | { | ||
795 | BIOerr(BIO_F_BIO_NREAD, BIO_R_UNINITIALIZED); | ||
796 | return -2; | ||
797 | } | ||
798 | |||
799 | ret = (int) BIO_ctrl(bio, BIO_C_NREAD, num, buf); | ||
800 | if (ret > 0) | ||
801 | bio->num_read += ret; | ||
802 | return ret; | ||
803 | } | ||
804 | |||
805 | int BIO_nwrite0(BIO *bio, char **buf) | ||
806 | { | ||
807 | long ret; | ||
808 | |||
809 | if (!bio->init) | ||
810 | { | ||
811 | BIOerr(BIO_F_BIO_NWRITE0, BIO_R_UNINITIALIZED); | ||
812 | return -2; | ||
813 | } | ||
814 | |||
815 | ret = BIO_ctrl(bio, BIO_C_NWRITE0, 0, buf); | ||
816 | if (ret > INT_MAX) | ||
817 | return INT_MAX; | ||
818 | else | ||
819 | return (int) ret; | ||
820 | } | ||
821 | |||
822 | int BIO_nwrite(BIO *bio, char **buf, int num) | ||
823 | { | ||
824 | int ret; | ||
825 | |||
826 | if (!bio->init) | ||
827 | { | ||
828 | BIOerr(BIO_F_BIO_NWRITE, BIO_R_UNINITIALIZED); | ||
829 | return -2; | ||
830 | } | ||
831 | |||
832 | ret = BIO_ctrl(bio, BIO_C_NWRITE, num, buf); | ||
833 | if (ret > 0) | ||
834 | bio->num_read += ret; | ||
835 | return ret; | ||
836 | } | ||
diff --git a/src/lib/libcrypto/bio/bss_conn.c b/src/lib/libcrypto/bio/bss_conn.c index 68c46e3d69..22d00b369e 100644 --- a/src/lib/libcrypto/bio/bss_conn.c +++ b/src/lib/libcrypto/bio/bss_conn.c | |||
@@ -90,11 +90,11 @@ typedef struct bio_connect_st | |||
90 | struct sockaddr_in them; | 90 | struct sockaddr_in them; |
91 | 91 | ||
92 | /* int socket; this will be kept in bio->num so that it is | 92 | /* int socket; this will be kept in bio->num so that it is |
93 | * compatable with the bss_sock bio */ | 93 | * compatible with the bss_sock bio */ |
94 | 94 | ||
95 | /* called when the connection is initially made | 95 | /* called when the connection is initially made |
96 | * callback(BIO,state,ret); The callback should return | 96 | * callback(BIO,state,ret); The callback should return |
97 | * 'ret'. state is for compatablity with the ssl info_callback */ | 97 | * 'ret'. state is for compatibility with the ssl info_callback */ |
98 | int (*info_callback)(); | 98 | int (*info_callback)(); |
99 | } BIO_CONNECT; | 99 | } BIO_CONNECT; |
100 | 100 | ||
@@ -104,6 +104,7 @@ static int conn_puts(BIO *h,char *str); | |||
104 | static long conn_ctrl(BIO *h,int cmd,long arg1,char *arg2); | 104 | static long conn_ctrl(BIO *h,int cmd,long arg1,char *arg2); |
105 | static int conn_new(BIO *h); | 105 | static int conn_new(BIO *h); |
106 | static int conn_free(BIO *data); | 106 | static int conn_free(BIO *data); |
107 | static long conn_callback_ctrl(BIO *h,int cmd,void *(*fp)()); | ||
107 | 108 | ||
108 | static int conn_state(BIO *b, BIO_CONNECT *c); | 109 | static int conn_state(BIO *b, BIO_CONNECT *c); |
109 | static void conn_close_socket(BIO *data); | 110 | static void conn_close_socket(BIO *data); |
@@ -121,6 +122,7 @@ static BIO_METHOD methods_connectp= | |||
121 | conn_ctrl, | 122 | conn_ctrl, |
122 | conn_new, | 123 | conn_new, |
123 | conn_free, | 124 | conn_free, |
125 | conn_callback_ctrl, | ||
124 | }; | 126 | }; |
125 | 127 | ||
126 | static int conn_state(BIO *b, BIO_CONNECT *c) | 128 | static int conn_state(BIO *b, BIO_CONNECT *c) |
@@ -494,7 +496,7 @@ static long conn_ctrl(BIO *b, int cmd, long num, char *ptr) | |||
494 | *((int *)ptr)=data->port; | 496 | *((int *)ptr)=data->port; |
495 | } | 497 | } |
496 | if ((!b->init) || (ptr == NULL)) | 498 | if ((!b->init) || (ptr == NULL)) |
497 | *pptr="not initalised"; | 499 | *pptr="not initialized"; |
498 | ret=1; | 500 | ret=1; |
499 | } | 501 | } |
500 | break; | 502 | break; |
@@ -564,16 +566,25 @@ static long conn_ctrl(BIO *b, int cmd, long num, char *ptr) | |||
564 | case BIO_CTRL_FLUSH: | 566 | case BIO_CTRL_FLUSH: |
565 | break; | 567 | break; |
566 | case BIO_CTRL_DUP: | 568 | case BIO_CTRL_DUP: |
569 | { | ||
567 | dbio=(BIO *)ptr; | 570 | dbio=(BIO *)ptr; |
568 | if (data->param_port) | 571 | if (data->param_port) |
569 | BIO_set_conn_port(dbio,data->param_port); | 572 | BIO_set_conn_port(dbio,data->param_port); |
570 | if (data->param_hostname) | 573 | if (data->param_hostname) |
571 | BIO_set_conn_hostname(dbio,data->param_hostname); | 574 | BIO_set_conn_hostname(dbio,data->param_hostname); |
572 | BIO_set_nbio(dbio,data->nbio); | 575 | BIO_set_nbio(dbio,data->nbio); |
573 | (void)BIO_set_info_callback(dbio,data->info_callback); | 576 | (void)BIO_set_info_callback(dbio,(void *(*)())(data->info_callback)); |
577 | } | ||
574 | break; | 578 | break; |
575 | case BIO_CTRL_SET_CALLBACK: | 579 | case BIO_CTRL_SET_CALLBACK: |
576 | data->info_callback=(int (*)())ptr; | 580 | { |
581 | #if 0 /* FIXME: Should this be used? -- Richard Levitte */ | ||
582 | BIOerr(BIO_F_CONN_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
583 | ret = -1; | ||
584 | #else | ||
585 | ret=0; | ||
586 | #endif | ||
587 | } | ||
577 | break; | 588 | break; |
578 | case BIO_CTRL_GET_CALLBACK: | 589 | case BIO_CTRL_GET_CALLBACK: |
579 | { | 590 | { |
@@ -590,6 +601,27 @@ static long conn_ctrl(BIO *b, int cmd, long num, char *ptr) | |||
590 | return(ret); | 601 | return(ret); |
591 | } | 602 | } |
592 | 603 | ||
604 | static long conn_callback_ctrl(BIO *b, int cmd, void *(*fp)()) | ||
605 | { | ||
606 | long ret=1; | ||
607 | BIO_CONNECT *data; | ||
608 | |||
609 | data=(BIO_CONNECT *)b->ptr; | ||
610 | |||
611 | switch (cmd) | ||
612 | { | ||
613 | case BIO_CTRL_SET_CALLBACK: | ||
614 | { | ||
615 | data->info_callback=(int (*)())fp; | ||
616 | } | ||
617 | break; | ||
618 | default: | ||
619 | ret=0; | ||
620 | break; | ||
621 | } | ||
622 | return(ret); | ||
623 | } | ||
624 | |||
593 | static int conn_puts(BIO *bp, char *str) | 625 | static int conn_puts(BIO *bp, char *str) |
594 | { | 626 | { |
595 | int n,ret; | 627 | int n,ret; |
diff --git a/src/lib/libcrypto/bio/bss_file.c b/src/lib/libcrypto/bio/bss_file.c index 52c0c39df0..0d44dc3889 100644 --- a/src/lib/libcrypto/bio/bss_file.c +++ b/src/lib/libcrypto/bio/bss_file.c | |||
@@ -91,6 +91,7 @@ static BIO_METHOD methods_filep= | |||
91 | file_ctrl, | 91 | file_ctrl, |
92 | file_new, | 92 | file_new, |
93 | file_free, | 93 | file_free, |
94 | NULL, | ||
94 | }; | 95 | }; |
95 | 96 | ||
96 | BIO *BIO_new_file(const char *filename, const char *mode) | 97 | BIO *BIO_new_file(const char *filename, const char *mode) |
@@ -171,7 +172,7 @@ static int MS_CALLBACK file_write(BIO *b, char *in, int inl) | |||
171 | if (fwrite(in,(int)inl,1,(FILE *)b->ptr)) | 172 | if (fwrite(in,(int)inl,1,(FILE *)b->ptr)) |
172 | ret=inl; | 173 | ret=inl; |
173 | /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */ | 174 | /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */ |
174 | /* acording to Tim Hudson <tjh@cryptsoft.com>, the commented | 175 | /* according to Tim Hudson <tjh@cryptsoft.com>, the commented |
175 | * out version above can cause 'inl' write calls under | 176 | * out version above can cause 'inl' write calls under |
176 | * some stupid stdio implementations (VMS) */ | 177 | * some stupid stdio implementations (VMS) */ |
177 | } | 178 | } |
diff --git a/src/lib/libcrypto/bio/bss_log.c b/src/lib/libcrypto/bio/bss_log.c index db82e757e7..4308b19663 100644 --- a/src/lib/libcrypto/bio/bss_log.c +++ b/src/lib/libcrypto/bio/bss_log.c | |||
@@ -72,6 +72,8 @@ | |||
72 | #else | 72 | #else |
73 | #include <syslog.h> | 73 | #include <syslog.h> |
74 | #endif | 74 | #endif |
75 | #else | ||
76 | #include <process.h> | ||
75 | #endif | 77 | #endif |
76 | 78 | ||
77 | #include "cryptlib.h" | 79 | #include "cryptlib.h" |
@@ -98,6 +100,7 @@ static BIO_METHOD methods_slg= | |||
98 | slg_ctrl, | 100 | slg_ctrl, |
99 | slg_new, | 101 | slg_new, |
100 | slg_free, | 102 | slg_free, |
103 | NULL, | ||
101 | }; | 104 | }; |
102 | 105 | ||
103 | BIO_METHOD *BIO_s_log(void) | 106 | BIO_METHOD *BIO_s_log(void) |
@@ -131,8 +134,10 @@ static int MS_CALLBACK slg_write(BIO *b, char *in, int inl) | |||
131 | char* buf= in; | 134 | char* buf= in; |
132 | char* pp; | 135 | char* pp; |
133 | #if defined(WIN32) | 136 | #if defined(WIN32) |
134 | LPTSTR lpszStrings[1]; | 137 | LPCSTR lpszStrings[2]; |
135 | WORD evtype= EVENTLOG_ERROR_TYPE; | 138 | WORD evtype= EVENTLOG_ERROR_TYPE; |
139 | int pid = _getpid(); | ||
140 | char pidbuf[20]; | ||
136 | #else | 141 | #else |
137 | int priority; | 142 | int priority; |
138 | #endif | 143 | #endif |
@@ -156,10 +161,13 @@ static int MS_CALLBACK slg_write(BIO *b, char *in, int inl) | |||
156 | evtype= EVENTLOG_ERROR_TYPE; | 161 | evtype= EVENTLOG_ERROR_TYPE; |
157 | pp= buf; | 162 | pp= buf; |
158 | } | 163 | } |
159 | lpszStrings[0]= pp; | 164 | |
165 | sprintf(pidbuf, "[%d] ", pid); | ||
166 | lpszStrings[0] = pidbuf; | ||
167 | lpszStrings[1] = pp; | ||
160 | 168 | ||
161 | if(b->ptr) | 169 | if(b->ptr) |
162 | ReportEvent(b->ptr, evtype, 0, 1024, NULL, 1, 0, | 170 | ReportEvent(b->ptr, evtype, 0, 1024, NULL, 2, 0, |
163 | lpszStrings, NULL); | 171 | lpszStrings, NULL); |
164 | #else | 172 | #else |
165 | if(strncmp(buf, "ERR ", 4) == 0){ | 173 | if(strncmp(buf, "ERR ", 4) == 0){ |
diff --git a/src/lib/libcrypto/bio/bss_mem.c b/src/lib/libcrypto/bio/bss_mem.c index 7e749a503e..41eab92415 100644 --- a/src/lib/libcrypto/bio/bss_mem.c +++ b/src/lib/libcrypto/bio/bss_mem.c | |||
@@ -79,6 +79,7 @@ static BIO_METHOD mem_method= | |||
79 | mem_ctrl, | 79 | mem_ctrl, |
80 | mem_new, | 80 | mem_new, |
81 | mem_free, | 81 | mem_free, |
82 | NULL, | ||
82 | }; | 83 | }; |
83 | 84 | ||
84 | /* bio->num is used to hold the value to return on 'empty', if it is | 85 | /* bio->num is used to hold the value to return on 'empty', if it is |
@@ -89,6 +90,26 @@ BIO_METHOD *BIO_s_mem(void) | |||
89 | return(&mem_method); | 90 | return(&mem_method); |
90 | } | 91 | } |
91 | 92 | ||
93 | BIO *BIO_new_mem_buf(void *buf, int len) | ||
94 | { | ||
95 | BIO *ret; | ||
96 | BUF_MEM *b; | ||
97 | if (!buf) { | ||
98 | BIOerr(BIO_F_BIO_NEW_MEM_BUF,BIO_R_NULL_PARAMETER); | ||
99 | return NULL; | ||
100 | } | ||
101 | if(len == -1) len = strlen(buf); | ||
102 | if(!(ret = BIO_new(BIO_s_mem())) ) return NULL; | ||
103 | b = (BUF_MEM *)ret->ptr; | ||
104 | b->data = buf; | ||
105 | b->length = len; | ||
106 | b->max = len; | ||
107 | ret->flags |= BIO_FLAGS_MEM_RDONLY; | ||
108 | /* Since this is static data retrying wont help */ | ||
109 | ret->num = 0; | ||
110 | return ret; | ||
111 | } | ||
112 | |||
92 | static int mem_new(BIO *bi) | 113 | static int mem_new(BIO *bi) |
93 | { | 114 | { |
94 | BUF_MEM *b; | 115 | BUF_MEM *b; |
@@ -109,7 +130,10 @@ static int mem_free(BIO *a) | |||
109 | { | 130 | { |
110 | if ((a->init) && (a->ptr != NULL)) | 131 | if ((a->init) && (a->ptr != NULL)) |
111 | { | 132 | { |
112 | BUF_MEM_free((BUF_MEM *)a->ptr); | 133 | BUF_MEM *b; |
134 | b = (BUF_MEM *)a->ptr; | ||
135 | if(a->flags & BIO_FLAGS_MEM_RDONLY) b->data = NULL; | ||
136 | BUF_MEM_free(b); | ||
113 | a->ptr=NULL; | 137 | a->ptr=NULL; |
114 | } | 138 | } |
115 | } | 139 | } |
@@ -126,17 +150,18 @@ static int mem_read(BIO *b, char *out, int outl) | |||
126 | bm=(BUF_MEM *)b->ptr; | 150 | bm=(BUF_MEM *)b->ptr; |
127 | BIO_clear_retry_flags(b); | 151 | BIO_clear_retry_flags(b); |
128 | ret=(outl > bm->length)?bm->length:outl; | 152 | ret=(outl > bm->length)?bm->length:outl; |
129 | if ((out != NULL) && (ret > 0)) | 153 | if ((out != NULL) && (ret > 0)) { |
130 | { | ||
131 | memcpy(out,bm->data,ret); | 154 | memcpy(out,bm->data,ret); |
132 | bm->length-=ret; | 155 | bm->length-=ret; |
133 | /* memmove(&(bm->data[0]),&(bm->data[ret]), bm->length); */ | 156 | /* memmove(&(bm->data[0]),&(bm->data[ret]), bm->length); */ |
134 | from=(char *)&(bm->data[ret]); | 157 | if(b->flags & BIO_FLAGS_MEM_RDONLY) bm->data += ret; |
135 | to=(char *)&(bm->data[0]); | 158 | else { |
136 | for (i=0; i<bm->length; i++) | 159 | from=(char *)&(bm->data[ret]); |
137 | to[i]=from[i]; | 160 | to=(char *)&(bm->data[0]); |
161 | for (i=0; i<bm->length; i++) | ||
162 | to[i]=from[i]; | ||
138 | } | 163 | } |
139 | else if (bm->length == 0) | 164 | } else if (bm->length == 0) |
140 | { | 165 | { |
141 | if (b->num != 0) | 166 | if (b->num != 0) |
142 | BIO_set_retry_read(b); | 167 | BIO_set_retry_read(b); |
@@ -158,6 +183,11 @@ static int mem_write(BIO *b, char *in, int inl) | |||
158 | goto end; | 183 | goto end; |
159 | } | 184 | } |
160 | 185 | ||
186 | if(b->flags & BIO_FLAGS_MEM_RDONLY) { | ||
187 | BIOerr(BIO_F_MEM_WRITE,BIO_R_WRITE_TO_READ_ONLY_BIO); | ||
188 | goto end; | ||
189 | } | ||
190 | |||
161 | BIO_clear_retry_flags(b); | 191 | BIO_clear_retry_flags(b); |
162 | blen=bm->length; | 192 | blen=bm->length; |
163 | if (BUF_MEM_grow(bm,blen+inl) != (blen+inl)) | 193 | if (BUF_MEM_grow(bm,blen+inl) != (blen+inl)) |
@@ -178,9 +208,15 @@ static long mem_ctrl(BIO *b, int cmd, long num, char *ptr) | |||
178 | switch (cmd) | 208 | switch (cmd) |
179 | { | 209 | { |
180 | case BIO_CTRL_RESET: | 210 | case BIO_CTRL_RESET: |
181 | if (bm->data != NULL) | 211 | if (bm->data != NULL) { |
182 | memset(bm->data,0,bm->max); | 212 | /* For read only case reset to the start again */ |
183 | bm->length=0; | 213 | if(b->flags & BIO_FLAGS_MEM_RDONLY) |
214 | bm->data -= bm->max - bm->length; | ||
215 | else { | ||
216 | memset(bm->data,0,bm->max); | ||
217 | bm->length=0; | ||
218 | } | ||
219 | } | ||
184 | break; | 220 | break; |
185 | case BIO_CTRL_EOF: | 221 | case BIO_CTRL_EOF: |
186 | ret=(long)(bm->length == 0); | 222 | ret=(long)(bm->length == 0); |
diff --git a/src/lib/libcrypto/bio/bss_null.c b/src/lib/libcrypto/bio/bss_null.c index d04be888e5..aee18e3ada 100644 --- a/src/lib/libcrypto/bio/bss_null.c +++ b/src/lib/libcrypto/bio/bss_null.c | |||
@@ -79,6 +79,7 @@ static BIO_METHOD null_method= | |||
79 | null_ctrl, | 79 | null_ctrl, |
80 | null_new, | 80 | null_new, |
81 | null_free, | 81 | null_free, |
82 | NULL, | ||
82 | }; | 83 | }; |
83 | 84 | ||
84 | BIO_METHOD *BIO_s_null(void) | 85 | BIO_METHOD *BIO_s_null(void) |
diff --git a/src/lib/libcrypto/bio/bss_rtcp.c b/src/lib/libcrypto/bio/bss_rtcp.c index 2ef040057e..4ad0739464 100644 --- a/src/lib/libcrypto/bio/bss_rtcp.c +++ b/src/lib/libcrypto/bio/bss_rtcp.c | |||
@@ -107,6 +107,7 @@ static BIO_METHOD rtcp_method= | |||
107 | rtcp_ctrl, | 107 | rtcp_ctrl, |
108 | rtcp_new, | 108 | rtcp_new, |
109 | rtcp_free, | 109 | rtcp_free, |
110 | NULL, | ||
110 | }; | 111 | }; |
111 | 112 | ||
112 | BIO_METHOD *BIO_s_rtcp(void) | 113 | BIO_METHOD *BIO_s_rtcp(void) |
diff --git a/src/lib/libcrypto/bio/bss_sock.c b/src/lib/libcrypto/bio/bss_sock.c index d336b99fe8..8ce80ef68d 100644 --- a/src/lib/libcrypto/bio/bss_sock.c +++ b/src/lib/libcrypto/bio/bss_sock.c | |||
@@ -95,6 +95,7 @@ static BIO_METHOD methods_sockp= | |||
95 | sock_ctrl, | 95 | sock_ctrl, |
96 | sock_new, | 96 | sock_new, |
97 | sock_free, | 97 | sock_free, |
98 | NULL, | ||
98 | }; | 99 | }; |
99 | 100 | ||
100 | BIO_METHOD *BIO_s_socket(void) | 101 | BIO_METHOD *BIO_s_socket(void) |
@@ -112,6 +113,7 @@ static BIO_METHOD methods_fdp= | |||
112 | fd_ctrl, | 113 | fd_ctrl, |
113 | fd_new, | 114 | fd_new, |
114 | fd_free, | 115 | fd_free, |
116 | NULL, | ||
115 | }; | 117 | }; |
116 | 118 | ||
117 | BIO_METHOD *BIO_s_fd(void) | 119 | BIO_METHOD *BIO_s_fd(void) |
@@ -163,8 +165,7 @@ static int fd_free(BIO *a) | |||
163 | if (a->init) | 165 | if (a->init) |
164 | { | 166 | { |
165 | #ifndef BIO_FD | 167 | #ifndef BIO_FD |
166 | shutdown(a->num,2); | 168 | SHUTDOWN2(a->num); |
167 | closesocket(a->num); | ||
168 | #else /* BIO_FD */ | 169 | #else /* BIO_FD */ |
169 | close(a->num); | 170 | close(a->num); |
170 | #endif | 171 | #endif |