summaryrefslogtreecommitdiff
path: root/lib/libcrypto/bio
diff options
context:
space:
mode:
authorBob Beck <beck@cvs.openbsd.org>2000-12-15 02:58:48 +0000
committerBob Beck <beck@cvs.openbsd.org>2000-12-15 02:58:48 +0000
commit01c37e03996dffeff1618614755c6cc676899acb (patch)
tree988002fb9b1d859c10890511aa5273cfb00662dc /lib/libcrypto/bio
parent9865f3ff77de9cfef0c5c8b0470daf6faa2f14af (diff)
openssl-engine-0.9.6 merge
Diffstat (limited to 'lib/libcrypto/bio')
-rw-r--r--lib/libcrypto/bio/Makefile.ssl127
-rw-r--r--lib/libcrypto/bio/b_dump.c122
-rw-r--r--lib/libcrypto/bio/b_print.c346
-rw-r--r--lib/libcrypto/bio/b_sock.c37
-rw-r--r--lib/libcrypto/bio/bf_buff.c52
-rw-r--r--lib/libcrypto/bio/bf_nbio.c20
-rw-r--r--lib/libcrypto/bio/bf_null.c20
-rw-r--r--lib/libcrypto/bio/bio.h66
-rw-r--r--lib/libcrypto/bio/bio_err.c7
-rw-r--r--lib/libcrypto/bio/bio_lib.c30
-rw-r--r--lib/libcrypto/bio/bss_acpt.c24
-rw-r--r--lib/libcrypto/bio/bss_bio.c20
-rw-r--r--lib/libcrypto/bio/bss_conn.c47
-rw-r--r--lib/libcrypto/bio/bss_file.c16
-rw-r--r--lib/libcrypto/bio/bss_log.c130
-rw-r--r--lib/libcrypto/bio/bss_mem.c33
-rw-r--r--lib/libcrypto/bio/bss_null.c16
-rw-r--r--lib/libcrypto/bio/bss_rtcp.c16
-rw-r--r--lib/libcrypto/bio/bss_sock.c28
19 files changed, 637 insertions, 520 deletions
diff --git a/lib/libcrypto/bio/Makefile.ssl b/lib/libcrypto/bio/Makefile.ssl
index 755f255fe4b..916d651d470 100644
--- a/lib/libcrypto/bio/Makefile.ssl
+++ b/lib/libcrypto/bio/Makefile.ssl
@@ -27,11 +27,13 @@ LIBSRC= bio_lib.c bio_cb.c bio_err.c \
bss_file.c bss_sock.c bss_conn.c \
bf_null.c bf_buff.c b_print.c b_dump.c \
b_sock.c bss_acpt.c bf_nbio.c bss_log.c bss_bio.c
+# bf_lbuf.c
LIBOBJ= bio_lib.o bio_cb.o bio_err.o \
bss_mem.o bss_null.o bss_fd.o \
bss_file.o bss_sock.o bss_conn.o \
bf_null.o bf_buff.o b_print.o b_dump.o \
b_sock.o bss_acpt.o bf_nbio.o bss_log.o bss_bio.o
+# bf_lbuf.o
SRC= $(LIBSRC)
@@ -89,20 +91,23 @@ clean:
b_dump.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
b_dump.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
b_dump.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-b_dump.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-b_dump.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+b_dump.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
+b_dump.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
+b_dump.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
b_dump.o: ../cryptlib.h
b_print.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
b_print.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
b_print.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-b_print.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-b_print.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+b_print.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
+b_print.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
+b_print.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
b_print.o: ../cryptlib.h
b_sock.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
b_sock.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
b_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-b_sock.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-b_sock.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+b_sock.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
+b_sock.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
+b_sock.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
b_sock.o: ../cryptlib.h
bf_buff.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
bf_buff.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
@@ -111,14 +116,16 @@ bf_buff.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
bf_buff.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
bf_buff.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
bf_buff.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-bf_buff.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
+bf_buff.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
+bf_buff.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
bf_buff.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
-bf_buff.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-bf_buff.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
-bf_buff.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
-bf_buff.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
-bf_buff.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-bf_buff.o: ../../include/openssl/stack.h ../cryptlib.h
+bf_buff.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+bf_buff.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+bf_buff.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
+bf_buff.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
+bf_buff.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+bf_buff.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+bf_buff.o: ../../include/openssl/symhacks.h ../cryptlib.h
bf_nbio.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
bf_nbio.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
bf_nbio.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
@@ -126,14 +133,16 @@ bf_nbio.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
bf_nbio.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
bf_nbio.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
bf_nbio.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-bf_nbio.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
+bf_nbio.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
+bf_nbio.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
bf_nbio.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
-bf_nbio.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-bf_nbio.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
-bf_nbio.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
-bf_nbio.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
-bf_nbio.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
-bf_nbio.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+bf_nbio.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+bf_nbio.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+bf_nbio.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
+bf_nbio.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
+bf_nbio.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
+bf_nbio.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+bf_nbio.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
bf_nbio.o: ../cryptlib.h
bf_null.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
bf_null.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
@@ -142,79 +151,93 @@ bf_null.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
bf_null.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
bf_null.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
bf_null.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-bf_null.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
+bf_null.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
+bf_null.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
bf_null.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
-bf_null.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-bf_null.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
-bf_null.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
-bf_null.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
-bf_null.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-bf_null.o: ../../include/openssl/stack.h ../cryptlib.h
+bf_null.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+bf_null.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+bf_null.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
+bf_null.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
+bf_null.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
+bf_null.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+bf_null.o: ../../include/openssl/symhacks.h ../cryptlib.h
bio_cb.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
bio_cb.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
bio_cb.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-bio_cb.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-bio_cb.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+bio_cb.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
+bio_cb.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
+bio_cb.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
bio_cb.o: ../cryptlib.h
bio_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
-bio_err.o: ../../include/openssl/err.h ../../include/openssl/opensslv.h
-bio_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+bio_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
+bio_err.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
+bio_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
bio_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
bio_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
bio_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-bio_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-bio_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+bio_lib.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
+bio_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
+bio_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
bio_lib.o: ../cryptlib.h
bss_acpt.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
bss_acpt.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
bss_acpt.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-bss_acpt.o: ../../include/openssl/opensslconf.h
+bss_acpt.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
bss_acpt.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
-bss_acpt.o: ../../include/openssl/stack.h ../cryptlib.h
+bss_acpt.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+bss_acpt.o: ../cryptlib.h
bss_bio.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
bss_bio.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
-bss_bio.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
-bss_bio.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
-bss_bio.o: ../../include/openssl/stack.h
+bss_bio.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
+bss_bio.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+bss_bio.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+bss_bio.o: ../../include/openssl/symhacks.h
bss_conn.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
bss_conn.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
bss_conn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-bss_conn.o: ../../include/openssl/opensslconf.h
+bss_conn.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
bss_conn.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
-bss_conn.o: ../../include/openssl/stack.h ../cryptlib.h
+bss_conn.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+bss_conn.o: ../cryptlib.h
bss_fd.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
bss_fd.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
bss_fd.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-bss_fd.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-bss_fd.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+bss_fd.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
+bss_fd.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
+bss_fd.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
bss_fd.o: ../cryptlib.h bss_sock.c
bss_file.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
bss_file.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
bss_file.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-bss_file.o: ../../include/openssl/opensslconf.h
+bss_file.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
bss_file.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
-bss_file.o: ../../include/openssl/stack.h ../cryptlib.h
+bss_file.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+bss_file.o: ../cryptlib.h
bss_log.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
bss_log.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
bss_log.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-bss_log.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-bss_log.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+bss_log.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
+bss_log.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
+bss_log.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
bss_log.o: ../cryptlib.h
bss_mem.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
bss_mem.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
bss_mem.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-bss_mem.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-bss_mem.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
+bss_mem.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
+bss_mem.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
+bss_mem.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
bss_mem.o: ../cryptlib.h
bss_null.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
bss_null.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
bss_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-bss_null.o: ../../include/openssl/opensslconf.h
+bss_null.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
bss_null.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
-bss_null.o: ../../include/openssl/stack.h ../cryptlib.h
+bss_null.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+bss_null.o: ../cryptlib.h
bss_sock.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
bss_sock.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
bss_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
-bss_sock.o: ../../include/openssl/opensslconf.h
+bss_sock.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
bss_sock.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
-bss_sock.o: ../../include/openssl/stack.h ../cryptlib.h
+bss_sock.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+bss_sock.o: ../cryptlib.h
diff --git a/lib/libcrypto/bio/b_dump.c b/lib/libcrypto/bio/b_dump.c
index f5aeb237f50..8397cfab6a2 100644
--- a/lib/libcrypto/bio/b_dump.c
+++ b/lib/libcrypto/bio/b_dump.c
@@ -66,63 +66,87 @@
#define TRUNCATE
#define DUMP_WIDTH 16
+#define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH-((i-(i>6?6:i)+3)/4))
int BIO_dump(BIO *bio, const char *s, int len)
-{
- int ret=0;
- char buf[160+1],tmp[20];
- int i,j,rows,trunc;
- unsigned char ch;
-
- trunc=0;
+ {
+ return BIO_dump_indent(bio, s, len, 0);
+ }
+int BIO_dump_indent(BIO *bio, const char *s, int len, int indent)
+ {
+ int ret=0;
+ char buf[288+1],tmp[20],str[128+1];
+ int i,j,rows,trunc;
+ unsigned char ch;
+ int dump_width;
+
+ trunc=0;
+
#ifdef TRUNCATE
- for(; (len > 0) && ((s[len-1] == ' ') || (s[len-1] == '\0')); len--)
- trunc++;
+ for(; (len > 0) && ((s[len-1] == ' ') || (s[len-1] == '\0')); len--)
+ trunc++;
#endif
- rows=(len/DUMP_WIDTH);
- if ((rows*DUMP_WIDTH)<len)
- rows++;
- for(i=0;i<rows;i++) {
- buf[0]='\0'; /* start with empty string */
- sprintf(tmp,"%04x - ",i*DUMP_WIDTH);
- strcpy(buf,tmp);
- for(j=0;j<DUMP_WIDTH;j++) {
- if (((i*DUMP_WIDTH)+j)>=len) {
- strcat(buf," ");
- } else {
- ch=((unsigned char)*(s+i*DUMP_WIDTH+j)) & 0xff;
- sprintf(tmp,"%02x%c",ch,j==7?'-':' ');
- strcat(buf,tmp);
- }
- }
- strcat(buf," ");
- for(j=0;j<DUMP_WIDTH;j++) {
- if (((i*DUMP_WIDTH)+j)>=len)
- break;
- ch=((unsigned char)*(s+i*DUMP_WIDTH+j)) & 0xff;
+ if (indent < 0)
+ indent = 0;
+ if (indent)
+ {
+ if (indent > 128) indent=128;
+ memset(str,' ',indent);
+ }
+ str[indent]='\0';
+
+ dump_width=DUMP_WIDTH_LESS_INDENT(indent);
+ rows=(len/dump_width);
+ if ((rows*dump_width)<len)
+ rows++;
+ for(i=0;i<rows;i++)
+ {
+ buf[0]='\0'; /* start with empty string */
+ strcpy(buf,str);
+ sprintf(tmp,"%04x - ",i*dump_width);
+ strcat(buf,tmp);
+ for(j=0;j<dump_width;j++)
+ {
+ if (((i*dump_width)+j)>=len)
+ {
+ strcat(buf," ");
+ }
+ else
+ {
+ ch=((unsigned char)*(s+i*dump_width+j)) & 0xff;
+ sprintf(tmp,"%02x%c",ch,j==7?'-':' ');
+ strcat(buf,tmp);
+ }
+ }
+ strcat(buf," ");
+ for(j=0;j<dump_width;j++)
+ {
+ if (((i*dump_width)+j)>=len)
+ break;
+ ch=((unsigned char)*(s+i*dump_width+j)) & 0xff;
#ifndef CHARSET_EBCDIC
- sprintf(tmp,"%c",((ch>=' ')&&(ch<='~'))?ch:'.');
+ sprintf(tmp,"%c",((ch>=' ')&&(ch<='~'))?ch:'.');
#else
- sprintf(tmp,"%c",((ch>=os_toascii[' '])&&(ch<=os_toascii['~']))
- ? os_toebcdic[ch]
- : '.');
+ sprintf(tmp,"%c",((ch>=os_toascii[' '])&&(ch<=os_toascii['~']))
+ ? os_toebcdic[ch]
+ : '.');
#endif
- strcat(buf,tmp);
- }
- strcat(buf,"\n");
- /* if this is the last call then update the ddt_dump thing so that
- * we will move the selection point in the debug window
- */
- ret+=BIO_write(bio,(char *)buf,strlen(buf));
- }
+ strcat(buf,tmp);
+ }
+ strcat(buf,"\n");
+ /* if this is the last call then update the ddt_dump thing so that
+ * we will move the selection point in the debug window
+ */
+ ret+=BIO_write(bio,(char *)buf,strlen(buf));
+ }
#ifdef TRUNCATE
- if (trunc > 0) {
- sprintf(buf,"%04x - <SPACES/NULS>\n",len+trunc);
- ret+=BIO_write(bio,(char *)buf,strlen(buf));
- }
+ if (trunc > 0)
+ {
+ sprintf(buf,"%s%04x - <SPACES/NULS>\n",str,len+trunc);
+ ret+=BIO_write(bio,(char *)buf,strlen(buf));
+ }
#endif
- return(ret);
-}
-
+ return(ret);
+ }
diff --git a/lib/libcrypto/bio/b_print.c b/lib/libcrypto/bio/b_print.c
index b11b501512b..a62f5516354 100644
--- a/lib/libcrypto/bio/b_print.c
+++ b/lib/libcrypto/bio/b_print.c
@@ -61,7 +61,6 @@
*/
#include <stdio.h>
-#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
@@ -78,48 +77,7 @@
# endif
#endif
-static void dopr (char *buffer, size_t maxlen, size_t *retlen,
- const char *format, va_list args);
-#ifdef USE_ALLOCATING_PRINT
-static void doapr (char **buffer, size_t *retlen,
- const char *format, va_list args);
-#endif
-
-int BIO_printf (BIO *bio, ...)
- {
- va_list args;
- char *format;
- int ret;
- size_t retlen;
-#ifdef USE_ALLOCATING_PRINT
- char *hugebuf;
-#else
- MS_STATIC char hugebuf[1024*2]; /* 10k in one chunk is the limit */
-#endif
-
- va_start(args, bio);
- format=va_arg(args, char *);
-
-#ifndef USE_ALLOCATING_PRINT
- hugebuf[0]='\0';
- dopr(hugebuf, sizeof(hugebuf), &retlen, format, args);
-#else
- hugebuf = NULL;
- CRYPTO_push_info("doapr()");
- doapr(&hugebuf, &retlen, format, args);
- if (hugebuf)
- {
-#endif
- ret=BIO_write(bio, hugebuf, (int)retlen);
-
-#ifdef USE_ALLOCATING_PRINT
- Free(hugebuf);
- }
- CRYPTO_pop_info();
-#endif
- va_end(args);
- return(ret);
- }
+/***************************************************************************/
/*
* Copyright Patrick Powell 1995
@@ -140,6 +98,7 @@ int BIO_printf (BIO *bio, ...)
* o Andrew Tridgell <tridge@samba.org> (1998, for Samba)
* o Luke Mewburn <lukem@netbsd.org> (1999, for LukemFTP)
* o Ralf S. Engelschall <rse@engelschall.com> (1999, for Pth)
+ * o ... (for OpenSSL)
*/
#if HAVE_LONG_DOUBLE
@@ -154,25 +113,15 @@ int BIO_printf (BIO *bio, ...)
#define LLONG long
#endif
-static void fmtstr (void (*)(char **, size_t *, size_t *, int),
- char **, size_t *, size_t *, const char *, int, int,
- int);
-static void fmtint (void (*)(char **, size_t *, size_t *, int),
- char **, size_t *, size_t *, LLONG, int, int, int, int);
-static void fmtfp (void (*)(char **, size_t *, size_t *, int),
- char **, size_t *, size_t *, LDOUBLE, int, int, int);
-#ifndef USE_ALLOCATING_PRINT
-static int dopr_isbig (size_t, size_t);
-static int dopr_copy (size_t);
-static void dopr_outch (char **, size_t *, size_t *, int);
-#else
-static int doapr_isbig (size_t, size_t);
-static int doapr_copy (size_t);
-static void doapr_outch (char **, size_t *, size_t *, int);
-#endif
-static void _dopr(void (*)(char **, size_t *, size_t *, int),
- int (*)(size_t, size_t), int (*)(size_t),
- char **buffer, size_t *maxlen, size_t *retlen,
+static void fmtstr (char **, char **, size_t *, size_t *,
+ const char *, int, int, int);
+static void fmtint (char **, char **, size_t *, size_t *,
+ LLONG, int, int, int, int);
+static void fmtfp (char **, char **, size_t *, size_t *,
+ LDOUBLE, int, int, int);
+static void doapr_outch (char **, char **, size_t *, size_t *, int);
+static void _dopr(char **sbuffer, char **buffer,
+ size_t *maxlen, size_t *retlen, int *truncated,
const char *format, va_list args);
/* format read states */
@@ -204,41 +153,13 @@ static void _dopr(void (*)(char **, size_t *, size_t *, int),
#define char_to_int(p) (p - '0')
#define MAX(p,q) ((p >= q) ? p : q)
-#ifndef USE_ALLOCATING_PRINT
-static void
-dopr(
- char *buffer,
- size_t maxlen,
- size_t *retlen,
- const char *format,
- va_list args)
-{
- _dopr(dopr_outch, dopr_isbig, dopr_copy,
- &buffer, &maxlen, retlen, format, args);
-}
-
-#else
-static void
-doapr(
- char **buffer,
- size_t *retlen,
- const char *format,
- va_list args)
-{
- size_t dummy_maxlen = 0;
- _dopr(doapr_outch, doapr_isbig, doapr_copy,
- buffer, &dummy_maxlen, retlen, format, args);
-}
-#endif
-
static void
_dopr(
- void (*outch_fn)(char **, size_t *, size_t *, int),
- int (*isbig_fn)(size_t, size_t),
- int (*copy_fn)(size_t),
+ char **sbuffer,
char **buffer,
size_t *maxlen,
size_t *retlen,
+ int *truncated,
const char *format,
va_list args)
{
@@ -259,7 +180,7 @@ _dopr(
ch = *format++;
while (state != DP_S_DONE) {
- if ((ch == '\0') || (*isbig_fn)(currlen, *maxlen))
+ if (ch == '\0' || (buffer == NULL && currlen >= *maxlen))
state = DP_S_DONE;
switch (state) {
@@ -267,7 +188,7 @@ _dopr(
if (ch == '%')
state = DP_S_FLAGS;
else
- (*outch_fn)(buffer, &currlen, maxlen, ch);
+ doapr_outch(sbuffer,buffer, &currlen, maxlen, ch);
ch = *format++;
break;
case DP_S_FLAGS:
@@ -373,8 +294,8 @@ _dopr(
value = va_arg(args, int);
break;
}
- fmtint(outch_fn, buffer, &currlen, maxlen,
- value, 10, min, max, flags);
+ fmtint(sbuffer, buffer, &currlen, maxlen,
+ value, 10, min, max, flags);
break;
case 'X':
flags |= DP_F_UP;
@@ -399,7 +320,7 @@ _dopr(
unsigned int);
break;
}
- fmtint(outch_fn, buffer, &currlen, maxlen, value,
+ fmtint(sbuffer, buffer, &currlen, maxlen, value,
ch == 'o' ? 8 : (ch == 'u' ? 10 : 16),
min, max, flags);
break;
@@ -408,8 +329,8 @@ _dopr(
fvalue = va_arg(args, LDOUBLE);
else
fvalue = va_arg(args, double);
- fmtfp(outch_fn, buffer, &currlen, maxlen,
- fvalue, min, max, flags);
+ fmtfp(sbuffer, buffer, &currlen, maxlen,
+ fvalue, min, max, flags);
break;
case 'E':
flags |= DP_F_UP;
@@ -428,19 +349,23 @@ _dopr(
fvalue = va_arg(args, double);
break;
case 'c':
- (*outch_fn)(buffer, &currlen, maxlen,
+ doapr_outch(sbuffer, buffer, &currlen, maxlen,
va_arg(args, int));
break;
case 's':
strvalue = va_arg(args, char *);
- if (max < 0)
- max = (*copy_fn)(*maxlen);
- fmtstr(outch_fn, buffer, &currlen, maxlen, strvalue,
- flags, min, max);
+ if (max < 0) {
+ if (buffer)
+ max = INT_MAX;
+ else
+ max = *maxlen;
+ }
+ fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue,
+ flags, min, max);
break;
case 'p':
value = (long)va_arg(args, void *);
- fmtint(outch_fn, buffer, &currlen, maxlen,
+ fmtint(sbuffer, buffer, &currlen, maxlen,
value, 16, min, max, flags);
break;
case 'n': /* XXX */
@@ -463,7 +388,7 @@ _dopr(
}
break;
case '%':
- (*outch_fn)(buffer, &currlen, maxlen, ch);
+ doapr_outch(sbuffer, buffer, &currlen, maxlen, ch);
break;
case 'w':
/* not supported yet, treat as next char */
@@ -484,16 +409,17 @@ _dopr(
break;
}
}
- if (currlen >= *maxlen - 1)
+ *truncated = (currlen > *maxlen - 1);
+ if (*truncated)
currlen = *maxlen - 1;
- (*buffer)[currlen] = '\0';
- *retlen = currlen;
+ doapr_outch(sbuffer, buffer, &currlen, maxlen, '\0');
+ *retlen = currlen - 1;
return;
}
static void
fmtstr(
- void (*outch_fn)(char **, size_t *, size_t *, int),
+ char **sbuffer,
char **buffer,
size_t *currlen,
size_t *maxlen,
@@ -516,16 +442,16 @@ fmtstr(
padlen = -padlen;
while ((padlen > 0) && (cnt < max)) {
- (*outch_fn)(buffer, currlen, maxlen, ' ');
+ doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
--padlen;
++cnt;
}
while (*value && (cnt < max)) {
- (*outch_fn)(buffer, currlen, maxlen, *value++);
+ doapr_outch(sbuffer, buffer, currlen, maxlen, *value++);
++cnt;
}
while ((padlen < 0) && (cnt < max)) {
- (*outch_fn)(buffer, currlen, maxlen, ' ');
+ doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
++padlen;
++cnt;
}
@@ -533,7 +459,7 @@ fmtstr(
static void
fmtint(
- void (*outch_fn)(char **, size_t *, size_t *, int),
+ char **sbuffer,
char **buffer,
size_t *currlen,
size_t *maxlen,
@@ -590,28 +516,28 @@ fmtint(
/* spaces */
while (spadlen > 0) {
- (*outch_fn)(buffer, currlen, maxlen, ' ');
+ doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
--spadlen;
}
/* sign */
if (signvalue)
- (*outch_fn)(buffer, currlen, maxlen, signvalue);
+ doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
/* zeros */
if (zpadlen > 0) {
while (zpadlen > 0) {
- (*outch_fn)(buffer, currlen, maxlen, '0');
+ doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
--zpadlen;
}
}
/* digits */
while (place > 0)
- (*outch_fn)(buffer, currlen, maxlen, convert[--place]);
+ doapr_outch(sbuffer, buffer, currlen, maxlen, convert[--place]);
/* left justified spaces */
while (spadlen < 0) {
- (*outch_fn)(buffer, currlen, maxlen, ' ');
+ doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
++spadlen;
}
return;
@@ -650,7 +576,7 @@ round(LDOUBLE value)
static void
fmtfp(
- void (*outch_fn)(char **, size_t *, size_t *, int),
+ char **sbuffer,
char **buffer,
size_t *currlen,
size_t *maxlen,
@@ -731,114 +657,158 @@ fmtfp(
if ((flags & DP_F_ZERO) && (padlen > 0)) {
if (signvalue) {
- (*outch_fn)(buffer, currlen, maxlen, signvalue);
+ doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
--padlen;
signvalue = 0;
}
while (padlen > 0) {
- (*outch_fn)(buffer, currlen, maxlen, '0');
+ doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
--padlen;
}
}
while (padlen > 0) {
- (*outch_fn)(buffer, currlen, maxlen, ' ');
+ doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
--padlen;
}
if (signvalue)
- (*outch_fn)(buffer, currlen, maxlen, signvalue);
+ doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
while (iplace > 0)
- (*outch_fn)(buffer, currlen, maxlen, iconvert[--iplace]);
+ doapr_outch(sbuffer, buffer, currlen, maxlen, iconvert[--iplace]);
/*
* Decimal point. This should probably use locale to find the correct
* char to print out.
*/
if (max > 0) {
- (*outch_fn)(buffer, currlen, maxlen, '.');
+ doapr_outch(sbuffer, buffer, currlen, maxlen, '.');
while (fplace > 0)
- (*outch_fn)(buffer, currlen, maxlen, fconvert[--fplace]);
+ doapr_outch(sbuffer, buffer, currlen, maxlen, fconvert[--fplace]);
}
while (zpadlen > 0) {
- (*outch_fn)(buffer, currlen, maxlen, '0');
+ doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
--zpadlen;
}
while (padlen < 0) {
- (*outch_fn)(buffer, currlen, maxlen, ' ');
+ doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
++padlen;
}
}
-static int
-dopr_copy(
- size_t len)
-{
- return len;
-}
-
-#ifdef USE_ALLOCATING_PRINT
-static int
-doapr_copy(
- size_t len)
-{
- /* Return as high an integer as possible */
- return INT_MAX;
-}
-#endif
-
-static int
-dopr_isbig(
- size_t currlen,
- size_t maxlen)
-{
- return currlen > maxlen;
-}
-
-#ifdef USE_ALLOCATING_PRINT
-static int
-doapr_isbig(
- size_t currlen,
- size_t maxlen)
-{
- return 0;
-}
-#endif
-
-static void
-dopr_outch(
- char **buffer,
- size_t *currlen,
- size_t *maxlen,
- int c)
-{
- if (*currlen < *maxlen)
- (*buffer)[(*currlen)++] = (char)c;
- return;
-}
-
-#ifdef USE_ALLOCATING_PRINT
static void
doapr_outch(
+ char **sbuffer,
char **buffer,
size_t *currlen,
size_t *maxlen,
int c)
{
- if (*buffer == NULL) {
- if (*maxlen == 0)
- *maxlen = 1024;
- *buffer = Malloc(*maxlen);
+ /* If we haven't at least one buffer, someone has doe a big booboo */
+ assert(*sbuffer != NULL || buffer != NULL);
+
+ if (buffer) {
+ while (*currlen >= *maxlen) {
+ if (*buffer == NULL) {
+ assert(*sbuffer != NULL);
+ if (*maxlen == 0)
+ *maxlen = 1024;
+ *buffer = OPENSSL_malloc(*maxlen);
+ if (*currlen > 0)
+ memcpy(*buffer, *sbuffer, *currlen);
+ *sbuffer = NULL;
+ } else {
+ *maxlen += 1024;
+ *buffer = OPENSSL_realloc(*buffer, *maxlen);
+ }
+ }
+ /* What to do if *buffer is NULL? */
+ assert(*sbuffer != NULL || *buffer != NULL);
}
- while (*currlen >= *maxlen) {
- *maxlen += 1024;
- *buffer = Realloc(*buffer, *maxlen);
+
+ if (*currlen < *maxlen) {
+ if (*sbuffer)
+ (*sbuffer)[(*currlen)++] = (char)c;
+ else
+ (*buffer)[(*currlen)++] = (char)c;
}
- /* What to do if *buffer is NULL? */
- assert(*buffer != NULL);
- (*buffer)[(*currlen)++] = (char)c;
return;
}
-#endif
+
+/***************************************************************************/
+
+int BIO_printf (BIO *bio, const char *format, ...)
+ {
+ va_list args;
+ int ret;
+
+ va_start(args, format);
+
+ ret = BIO_vprintf(bio, format, args);
+
+ va_end(args);
+ return(ret);
+ }
+
+int BIO_vprintf (BIO *bio, const char *format, va_list args)
+ {
+ int ret;
+ size_t retlen;
+ MS_STATIC char hugebuf[1024*10];
+ char *hugebufp = hugebuf;
+ size_t hugebufsize = sizeof(hugebuf);
+ char *dynbuf = NULL;
+ int ignored;
+
+ dynbuf = NULL;
+ CRYPTO_push_info("doapr()");
+ _dopr(&hugebufp, &dynbuf, &hugebufsize,
+ &retlen, &ignored, format, args);
+ if (dynbuf)
+ {
+ ret=BIO_write(bio, dynbuf, (int)retlen);
+ OPENSSL_free(dynbuf);
+ }
+ else
+ {
+ ret=BIO_write(bio, hugebuf, (int)retlen);
+ }
+ CRYPTO_pop_info();
+ return(ret);
+ }
+
+/* As snprintf is not available everywhere, we provide our own implementation.
+ * This function has nothing to do with BIOs, but it's closely related
+ * to BIO_printf, and we need *some* name prefix ...
+ * (XXX the function should be renamed, but to what?) */
+int BIO_snprintf(char *buf, size_t n, const char *format, ...)
+ {
+ va_list args;
+ int ret;
+
+ va_start(args, format);
+
+ ret = BIO_vsnprintf(buf, n, format, args);
+
+ va_end(args);
+ return(ret);
+ }
+
+int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)
+ {
+ size_t retlen;
+ int truncated;
+
+ _dopr(&buf, NULL, &n, &retlen, &truncated, format, args);
+
+ if (truncated)
+ /* In case of truncation, return -1 like traditional snprintf.
+ * (Current drafts for ISO/IEC 9899 say snprintf should return
+ * the number of characters that would have been written,
+ * had the buffer been large enough.) */
+ return -1;
+ else
+ return (retlen <= INT_MAX) ? retlen : -1;
+ }
diff --git a/lib/libcrypto/bio/b_sock.c b/lib/libcrypto/bio/b_sock.c
index 6409f98f570..64310058b45 100644
--- a/lib/libcrypto/bio/b_sock.c
+++ b/lib/libcrypto/bio/b_sock.c
@@ -105,17 +105,22 @@ int BIO_get_host_ip(const char *str, unsigned char *ip)
struct hostent *he;
i=get_ip(str,ip);
- if (i > 0) return(1);
if (i < 0)
{
BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_INVALID_IP_ADDRESS);
goto err;
}
- /* do a gethostbyname */
+ /* At this point, we have something that is most probably correct
+ in some way, so let's init the socket. */
if (!BIO_sock_init())
return(0); /* don't generate another error code here */
+ /* If the string actually contained an IP address, we need not do
+ anything more */
+ if (i > 0) return(1);
+
+ /* do a gethostbyname */
CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME);
locked = 1;
he=BIO_gethostbyname(str);
@@ -267,14 +272,14 @@ static struct hostent *ghbn_dup(struct hostent *a)
int i,j;
MemCheck_off();
- ret=(struct hostent *)Malloc(sizeof(struct hostent));
+ ret=(struct hostent *)OPENSSL_malloc(sizeof(struct hostent));
if (ret == NULL) return(NULL);
memset(ret,0,sizeof(struct hostent));
for (i=0; a->h_aliases[i] != NULL; i++)
;
i++;
- ret->h_aliases = (char **)Malloc(i*sizeof(char *));
+ ret->h_aliases = (char **)OPENSSL_malloc(i*sizeof(char *));
if (ret->h_aliases == NULL)
goto err;
memset(ret->h_aliases, 0, i*sizeof(char *));
@@ -282,25 +287,25 @@ static struct hostent *ghbn_dup(struct hostent *a)
for (i=0; a->h_addr_list[i] != NULL; i++)
;
i++;
- ret->h_addr_list=(char **)Malloc(i*sizeof(char *));
+ ret->h_addr_list=(char **)OPENSSL_malloc(i*sizeof(char *));
if (ret->h_addr_list == NULL)
goto err;
memset(ret->h_addr_list, 0, i*sizeof(char *));
j=strlen(a->h_name)+1;
- if ((ret->h_name=Malloc(j)) == NULL) goto err;
+ if ((ret->h_name=OPENSSL_malloc(j)) == NULL) goto err;
memcpy((char *)ret->h_name,a->h_name,j);
for (i=0; a->h_aliases[i] != NULL; i++)
{
j=strlen(a->h_aliases[i])+1;
- if ((ret->h_aliases[i]=Malloc(j)) == NULL) goto err;
+ if ((ret->h_aliases[i]=OPENSSL_malloc(j)) == NULL) goto err;
memcpy(ret->h_aliases[i],a->h_aliases[i],j);
}
ret->h_length=a->h_length;
ret->h_addrtype=a->h_addrtype;
for (i=0; a->h_addr_list[i] != NULL; i++)
{
- if ((ret->h_addr_list[i]=Malloc(a->h_length)) == NULL)
+ if ((ret->h_addr_list[i]=OPENSSL_malloc(a->h_length)) == NULL)
goto err;
memcpy(ret->h_addr_list[i],a->h_addr_list[i],a->h_length);
}
@@ -325,17 +330,17 @@ static void ghbn_free(struct hostent *a)
if (a->h_aliases != NULL)
{
for (i=0; a->h_aliases[i] != NULL; i++)
- Free(a->h_aliases[i]);
- Free(a->h_aliases);
+ OPENSSL_free(a->h_aliases[i]);
+ OPENSSL_free(a->h_aliases);
}
if (a->h_addr_list != NULL)
{
for (i=0; a->h_addr_list[i] != NULL; i++)
- Free(a->h_addr_list[i]);
- Free(a->h_addr_list);
+ OPENSSL_free(a->h_addr_list[i]);
+ OPENSSL_free(a->h_addr_list);
}
- if (a->h_name != NULL) Free(a->h_name);
- Free(a);
+ if (a->h_name != NULL) OPENSSL_free(a->h_name);
+ OPENSSL_free(a);
}
struct hostent *BIO_gethostbyname(const char *name)
@@ -628,7 +633,7 @@ again:
}
ret=1;
err:
- if (str != NULL) Free(str);
+ if (str != NULL) OPENSSL_free(str);
if ((ret == 0) && (s != INVALID_SOCKET))
{
closesocket(s);
@@ -667,7 +672,7 @@ int BIO_accept(int sock, char **addr)
port=ntohs(from.sin_port);
if (*addr == NULL)
{
- if ((p=Malloc(24)) == NULL)
+ if ((p=OPENSSL_malloc(24)) == NULL)
{
BIOerr(BIO_F_BIO_ACCEPT,ERR_R_MALLOC_FAILURE);
goto end;
diff --git a/lib/libcrypto/bio/bf_buff.c b/lib/libcrypto/bio/bf_buff.c
index ff0c9070ae1..f50e8f98a3d 100644
--- a/lib/libcrypto/bio/bf_buff.c
+++ b/lib/libcrypto/bio/bf_buff.c
@@ -62,14 +62,14 @@
#include <openssl/bio.h>
#include <openssl/evp.h>
-static int buffer_write(BIO *h,char *buf,int num);
-static int buffer_read(BIO *h,char *buf,int size);
-static int buffer_puts(BIO *h,char *str);
-static int buffer_gets(BIO *h,char *str,int size);
-static long buffer_ctrl(BIO *h,int cmd,long arg1,char *arg2);
+static int buffer_write(BIO *h, const char *buf,int num);
+static int buffer_read(BIO *h, char *buf, int size);
+static int buffer_puts(BIO *h, const char *str);
+static int buffer_gets(BIO *h, char *str, int size);
+static long buffer_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int buffer_new(BIO *h);
static int buffer_free(BIO *data);
-static long buffer_callback_ctrl(BIO *h,int cmd, void (*fp)());
+static long buffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
#define DEFAULT_BUFFER_SIZE 1024
static BIO_METHOD methods_buffer=
@@ -95,12 +95,12 @@ static int buffer_new(BIO *bi)
{
BIO_F_BUFFER_CTX *ctx;
- ctx=(BIO_F_BUFFER_CTX *)Malloc(sizeof(BIO_F_BUFFER_CTX));
+ ctx=(BIO_F_BUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_F_BUFFER_CTX));
if (ctx == NULL) return(0);
- ctx->ibuf=(char *)Malloc(DEFAULT_BUFFER_SIZE);
- if (ctx->ibuf == NULL) { Free(ctx); return(0); }
- ctx->obuf=(char *)Malloc(DEFAULT_BUFFER_SIZE);
- if (ctx->obuf == NULL) { Free(ctx->ibuf); Free(ctx); return(0); }
+ ctx->ibuf=(char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
+ if (ctx->ibuf == NULL) { OPENSSL_free(ctx); return(0); }
+ ctx->obuf=(char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
+ if (ctx->obuf == NULL) { OPENSSL_free(ctx->ibuf); OPENSSL_free(ctx); return(0); }
ctx->ibuf_size=DEFAULT_BUFFER_SIZE;
ctx->obuf_size=DEFAULT_BUFFER_SIZE;
ctx->ibuf_len=0;
@@ -120,9 +120,9 @@ static int buffer_free(BIO *a)
if (a == NULL) return(0);
b=(BIO_F_BUFFER_CTX *)a->ptr;
- if (b->ibuf != NULL) Free(b->ibuf);
- if (b->obuf != NULL) Free(b->obuf);
- Free(a->ptr);
+ if (b->ibuf != NULL) OPENSSL_free(b->ibuf);
+ if (b->obuf != NULL) OPENSSL_free(b->obuf);
+ OPENSSL_free(a->ptr);
a->ptr=NULL;
a->init=0;
a->flags=0;
@@ -195,7 +195,7 @@ start:
goto start;
}
-static int buffer_write(BIO *b, char *in, int inl)
+static int buffer_write(BIO *b, const char *in, int inl)
{
int i,num=0;
BIO_F_BUFFER_CTX *ctx;
@@ -268,7 +268,7 @@ start:
goto start;
}
-static long buffer_ctrl(BIO *b, int cmd, long num, char *ptr)
+static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
{
BIO *dbio;
BIO_F_BUFFER_CTX *ctx;
@@ -319,9 +319,9 @@ static long buffer_ctrl(BIO *b, int cmd, long num, char *ptr)
case BIO_C_SET_BUFF_READ_DATA:
if (num > ctx->ibuf_size)
{
- p1=Malloc((int)num);
+ p1=OPENSSL_malloc((int)num);
if (p1 == NULL) goto malloc_error;
- if (ctx->ibuf != NULL) Free(ctx->ibuf);
+ if (ctx->ibuf != NULL) OPENSSL_free(ctx->ibuf);
ctx->ibuf=p1;
}
ctx->ibuf_off=0;
@@ -353,21 +353,21 @@ static long buffer_ctrl(BIO *b, int cmd, long num, char *ptr)
p2=ctx->obuf;
if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size))
{
- p1=(char *)Malloc((int)num);
+ p1=(char *)OPENSSL_malloc((int)num);
if (p1 == NULL) goto malloc_error;
}
if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size))
{
- p2=(char *)Malloc((int)num);
+ p2=(char *)OPENSSL_malloc((int)num);
if (p2 == NULL)
{
- if (p1 != ctx->ibuf) Free(p1);
+ if (p1 != ctx->ibuf) OPENSSL_free(p1);
goto malloc_error;
}
}
if (ctx->ibuf != p1)
{
- Free(ctx->ibuf);
+ OPENSSL_free(ctx->ibuf);
ctx->ibuf=p1;
ctx->ibuf_off=0;
ctx->ibuf_len=0;
@@ -375,7 +375,7 @@ static long buffer_ctrl(BIO *b, int cmd, long num, char *ptr)
}
if (ctx->obuf != p2)
{
- Free(ctx->obuf);
+ OPENSSL_free(ctx->obuf);
ctx->obuf=p2;
ctx->obuf_off=0;
ctx->obuf_len=0;
@@ -439,7 +439,7 @@ malloc_error:
return(0);
}
-static long buffer_callback_ctrl(BIO *b, int cmd, void (*fp)())
+static long buffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
{
long ret=1;
@@ -504,8 +504,8 @@ static int buffer_gets(BIO *b, char *buf, int size)
}
}
-static int buffer_puts(BIO *b, char *str)
+static int buffer_puts(BIO *b, const char *str)
{
- return(BIO_write(b,str,strlen(str)));
+ return(buffer_write(b,str,strlen(str)));
}
diff --git a/lib/libcrypto/bio/bf_nbio.c b/lib/libcrypto/bio/bf_nbio.c
index 5e574b72316..413ef5c4c5e 100644
--- a/lib/libcrypto/bio/bf_nbio.c
+++ b/lib/libcrypto/bio/bf_nbio.c
@@ -66,14 +66,14 @@
/* BIO_put and BIO_get both add to the digest,
* BIO_gets returns the digest */
-static int nbiof_write(BIO *h,char *buf,int num);
+static int nbiof_write(BIO *h,const char *buf,int num);
static int nbiof_read(BIO *h,char *buf,int size);
-static int nbiof_puts(BIO *h,char *str);
+static int nbiof_puts(BIO *h,const char *str);
static int nbiof_gets(BIO *h,char *str,int size);
-static long nbiof_ctrl(BIO *h,int cmd,long arg1,char *arg2);
+static long nbiof_ctrl(BIO *h,int cmd,long arg1,void *arg2);
static int nbiof_new(BIO *h);
static int nbiof_free(BIO *data);
-static long nbiof_callback_ctrl(BIO *h,int cmd,void (*fp)());
+static long nbiof_callback_ctrl(BIO *h,int cmd,bio_info_cb *fp);
typedef struct nbio_test_st
{
/* only set if we sent a 'should retry' error */
@@ -104,7 +104,7 @@ static int nbiof_new(BIO *bi)
{
NBIO_TEST *nt;
- nt=(NBIO_TEST *)Malloc(sizeof(NBIO_TEST));
+ nt=(NBIO_TEST *)OPENSSL_malloc(sizeof(NBIO_TEST));
nt->lrn= -1;
nt->lwn= -1;
bi->ptr=(char *)nt;
@@ -117,7 +117,7 @@ static int nbiof_free(BIO *a)
{
if (a == NULL) return(0);
if (a->ptr != NULL)
- Free(a->ptr);
+ OPENSSL_free(a->ptr);
a->ptr=NULL;
a->init=0;
a->flags=0;
@@ -159,7 +159,7 @@ static int nbiof_read(BIO *b, char *out, int outl)
return(ret);
}
-static int nbiof_write(BIO *b, char *in, int inl)
+static int nbiof_write(BIO *b, const char *in, int inl)
{
NBIO_TEST *nt;
int ret=0;
@@ -204,7 +204,7 @@ static int nbiof_write(BIO *b, char *in, int inl)
return(ret);
}
-static long nbiof_ctrl(BIO *b, int cmd, long num, char *ptr)
+static long nbiof_ctrl(BIO *b, int cmd, long num, void *ptr)
{
long ret;
@@ -226,7 +226,7 @@ static long nbiof_ctrl(BIO *b, int cmd, long num, char *ptr)
return(ret);
}
-static long nbiof_callback_ctrl(BIO *b, int cmd, void (*fp)())
+static long nbiof_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
{
long ret=1;
@@ -247,7 +247,7 @@ static int nbiof_gets(BIO *bp, char *buf, int size)
}
-static int nbiof_puts(BIO *bp, char *str)
+static int nbiof_puts(BIO *bp, const char *str)
{
if (bp->next_bio == NULL) return(0);
return(BIO_puts(bp->next_bio,str));
diff --git a/lib/libcrypto/bio/bf_null.c b/lib/libcrypto/bio/bf_null.c
index 0d183a6d9a4..2678a1a85d9 100644
--- a/lib/libcrypto/bio/bf_null.c
+++ b/lib/libcrypto/bio/bf_null.c
@@ -65,14 +65,14 @@
/* BIO_put and BIO_get both add to the digest,
* BIO_gets returns the digest */
-static int nullf_write(BIO *h,char *buf,int num);
-static int nullf_read(BIO *h,char *buf,int size);
-static int nullf_puts(BIO *h,char *str);
-static int nullf_gets(BIO *h,char *str,int size);
-static long nullf_ctrl(BIO *h,int cmd,long arg1,char *arg2);
+static int nullf_write(BIO *h, const char *buf, int num);
+static int nullf_read(BIO *h, char *buf, int size);
+static int nullf_puts(BIO *h, const char *str);
+static int nullf_gets(BIO *h, char *str, int size);
+static long nullf_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int nullf_new(BIO *h);
static int nullf_free(BIO *data);
-static long nullf_callback_ctrl(BIO *h,int cmd,void (*fp)());
+static long nullf_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
static BIO_METHOD methods_nullf=
{
BIO_TYPE_NULL_FILTER,
@@ -121,7 +121,7 @@ static int nullf_read(BIO *b, char *out, int outl)
return(ret);
}
-static int nullf_write(BIO *b, char *in, int inl)
+static int nullf_write(BIO *b, const char *in, int inl)
{
int ret=0;
@@ -133,7 +133,7 @@ static int nullf_write(BIO *b, char *in, int inl)
return(ret);
}
-static long nullf_ctrl(BIO *b, int cmd, long num, char *ptr)
+static long nullf_ctrl(BIO *b, int cmd, long num, void *ptr)
{
long ret;
@@ -154,7 +154,7 @@ static long nullf_ctrl(BIO *b, int cmd, long num, char *ptr)
return(ret);
}
-static long nullf_callback_ctrl(BIO *b, int cmd, void (*fp)())
+static long nullf_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
{
long ret=1;
@@ -175,7 +175,7 @@ static int nullf_gets(BIO *bp, char *buf, int size)
}
-static int nullf_puts(BIO *bp, char *str)
+static int nullf_puts(BIO *bp, const char *str)
{
if (bp->next_bio == NULL) return(0);
return(BIO_puts(bp->next_bio,str));
diff --git a/lib/libcrypto/bio/bio.h b/lib/libcrypto/bio/bio.h
index ebdb18170ba..97003b503c6 100644
--- a/lib/libcrypto/bio/bio.h
+++ b/lib/libcrypto/bio/bio.h
@@ -59,14 +59,17 @@
#ifndef HEADER_BIO_H
#define HEADER_BIO_H
-#ifdef __cplusplus
-extern "C" {
+#ifndef NO_FP_API
+# include <stdio.h>
#endif
+#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
#include <openssl/crypto.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/* These are the 'types' of BIOs */
#define BIO_TYPE_NONE 0
#define BIO_TYPE_MEM (1|0x0400)
@@ -88,6 +91,7 @@ extern "C" {
#define BIO_TYPE_NULL_FILTER (17|0x0200)
#define BIO_TYPE_BER (18|0x0200) /* BER -> bin filter */
#define BIO_TYPE_BIO (19|0x0400) /* (half a) BIO pair */
+#define BIO_TYPE_LINEBUFFER (20|0x0200) /* filter */
#define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */
#define BIO_TYPE_FILTER 0x0200
@@ -207,19 +211,23 @@ extern "C" {
#define BIO_method_name(b) ((b)->method->name)
#define BIO_method_type(b) ((b)->method->type)
+typedef struct bio_st BIO;
+
+typedef void bio_info_cb(struct bio_st *, int, const char *, int, long, long);
+
#ifndef WIN16
typedef struct bio_method_st
{
int type;
const char *name;
- int (*bwrite)();
- int (*bread)();
- int (*bputs)();
- int (*bgets)();
- long (*ctrl)();
- int (*create)();
- int (*destroy)();
- long (*callback_ctrl)();
+ int (*bwrite)(BIO *, const char *, int);
+ int (*bread)(BIO *, char *, int);
+ int (*bputs)(BIO *, const char *);
+ int (*bgets)(BIO *, char *, int);
+ long (*ctrl)(BIO *, int, long, void *);
+ int (*create)(BIO *);
+ int (*destroy)(BIO *);
+ long (*callback_ctrl)(BIO *, int, bio_info_cb *);
} BIO_METHOD;
#else
typedef struct bio_method_st
@@ -237,7 +245,7 @@ typedef struct bio_method_st
} BIO_METHOD;
#endif
-typedef struct bio_st
+struct bio_st
{
BIO_METHOD *method;
/* bio, mode, argp, argi, argl, ret */
@@ -257,7 +265,9 @@ typedef struct bio_st
unsigned long num_write;
CRYPTO_EX_DATA ex_data;
- } BIO;
+ };
+
+DECLARE_STACK_OF(BIO)
typedef struct bio_f_buffer_ctx_struct
{
@@ -454,8 +464,8 @@ int BIO_read_filename(BIO *b,const char *name);
size_t BIO_ctrl_pending(BIO *b);
size_t BIO_ctrl_wpending(BIO *b);
#define BIO_flush(b) (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL)
-#define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0,(void (**)())(cbp))
-#define BIO_set_info_callback(b,cb) (int)BIO_callback_ctrl(b,BIO_CTRL_SET_CALLBACK,(void (*)())(cb))
+#define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0,(bio_info_cb **)(cbp))
+#define BIO_set_info_callback(b,cb) (int)BIO_callback_ctrl(b,BIO_CTRL_SET_CALLBACK,(bio_info_cb *)(cb))
/* For the BIO_f_buffer() type */
#define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL)
@@ -465,6 +475,7 @@ size_t BIO_ctrl_wpending(BIO *b);
#define BIO_get_write_buf_size(b,size) (size_t)BIO_ctrl(b,BIO_C_GET_WRITE_BUF_SIZE,size,NULL)
#define BIO_make_bio_pair(b1,b2) (int)BIO_ctrl(b1,BIO_C_MAKE_BIO_PAIR,0,b2)
#define BIO_destroy_bio_pair(b) (int)BIO_ctrl(b,BIO_C_DESTROY_BIO_PAIR,0,NULL)
+#define BIO_shutdown_wr(b) (int)BIO_ctrl(b, BIO_C_SHUTDOWN_WR, 0, NULL)
/* macros with inappropriate type -- but ...pending macros use int too: */
#define BIO_get_write_guarantee(b) (int)BIO_ctrl(b,BIO_C_GET_WRITE_GUARANTEE,0,NULL)
#define BIO_get_read_request(b) (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL)
@@ -472,11 +483,6 @@ size_t BIO_ctrl_get_write_guarantee(BIO *b);
size_t BIO_ctrl_get_read_request(BIO *b);
int BIO_ctrl_reset_read_request(BIO *b);
-#ifdef NO_STDIO
-#define NO_FP_API
-#endif
-
-
/* These two aren't currently implemented */
/* int BIO_get_ex_num(BIO *bio); */
/* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */
@@ -487,6 +493,7 @@ int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
unsigned long BIO_number_read(BIO *bio);
unsigned long BIO_number_written(BIO *bio);
+# ifndef NO_FP_API
# if defined(WIN16) && defined(_WINDLL)
BIO_METHOD *BIO_s_file_internal(void);
BIO *BIO_new_file_internal(char *filename, char *mode);
@@ -502,21 +509,24 @@ BIO *BIO_new_fp(FILE *stream, int close_flag);
# define BIO_new_file_internal BIO_new_file
# define BIO_new_fp_internal BIO_s_file
# endif /* FP_API */
+# endif
BIO * BIO_new(BIO_METHOD *type);
int BIO_set(BIO *a,BIO_METHOD *type);
int BIO_free(BIO *a);
+void BIO_vfree(BIO *a);
int BIO_read(BIO *b, void *data, int len);
int BIO_gets(BIO *bp,char *buf, int size);
int BIO_write(BIO *b, const void *data, int len);
int BIO_puts(BIO *bp,const char *buf);
long BIO_ctrl(BIO *bp,int cmd,long larg,void *parg);
-long BIO_callback_ctrl(BIO *bp,int cmd,void (*fp)());
+long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long));
char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg);
long BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg);
BIO * BIO_push(BIO *b,BIO *append);
BIO * BIO_pop(BIO *b);
void BIO_free_all(BIO *a);
BIO * BIO_find_type(BIO *b,int bio_type);
+BIO * BIO_next(BIO *b);
BIO * BIO_get_retry_BIO(BIO *bio, int *reason);
int BIO_get_retry_reason(BIO *bio);
BIO * BIO_dup_chain(BIO *in);
@@ -545,6 +555,9 @@ BIO_METHOD *BIO_s_bio(void);
BIO_METHOD *BIO_s_null(void);
BIO_METHOD *BIO_f_null(void);
BIO_METHOD *BIO_f_buffer(void);
+#ifdef VMS
+BIO_METHOD *BIO_f_linebuffer(void);
+#endif
BIO_METHOD *BIO_f_nbio_test(void);
/* BIO_METHOD *BIO_f_ber(void); */
@@ -553,6 +566,7 @@ int BIO_sock_non_fatal_error(int error);
int BIO_fd_should_retry(int i);
int BIO_fd_non_fatal_error(int error);
int BIO_dump(BIO *b,const char *bytes,int len);
+int BIO_dump_indent(BIO *b,const char *bytes,int len,int indent);
struct hostent *BIO_gethostbyname(const char *name);
/* We might want a thread-safe interface too:
@@ -592,7 +606,10 @@ void BIO_copy_next_retry(BIO *b);
long BIO_ghbn_ctrl(int cmd,int iarg,char *parg);
-int BIO_printf(BIO *bio, ...);
+int BIO_printf(BIO *bio, const char *format, ...);
+int BIO_vprintf(BIO *bio, const char *format, va_list args);
+int BIO_snprintf(char *buf, size_t n, const char *format, ...);
+int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args);
/* BEGIN ERROR CODES */
/* The following lines are auto generated by the script mkerr.pl. Any changes
@@ -627,6 +644,8 @@ int BIO_printf(BIO *bio, ...);
#define BIO_F_CONN_CTRL 127
#define BIO_F_CONN_STATE 115
#define BIO_F_FILE_CTRL 116
+#define BIO_F_LINEBUFFER_CTRL 129
+#define BIO_F_MEM_READ 128
#define BIO_F_MEM_WRITE 117
#define BIO_F_SSL_NEW 118
#define BIO_F_WSASTARTUP 119
@@ -637,6 +656,7 @@ int BIO_printf(BIO *bio, ...);
#define BIO_R_BAD_HOSTNAME_LOOKUP 102
#define BIO_R_BROKEN_PIPE 124
#define BIO_R_CONNECT_ERROR 103
+#define BIO_R_EOF_ON_MEMORY_BIO 127
#define BIO_R_ERROR_SETTING_NBIO 104
#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET 105
#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET 106
diff --git a/lib/libcrypto/bio/bio_err.c b/lib/libcrypto/bio/bio_err.c
index f38e7b91786..bb815fb1e60 100644
--- a/lib/libcrypto/bio/bio_err.c
+++ b/lib/libcrypto/bio/bio_err.c
@@ -91,6 +91,8 @@ static ERR_STRING_DATA BIO_str_functs[]=
{ERR_PACK(0,BIO_F_CONN_CTRL,0), "CONN_CTRL"},
{ERR_PACK(0,BIO_F_CONN_STATE,0), "CONN_STATE"},
{ERR_PACK(0,BIO_F_FILE_CTRL,0), "FILE_CTRL"},
+{ERR_PACK(0,BIO_F_LINEBUFFER_CTRL,0), "LINEBUFFER_CTRL"},
+{ERR_PACK(0,BIO_F_MEM_READ,0), "MEM_READ"},
{ERR_PACK(0,BIO_F_MEM_WRITE,0), "MEM_WRITE"},
{ERR_PACK(0,BIO_F_SSL_NEW,0), "SSL_new"},
{ERR_PACK(0,BIO_F_WSASTARTUP,0), "WSASTARTUP"},
@@ -104,6 +106,7 @@ static ERR_STRING_DATA BIO_str_reasons[]=
{BIO_R_BAD_HOSTNAME_LOOKUP ,"bad hostname lookup"},
{BIO_R_BROKEN_PIPE ,"broken pipe"},
{BIO_R_CONNECT_ERROR ,"connect error"},
+{BIO_R_EOF_ON_MEMORY_BIO ,"EOF on memory BIO"},
{BIO_R_ERROR_SETTING_NBIO ,"error setting nbio"},
{BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET,"error setting nbio on accepted socket"},
{BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET,"error setting nbio on accept socket"},
@@ -124,8 +127,8 @@ static ERR_STRING_DATA BIO_str_reasons[]=
{BIO_R_UNABLE_TO_LISTEN_SOCKET ,"unable to listen socket"},
{BIO_R_UNINITIALIZED ,"uninitialized"},
{BIO_R_UNSUPPORTED_METHOD ,"unsupported method"},
-{BIO_R_WRITE_TO_READ_ONLY_BIO ,"write to read only bio"},
-{BIO_R_WSASTARTUP ,"wsastartup"},
+{BIO_R_WRITE_TO_READ_ONLY_BIO ,"write to read only BIO"},
+{BIO_R_WSASTARTUP ,"WSAStartup"},
{0,NULL}
};
diff --git a/lib/libcrypto/bio/bio_lib.c b/lib/libcrypto/bio/bio_lib.c
index e88dcc80f3d..381afc9b8e0 100644
--- a/lib/libcrypto/bio/bio_lib.c
+++ b/lib/libcrypto/bio/bio_lib.c
@@ -70,7 +70,7 @@ BIO *BIO_new(BIO_METHOD *method)
{
BIO *ret=NULL;
- ret=(BIO *)Malloc(sizeof(BIO));
+ ret=(BIO *)OPENSSL_malloc(sizeof(BIO));
if (ret == NULL)
{
BIOerr(BIO_F_BIO_NEW,ERR_R_MALLOC_FAILURE);
@@ -78,7 +78,7 @@ BIO *BIO_new(BIO_METHOD *method)
}
if (!BIO_set(ret,method))
{
- Free(ret);
+ OPENSSL_free(ret);
ret=NULL;
}
return(ret);
@@ -133,10 +133,13 @@ int BIO_free(BIO *a)
if ((a->method == NULL) || (a->method->destroy == NULL)) return(1);
ret=a->method->destroy(a);
- Free(a);
+ OPENSSL_free(a);
return(1);
}
+void BIO_vfree(BIO *a)
+ { BIO_free(a); }
+
int BIO_read(BIO *b, void *out, int outl)
{
int i;
@@ -198,13 +201,7 @@ int BIO_write(BIO *b, const void *in, int inl)
if (i > 0) b->num_write+=(unsigned long)i;
- /* This is evil and not thread safe. If the BIO has been freed,
- * we must not call the callback. The only way to be able to
- * determine this is the reference count which is now invalid since
- * the memory has been free()ed.
- */
- if (b->references <= 0) abort();
- if (cb != NULL) /* && (b->references >= 1)) */
+ if (cb != NULL)
i=(int)cb(b,BIO_CB_WRITE|BIO_CB_RETURN,in,inl,
0L,(long)i);
return(i);
@@ -235,6 +232,8 @@ int BIO_puts(BIO *b, const char *in)
i=b->method->bputs(b,in);
+ if (i > 0) b->num_write+=(unsigned long)i;
+
if (cb != NULL)
i=(int)cb(b,BIO_CB_PUTS|BIO_CB_RETURN,in,0,
0L,(long)i);
@@ -317,7 +316,7 @@ long BIO_ctrl(BIO *b, int cmd, long larg, void *parg)
return(ret);
}
-long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)())
+long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long))
{
long ret;
long (*cb)();
@@ -419,6 +418,7 @@ BIO *BIO_find_type(BIO *bio, int type)
{
int mt,mask;
+ if(!bio) return NULL;
mask=type&0xff;
do {
if (bio->method != NULL)
@@ -437,6 +437,12 @@ BIO *BIO_find_type(BIO *bio, int type)
return(NULL);
}
+BIO *BIO_next(BIO *b)
+ {
+ if(!b) return NULL;
+ return b->next_bio;
+ }
+
void BIO_free_all(BIO *bio)
{
BIO *b;
@@ -532,3 +538,5 @@ unsigned long BIO_number_written(BIO *bio)
if(bio) return bio->num_write;
return 0;
}
+
+IMPLEMENT_STACK_OF(BIO)
diff --git a/lib/libcrypto/bio/bss_acpt.c b/lib/libcrypto/bio/bss_acpt.c
index 9afa6364069..4da5822062c 100644
--- a/lib/libcrypto/bio/bss_acpt.c
+++ b/lib/libcrypto/bio/bss_acpt.c
@@ -92,10 +92,10 @@ typedef struct bio_accept_st
BIO *bio_chain;
} BIO_ACCEPT;
-static int acpt_write(BIO *h,char *buf,int num);
-static int acpt_read(BIO *h,char *buf,int size);
-static int acpt_puts(BIO *h,char *str);
-static long acpt_ctrl(BIO *h,int cmd,long arg1,char *arg2);
+static int acpt_write(BIO *h, const char *buf, int num);
+static int acpt_read(BIO *h, char *buf, int size);
+static int acpt_puts(BIO *h, const char *str);
+static long acpt_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int acpt_new(BIO *h);
static int acpt_free(BIO *data);
static int acpt_state(BIO *b, BIO_ACCEPT *c);
@@ -145,7 +145,7 @@ BIO_ACCEPT *BIO_ACCEPT_new(void)
{
BIO_ACCEPT *ret;
- if ((ret=(BIO_ACCEPT *)Malloc(sizeof(BIO_ACCEPT))) == NULL)
+ if ((ret=(BIO_ACCEPT *)OPENSSL_malloc(sizeof(BIO_ACCEPT))) == NULL)
return(NULL);
memset(ret,0,sizeof(BIO_ACCEPT));
@@ -159,10 +159,10 @@ void BIO_ACCEPT_free(BIO_ACCEPT *a)
if(a == NULL)
return;
- if (a->param_addr != NULL) Free(a->param_addr);
- if (a->addr != NULL) Free(a->addr);
+ if (a->param_addr != NULL) OPENSSL_free(a->param_addr);
+ if (a->addr != NULL) OPENSSL_free(a->addr);
if (a->bio_chain != NULL) BIO_free(a->bio_chain);
- Free(a);
+ OPENSSL_free(a);
}
static void acpt_close_socket(BIO *bio)
@@ -307,7 +307,7 @@ static int acpt_read(BIO *b, char *out, int outl)
return(ret);
}
-static int acpt_write(BIO *b, char *in, int inl)
+static int acpt_write(BIO *b, const char *in, int inl)
{
int ret;
BIO_ACCEPT *data;
@@ -326,7 +326,7 @@ static int acpt_write(BIO *b, char *in, int inl)
return(ret);
}
-static long acpt_ctrl(BIO *b, int cmd, long num, char *ptr)
+static long acpt_ctrl(BIO *b, int cmd, long num, void *ptr)
{
BIO *dbio;
int *ip;
@@ -355,7 +355,7 @@ static long acpt_ctrl(BIO *b, int cmd, long num, char *ptr)
{
b->init=1;
if (data->param_addr != NULL)
- Free(data->param_addr);
+ OPENSSL_free(data->param_addr);
data->param_addr=BUF_strdup(ptr);
}
else if (num == 1)
@@ -440,7 +440,7 @@ static long acpt_ctrl(BIO *b, int cmd, long num, char *ptr)
return(ret);
}
-static int acpt_puts(BIO *bp, char *str)
+static int acpt_puts(BIO *bp, const char *str)
{
int n,ret;
diff --git a/lib/libcrypto/bio/bss_bio.c b/lib/libcrypto/bio/bss_bio.c
index 1e2d7491f2c..78c6ab4fdd9 100644
--- a/lib/libcrypto/bio/bss_bio.c
+++ b/lib/libcrypto/bio/bss_bio.c
@@ -30,9 +30,9 @@
static int bio_new(BIO *bio);
static int bio_free(BIO *bio);
static int bio_read(BIO *bio, char *buf, int size);
-static int bio_write(BIO *bio, char *buf, int num);
+static int bio_write(BIO *bio, const char *buf, int num);
static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr);
-static int bio_puts(BIO *bio, char *str);
+static int bio_puts(BIO *bio, const char *str);
static int bio_make_pair(BIO *bio1, BIO *bio2);
static void bio_destroy_pair(BIO *bio);
@@ -80,7 +80,7 @@ static int bio_new(BIO *bio)
{
struct bio_bio_st *b;
- b = Malloc(sizeof *b);
+ b = OPENSSL_malloc(sizeof *b);
if (b == NULL)
return 0;
@@ -108,10 +108,10 @@ static int bio_free(BIO *bio)
if (b->buf != NULL)
{
- Free(b->buf);
+ OPENSSL_free(b->buf);
}
- Free(b);
+ OPENSSL_free(b);
return 1;
}
@@ -283,7 +283,7 @@ static ssize_t bio_nread(BIO *bio, char **buf, size_t num_)
}
-static int bio_write(BIO *bio, char *buf, int num_)
+static int bio_write(BIO *bio, const char *buf, int num_)
{
size_t num = num_;
size_t rest;
@@ -464,7 +464,7 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr)
{
if (b->buf)
{
- Free(b->buf);
+ OPENSSL_free(b->buf);
b->buf = NULL;
}
b->size = new_size;
@@ -628,7 +628,7 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr)
return ret;
}
-static int bio_puts(BIO *bio, char *str)
+static int bio_puts(BIO *bio, const char *str)
{
return bio_write(bio, str, strlen(str));
}
@@ -652,7 +652,7 @@ static int bio_make_pair(BIO *bio1, BIO *bio2)
if (b1->buf == NULL)
{
- b1->buf = Malloc(b1->size);
+ b1->buf = OPENSSL_malloc(b1->size);
if (b1->buf == NULL)
{
BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE);
@@ -664,7 +664,7 @@ static int bio_make_pair(BIO *bio1, BIO *bio2)
if (b2->buf == NULL)
{
- b2->buf = Malloc(b2->size);
+ b2->buf = OPENSSL_malloc(b2->size);
if (b2->buf == NULL)
{
BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE);
diff --git a/lib/libcrypto/bio/bss_conn.c b/lib/libcrypto/bio/bss_conn.c
index 22d00b369ec..a6b77a2cb9b 100644
--- a/lib/libcrypto/bio/bss_conn.c
+++ b/lib/libcrypto/bio/bss_conn.c
@@ -98,13 +98,13 @@ typedef struct bio_connect_st
int (*info_callback)();
} BIO_CONNECT;
-static int conn_write(BIO *h,char *buf,int num);
-static int conn_read(BIO *h,char *buf,int size);
-static int conn_puts(BIO *h,char *str);
-static long conn_ctrl(BIO *h,int cmd,long arg1,char *arg2);
+static int conn_write(BIO *h, const char *buf, int num);
+static int conn_read(BIO *h, char *buf, int size);
+static int conn_puts(BIO *h, const char *str);
+static long conn_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int conn_new(BIO *h);
static int conn_free(BIO *data);
-static long conn_callback_ctrl(BIO *h,int cmd,void *(*fp)());
+static long conn_callback_ctrl(BIO *h, int cmd, bio_info_cb *);
static int conn_state(BIO *b, BIO_CONNECT *c);
static void conn_close_socket(BIO *data);
@@ -165,7 +165,7 @@ static int conn_state(BIO *b, BIO_CONNECT *c)
break;
}
if (c->param_port != NULL)
- Free(c->param_port);
+ OPENSSL_free(c->param_port);
c->param_port=BUF_strdup(p);
}
}
@@ -188,7 +188,7 @@ static int conn_state(BIO *b, BIO_CONNECT *c)
case BIO_CONN_S_GET_PORT:
if (c->param_port == NULL)
{
- abort();
+ /* abort(); */
goto exit_loop;
}
else if (BIO_get_port(c->param_port,&c->port) <= 0)
@@ -236,7 +236,7 @@ static int conn_state(BIO *b, BIO_CONNECT *c)
}
c->state=BIO_CONN_S_CONNECT;
-#ifdef SO_KEEPALIVE
+#if defined(SO_KEEPALIVE) && !defined(MPE)
i=1;
i=setsockopt(b->num,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i));
if (i < 0)
@@ -299,7 +299,7 @@ static int conn_state(BIO *b, BIO_CONNECT *c)
ret=1;
goto exit_loop;
default:
- abort();
+ /* abort(); */
goto exit_loop;
}
@@ -322,7 +322,7 @@ BIO_CONNECT *BIO_CONNECT_new(void)
{
BIO_CONNECT *ret;
- if ((ret=(BIO_CONNECT *)Malloc(sizeof(BIO_CONNECT))) == NULL)
+ if ((ret=(BIO_CONNECT *)OPENSSL_malloc(sizeof(BIO_CONNECT))) == NULL)
return(NULL);
ret->state=BIO_CONN_S_BEFORE;
ret->param_hostname=NULL;
@@ -344,10 +344,10 @@ void BIO_CONNECT_free(BIO_CONNECT *a)
return;
if (a->param_hostname != NULL)
- Free(a->param_hostname);
+ OPENSSL_free(a->param_hostname);
if (a->param_port != NULL)
- Free(a->param_port);
- Free(a);
+ OPENSSL_free(a->param_port);
+ OPENSSL_free(a);
}
BIO_METHOD *BIO_s_connect(void)
@@ -426,7 +426,7 @@ static int conn_read(BIO *b, char *out, int outl)
return(ret);
}
-static int conn_write(BIO *b, char *in, int inl)
+static int conn_write(BIO *b, const char *in, int inl)
{
int ret;
BIO_CONNECT *data;
@@ -449,7 +449,7 @@ static int conn_write(BIO *b, char *in, int inl)
return(ret);
}
-static long conn_ctrl(BIO *b, int cmd, long num, char *ptr)
+static long conn_ctrl(BIO *b, int cmd, long num, void *ptr)
{
BIO *dbio;
int *ip;
@@ -507,23 +507,24 @@ static long conn_ctrl(BIO *b, int cmd, long num, char *ptr)
if (num == 0)
{
if (data->param_hostname != NULL)
- Free(data->param_hostname);
+ OPENSSL_free(data->param_hostname);
data->param_hostname=BUF_strdup(ptr);
}
else if (num == 1)
{
if (data->param_port != NULL)
- Free(data->param_port);
+ OPENSSL_free(data->param_port);
data->param_port=BUF_strdup(ptr);
}
else if (num == 2)
{
char buf[16];
+ char *p = ptr;
sprintf(buf,"%d.%d.%d.%d",
- ptr[0],ptr[1],ptr[2],ptr[3]);
+ p[0],p[1],p[2],p[3]);
if (data->param_hostname != NULL)
- Free(data->param_hostname);
+ OPENSSL_free(data->param_hostname);
data->param_hostname=BUF_strdup(buf);
memcpy(&(data->ip[0]),ptr,4);
}
@@ -533,7 +534,7 @@ static long conn_ctrl(BIO *b, int cmd, long num, char *ptr)
sprintf(buf,"%d",*(int *)ptr);
if (data->param_port != NULL)
- Free(data->param_port);
+ OPENSSL_free(data->param_port);
data->param_port=BUF_strdup(buf);
data->port= *(int *)ptr;
}
@@ -573,7 +574,7 @@ static long conn_ctrl(BIO *b, int cmd, long num, char *ptr)
if (data->param_hostname)
BIO_set_conn_hostname(dbio,data->param_hostname);
BIO_set_nbio(dbio,data->nbio);
- (void)BIO_set_info_callback(dbio,(void *(*)())(data->info_callback));
+ (void)BIO_set_info_callback(dbio,data->info_callback);
}
break;
case BIO_CTRL_SET_CALLBACK:
@@ -601,7 +602,7 @@ static long conn_ctrl(BIO *b, int cmd, long num, char *ptr)
return(ret);
}
-static long conn_callback_ctrl(BIO *b, int cmd, void *(*fp)())
+static long conn_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
{
long ret=1;
BIO_CONNECT *data;
@@ -622,7 +623,7 @@ static long conn_callback_ctrl(BIO *b, int cmd, void *(*fp)())
return(ret);
}
-static int conn_puts(BIO *bp, char *str)
+static int conn_puts(BIO *bp, const char *str)
{
int n,ret;
diff --git a/lib/libcrypto/bio/bss_file.c b/lib/libcrypto/bio/bss_file.c
index 0d44dc38896..1f770b390f8 100644
--- a/lib/libcrypto/bio/bss_file.c
+++ b/lib/libcrypto/bio/bss_file.c
@@ -73,11 +73,11 @@
#if !defined(NO_STDIO)
-static int MS_CALLBACK file_write(BIO *h,char *buf,int num);
-static int MS_CALLBACK file_read(BIO *h,char *buf,int size);
-static int MS_CALLBACK file_puts(BIO *h,char *str);
-static int MS_CALLBACK file_gets(BIO *h,char *str,int size);
-static long MS_CALLBACK file_ctrl(BIO *h,int cmd,long arg1,char *arg2);
+static int MS_CALLBACK file_write(BIO *h, const char *buf, int num);
+static int MS_CALLBACK file_read(BIO *h, char *buf, int size);
+static int MS_CALLBACK file_puts(BIO *h, const char *str);
+static int MS_CALLBACK file_gets(BIO *h, char *str, int size);
+static long MS_CALLBACK file_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int MS_CALLBACK file_new(BIO *h);
static int MS_CALLBACK file_free(BIO *data);
static BIO_METHOD methods_filep=
@@ -163,7 +163,7 @@ static int MS_CALLBACK file_read(BIO *b, char *out, int outl)
return(ret);
}
-static int MS_CALLBACK file_write(BIO *b, char *in, int inl)
+static int MS_CALLBACK file_write(BIO *b, const char *in, int inl)
{
int ret=0;
@@ -179,7 +179,7 @@ static int MS_CALLBACK file_write(BIO *b, char *in, int inl)
return(ret);
}
-static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, char *ptr)
+static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr)
{
long ret=1;
FILE *fp=(FILE *)b->ptr;
@@ -294,7 +294,7 @@ static int MS_CALLBACK file_gets(BIO *bp, char *buf, int size)
return(ret);
}
-static int MS_CALLBACK file_puts(BIO *bp, char *str)
+static int MS_CALLBACK file_puts(BIO *bp, const char *str)
{
int n,ret;
diff --git a/lib/libcrypto/bio/bss_log.c b/lib/libcrypto/bio/bss_log.c
index 497eb1af72b..1edf16a76fd 100644
--- a/lib/libcrypto/bio/bss_log.c
+++ b/lib/libcrypto/bio/bss_log.c
@@ -110,14 +110,26 @@
#define LOG_DAEMON OPC$M_NM_NTWORK
#endif
-static int MS_CALLBACK slg_write(BIO *h,char *buf,int num);
-static int MS_CALLBACK slg_puts(BIO *h,char *str);
-static long MS_CALLBACK slg_ctrl(BIO *h,int cmd,long arg1,char *arg2);
+static int MS_CALLBACK slg_write(BIO *h, const char *buf, int num);
+static int MS_CALLBACK slg_puts(BIO *h, const char *str);
+static long MS_CALLBACK slg_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int MS_CALLBACK slg_new(BIO *h);
static int MS_CALLBACK slg_free(BIO *data);
-static void xopenlog(BIO* bp, const char* name, int level);
+static void xopenlog(BIO* bp, char* name, int level);
static void xsyslog(BIO* bp, int priority, const char* string);
static void xcloselog(BIO* bp);
+#ifdef WIN32
+LONG (WINAPI *go_for_advapi)() = RegOpenKeyEx;
+HANDLE (WINAPI *register_event_source)() = NULL;
+BOOL (WINAPI *deregister_event_source)() = NULL;
+BOOL (WINAPI *report_event)() = NULL;
+#define DL_PROC(m,f) (GetProcAddress( m, f ))
+#ifdef UNICODE
+#define DL_PROC_X(m,f) DL_PROC( m, f "W" )
+#else
+#define DL_PROC_X(m,f) DL_PROC( m, f "A" )
+#endif
+#endif
static BIO_METHOD methods_slg=
{
@@ -153,40 +165,60 @@ static int MS_CALLBACK slg_free(BIO *a)
return(1);
}
-static int MS_CALLBACK slg_write(BIO *b, char *in, int inl)
+static int MS_CALLBACK slg_write(BIO *b, const char *in, int inl)
{
int ret= inl;
- char* buf= in;
+ char* buf;
char* pp;
- int priority;
-
- if((buf= (char *)Malloc(inl+ 1)) == NULL){
+ int priority, i;
+ static struct
+ {
+ int strl;
+ char str[10];
+ int log_level;
+ }
+ mapping[] =
+ {
+ { 6, "PANIC ", LOG_EMERG },
+ { 6, "EMERG ", LOG_EMERG },
+ { 4, "EMR ", LOG_EMERG },
+ { 6, "ALERT ", LOG_ALERT },
+ { 4, "ALR ", LOG_ALERT },
+ { 5, "CRIT ", LOG_CRIT },
+ { 4, "CRI ", LOG_CRIT },
+ { 6, "ERROR ", LOG_ERR },
+ { 4, "ERR ", LOG_ERR },
+ { 8, "WARNING ", LOG_WARNING },
+ { 5, "WARN ", LOG_WARNING },
+ { 4, "WAR ", LOG_WARNING },
+ { 7, "NOTICE ", LOG_NOTICE },
+ { 5, "NOTE ", LOG_NOTICE },
+ { 4, "NOT ", LOG_NOTICE },
+ { 5, "INFO ", LOG_INFO },
+ { 4, "INF ", LOG_INFO },
+ { 6, "DEBUG ", LOG_DEBUG },
+ { 4, "DBG ", LOG_DEBUG },
+ { 0, "", LOG_ERR } /* The default */
+ };
+
+ if((buf= (char *)OPENSSL_malloc(inl+ 1)) == NULL){
return(0);
}
strncpy(buf, in, inl);
buf[inl]= '\0';
- if(strncmp(buf, "ERR ", 4) == 0){
- priority= LOG_ERR;
- pp= buf+ 4;
- }else if(strncmp(buf, "WAR ", 4) == 0){
- priority= LOG_WARNING;
- pp= buf+ 4;
- }else if(strncmp(buf, "INF ", 4) == 0){
- priority= LOG_INFO;
- pp= buf+ 4;
- }else{
- priority= LOG_ERR;
- pp= buf;
- }
+ i = 0;
+ while(strncmp(buf, mapping[i].str, mapping[i].strl) != 0) i++;
+ priority = mapping[i].log_level;
+ pp = buf + mapping[i].strl;
xsyslog(b, priority, pp);
- Free(buf);
+ OPENSSL_free(buf);
return(ret);
}
-static long MS_CALLBACK slg_ctrl(BIO *b, int cmd, long num, char *ptr)
+static long MS_CALLBACK slg_ctrl(BIO *b, int cmd, long num, void *ptr)
{
switch (cmd)
{
@@ -200,7 +232,7 @@ static long MS_CALLBACK slg_ctrl(BIO *b, int cmd, long num, char *ptr)
return(0);
}
-static int MS_CALLBACK slg_puts(BIO *bp, char *str)
+static int MS_CALLBACK slg_puts(BIO *bp, const char *str)
{
int n,ret;
@@ -211,9 +243,29 @@ static int MS_CALLBACK slg_puts(BIO *bp, char *str)
#if defined(WIN32)
-static void xopenlog(BIO* bp, const char* name, int level)
+static void xopenlog(BIO* bp, char* name, int level)
{
- bp->ptr= (char *)RegisterEventSource(NULL, name);
+ if ( !register_event_source )
+ {
+ HANDLE advapi;
+ if ( !(advapi = GetModuleHandle("advapi32")) )
+ return;
+ register_event_source = (HANDLE (WINAPI *)())DL_PROC_X(advapi,
+ "RegisterEventSource" );
+ deregister_event_source = (BOOL (WINAPI *)())DL_PROC(advapi,
+ "DeregisterEventSource");
+ report_event = (BOOL (WINAPI *)())DL_PROC_X(advapi,
+ "ReportEvent" );
+ if ( !(register_event_source && deregister_event_source &&
+ report_event) )
+ {
+ register_event_source = NULL;
+ deregister_event_source = NULL;
+ report_event = NULL;
+ return;
+ }
+ }
+ bp->ptr= (char *)register_event_source(NULL, name);
}
static void xsyslog(BIO *bp, int priority, const char *string)
@@ -225,16 +277,22 @@ static void xsyslog(BIO *bp, int priority, const char *string)
switch (priority)
{
+ case LOG_EMERG:
+ case LOG_ALERT:
+ case LOG_CRIT:
case LOG_ERR:
evtype = EVENTLOG_ERROR_TYPE;
break;
case LOG_WARNING:
evtype = EVENTLOG_WARNING_TYPE;
break;
+ case LOG_NOTICE:
case LOG_INFO:
+ case LOG_DEBUG:
evtype = EVENTLOG_INFORMATION_TYPE;
break;
- default:
+ default: /* Should never happen, but set it
+ as error anyway. */
evtype = EVENTLOG_ERROR_TYPE;
break;
}
@@ -243,15 +301,15 @@ static void xsyslog(BIO *bp, int priority, const char *string)
lpszStrings[0] = pidbuf;
lpszStrings[1] = string;
- if(bp->ptr)
- ReportEvent(bp->ptr, evtype, 0, 1024, NULL, 2, 0,
+ if(report_event && bp->ptr)
+ report_event(bp->ptr, evtype, 0, 1024, NULL, 2, 0,
lpszStrings, NULL);
}
static void xcloselog(BIO* bp)
{
- if(bp->ptr)
- DeregisterEventSource((HANDLE)(bp->ptr));
+ if(deregister_event_source && bp->ptr)
+ deregister_event_source((HANDLE)(bp->ptr));
bp->ptr= NULL;
}
@@ -259,7 +317,7 @@ static void xcloselog(BIO* bp)
static int VMS_OPC_target = LOG_DAEMON;
-static void xopenlog(BIO* bp, const char* name, int level)
+static void xopenlog(BIO* bp, char* name, int level)
{
VMS_OPC_target = level;
}
@@ -294,7 +352,7 @@ static void xsyslog(BIO *bp, int priority, const char *string)
lib$sys_fao(&fao_cmd, &len, &buf_dsc, priority_tag, string);
/* we know there's an 8 byte header. That's documented */
- opcdef_p = (struct opcdef *) Malloc(8 + len);
+ opcdef_p = (struct opcdef *) OPENSSL_malloc(8 + len);
opcdef_p->opc$b_ms_type = OPC$_RQ_RQST;
memcpy(opcdef_p->opc$z_ms_target_classes, &VMS_OPC_target, 3);
opcdef_p->opc$l_ms_rqstid = 0;
@@ -307,7 +365,7 @@ static void xsyslog(BIO *bp, int priority, const char *string)
sys$sndopr(opc_dsc, 0);
- Free(opcdef_p);
+ OPENSSL_free(opcdef_p);
}
static void xcloselog(BIO* bp)
@@ -316,7 +374,7 @@ static void xcloselog(BIO* bp)
#else /* Unix */
-static void xopenlog(BIO* bp, const char* name, int level)
+static void xopenlog(BIO* bp, char* name, int level)
{
openlog(name, LOG_PID|LOG_CONS, level);
}
diff --git a/lib/libcrypto/bio/bss_mem.c b/lib/libcrypto/bio/bss_mem.c
index 41eab92415e..28ff7582bff 100644
--- a/lib/libcrypto/bio/bss_mem.c
+++ b/lib/libcrypto/bio/bss_mem.c
@@ -61,11 +61,11 @@
#include "cryptlib.h"
#include <openssl/bio.h>
-static int mem_write(BIO *h,char *buf,int num);
-static int mem_read(BIO *h,char *buf,int size);
-static int mem_puts(BIO *h,char *str);
-static int mem_gets(BIO *h,char *str,int size);
-static long mem_ctrl(BIO *h,int cmd,long arg1,char *arg2);
+static int mem_write(BIO *h, const char *buf, int num);
+static int mem_read(BIO *h, char *buf, int size);
+static int mem_puts(BIO *h, const char *str);
+static int mem_gets(BIO *h, char *str, int size);
+static long mem_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int mem_new(BIO *h);
static int mem_free(BIO *data);
static BIO_METHOD mem_method=
@@ -163,14 +163,14 @@ static int mem_read(BIO *b, char *out, int outl)
}
} else if (bm->length == 0)
{
- if (b->num != 0)
+ ret = b->num;
+ if (ret != 0)
BIO_set_retry_read(b);
- ret= b->num;
}
return(ret);
}
-static int mem_write(BIO *b, char *in, int inl)
+static int mem_write(BIO *b, const char *in, int inl)
{
int ret= -1;
int blen;
@@ -198,7 +198,7 @@ end:
return(ret);
}
-static long mem_ctrl(BIO *b, int cmd, long num, char *ptr)
+static long mem_ctrl(BIO *b, int cmd, long num, void *ptr)
{
long ret=1;
char **pptr;
@@ -208,15 +208,20 @@ static long mem_ctrl(BIO *b, int cmd, long num, char *ptr)
switch (cmd)
{
case BIO_CTRL_RESET:
- if (bm->data != NULL) {
+ if (bm->data != NULL)
+ {
/* For read only case reset to the start again */
if(b->flags & BIO_FLAGS_MEM_RDONLY)
- bm->data -= bm->max - bm->length;
- else {
+ {
+ bm->data -= bm->max - bm->length;
+ bm->length = bm->max;
+ }
+ else
+ {
memset(bm->data,0,bm->max);
bm->length=0;
+ }
}
- }
break;
case BIO_CTRL_EOF:
ret=(long)(bm->length == 0);
@@ -300,7 +305,7 @@ static int mem_gets(BIO *bp, char *buf, int size)
return(ret);
}
-static int mem_puts(BIO *bp, char *str)
+static int mem_puts(BIO *bp, const char *str)
{
int n,ret;
diff --git a/lib/libcrypto/bio/bss_null.c b/lib/libcrypto/bio/bss_null.c
index aee18e3ada4..46b73339dff 100644
--- a/lib/libcrypto/bio/bss_null.c
+++ b/lib/libcrypto/bio/bss_null.c
@@ -61,11 +61,11 @@
#include "cryptlib.h"
#include <openssl/bio.h>
-static int null_write(BIO *h,char *buf,int num);
-static int null_read(BIO *h,char *buf,int size);
-static int null_puts(BIO *h,char *str);
-static int null_gets(BIO *h,char *str,int size);
-static long null_ctrl(BIO *h,int cmd,long arg1,char *arg2);
+static int null_write(BIO *h, const char *buf, int num);
+static int null_read(BIO *h, char *buf, int size);
+static int null_puts(BIO *h, const char *str);
+static int null_gets(BIO *h, char *str, int size);
+static long null_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int null_new(BIO *h);
static int null_free(BIO *data);
static BIO_METHOD null_method=
@@ -106,12 +106,12 @@ static int null_read(BIO *b, char *out, int outl)
return(0);
}
-static int null_write(BIO *b, char *in, int inl)
+static int null_write(BIO *b, const char *in, int inl)
{
return(inl);
}
-static long null_ctrl(BIO *b, int cmd, long num, char *ptr)
+static long null_ctrl(BIO *b, int cmd, long num, void *ptr)
{
long ret=1;
@@ -142,7 +142,7 @@ static int null_gets(BIO *bp, char *buf, int size)
return(0);
}
-static int null_puts(BIO *bp, char *str)
+static int null_puts(BIO *bp, const char *str)
{
if (str == NULL) return(0);
return(strlen(str));
diff --git a/lib/libcrypto/bio/bss_rtcp.c b/lib/libcrypto/bio/bss_rtcp.c
index 4ad0739464b..7dae4855640 100644
--- a/lib/libcrypto/bio/bss_rtcp.c
+++ b/lib/libcrypto/bio/bss_rtcp.c
@@ -88,11 +88,11 @@ struct rpc_ctx {
struct rpc_msg msg;
};
-static int rtcp_write(BIO *h,char *buf,int num);
+static int rtcp_write(BIO *h,const char *buf,int num);
static int rtcp_read(BIO *h,char *buf,int size);
-static int rtcp_puts(BIO *h,char *str);
+static int rtcp_puts(BIO *h,const char *str);
static int rtcp_gets(BIO *h,char *str,int size);
-static long rtcp_ctrl(BIO *h,int cmd,long arg1,char *arg2);
+static long rtcp_ctrl(BIO *h,int cmd,long arg1,void *arg2);
static int rtcp_new(BIO *h);
static int rtcp_free(BIO *data);
@@ -156,7 +156,7 @@ static int rtcp_new(BIO *bi)
bi->init=1;
bi->num=0;
bi->flags = 0;
- bi->ptr=Malloc(sizeof(struct rpc_ctx));
+ bi->ptr=OPENSSL_malloc(sizeof(struct rpc_ctx));
ctx = (struct rpc_ctx *) bi->ptr;
ctx->filled = 0;
ctx->pos = 0;
@@ -166,7 +166,7 @@ static int rtcp_new(BIO *bi)
static int rtcp_free(BIO *a)
{
if (a == NULL) return(0);
- if ( a->ptr ) Free ( a->ptr );
+ if ( a->ptr ) OPENSSL_free ( a->ptr );
a->ptr = NULL;
return(1);
}
@@ -218,7 +218,7 @@ static int rtcp_read(BIO *b, char *out, int outl)
return length;
}
-static int rtcp_write(BIO *b, char *in, int inl)
+static int rtcp_write(BIO *b, const char *in, int inl)
{
int status, i, segment, length;
struct rpc_ctx *ctx;
@@ -247,7 +247,7 @@ static int rtcp_write(BIO *b, char *in, int inl)
return(i);
}
-static long rtcp_ctrl(BIO *b, int cmd, long num, char *ptr)
+static long rtcp_ctrl(BIO *b, int cmd, long num, void *ptr)
{
long ret=1;
@@ -283,7 +283,7 @@ static int rtcp_gets(BIO *bp, char *buf, int size)
return(0);
}
-static int rtcp_puts(BIO *bp, char *str)
+static int rtcp_puts(BIO *bp, const char *str)
{
int length;
if (str == NULL) return(0);
diff --git a/lib/libcrypto/bio/bss_sock.c b/lib/libcrypto/bio/bss_sock.c
index 8ce80ef68d2..50c6744c060 100644
--- a/lib/libcrypto/bio/bss_sock.c
+++ b/lib/libcrypto/bio/bss_sock.c
@@ -65,19 +65,19 @@
#include <openssl/bio.h>
#ifndef BIO_FD
-static int sock_write(BIO *h,char *buf,int num);
-static int sock_read(BIO *h,char *buf,int size);
-static int sock_puts(BIO *h,char *str);
-static long sock_ctrl(BIO *h,int cmd,long arg1,char *arg2);
+static int sock_write(BIO *h, const char *buf, int num);
+static int sock_read(BIO *h, char *buf, int size);
+static int sock_puts(BIO *h, const char *str);
+static long sock_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int sock_new(BIO *h);
static int sock_free(BIO *data);
int BIO_sock_should_retry(int s);
#else
-static int fd_write(BIO *h,char *buf,int num);
-static int fd_read(BIO *h,char *buf,int size);
-static int fd_puts(BIO *h,char *str);
-static long fd_ctrl(BIO *h,int cmd,long arg1,char *arg2);
+static int fd_write(BIO *h, const char *buf, int num);
+static int fd_read(BIO *h, char *buf, int size);
+static int fd_puts(BIO *h, const char *str);
+static long fd_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int fd_new(BIO *h);
static int fd_free(BIO *data);
int BIO_fd_should_retry(int s);
@@ -209,9 +209,9 @@ static int fd_read(BIO *b, char *out,int outl)
}
#ifndef BIO_FD
-static int sock_write(BIO *b, char *in, int inl)
+static int sock_write(BIO *b, const char *in, int inl)
#else
-static int fd_write(BIO *b, char *in, int inl)
+static int fd_write(BIO *b, const char *in, int inl)
#endif
{
int ret;
@@ -237,9 +237,9 @@ static int fd_write(BIO *b, char *in, int inl)
}
#ifndef BIO_FD
-static long sock_ctrl(BIO *b, int cmd, long num, char *ptr)
+static long sock_ctrl(BIO *b, int cmd, long num, void *ptr)
#else
-static long fd_ctrl(BIO *b, int cmd, long num, char *ptr)
+static long fd_ctrl(BIO *b, int cmd, long num, void *ptr)
#endif
{
long ret=1;
@@ -313,9 +313,9 @@ static int sock_gets(BIO *bp, char *buf,int size)
#endif
#ifndef BIO_FD
-static int sock_puts(BIO *bp, char *str)
+static int sock_puts(BIO *bp, const char *str)
#else
-static int fd_puts(BIO *bp, char *str)
+static int fd_puts(BIO *bp, const char *str)
#endif
{
int n,ret;