BIO_TYPE_ASN1,
"asn1",
asn1_bio_write,
+ /* TODO: Convert to new style read function */
+ bread_conv,
asn1_bio_read,
asn1_bio_puts,
asn1_bio_gets,
BIO_TYPE_BUFFER,
"buffer",
buffer_write,
+ /* TODO: Convert to new style read function */
+ bread_conv,
buffer_read,
buffer_puts,
buffer_gets,
BIO_TYPE_LINEBUFFER,
"linebuffer",
linebuffer_write,
+ /* TODO: Convert to new style read function */
+ bread_conv,
linebuffer_read,
linebuffer_puts,
linebuffer_gets,
BIO_TYPE_NBIO_TEST,
"non-blocking IO test filter",
nbiof_write,
+ /* TODO: Convert to new style read function */
+ bread_conv,
nbiof_read,
nbiof_puts,
nbiof_gets,
BIO_TYPE_NULL_FILTER,
"NULL filter",
nullf_write,
+ /* TODO: Convert to new style read function */
+ bread_conv,
nullf_read,
nullf_puts,
nullf_gets,
{ERR_FUNC(BIO_F_BIO_PARSE_HOSTSERV), "BIO_parse_hostserv"},
{ERR_FUNC(BIO_F_BIO_PUTS), "BIO_puts"},
{ERR_FUNC(BIO_F_BIO_READ), "BIO_read"},
+ {ERR_FUNC(BIO_F_BIO_READ_EX), "BIO_read_ex"},
{ERR_FUNC(BIO_F_BIO_SOCKET), "BIO_socket"},
{ERR_FUNC(BIO_F_BIO_SOCKET_NBIO), "BIO_socket_nbio"},
{ERR_FUNC(BIO_F_BIO_SOCK_INFO), "BIO_sock_info"},
struct bio_st {
const BIO_METHOD *method;
/* bio, mode, argp, argi, argl, ret */
- long (*callback) (struct bio_st *, int, const char *, int, long, long);
+ BIO_callback_fn callback;
+ BIO_callback_fn_ex callback_ex;
char *cb_arg; /* first argument for the callback */
int init;
int shutdown;
b->flags |= flags;
}
-long (*BIO_get_callback(const BIO *b)) (struct bio_st *, int, const char *,
- int, long, long) {
+BIO_callback_fn BIO_get_callback(const BIO *b)
+{
return b->callback;
}
-void BIO_set_callback(BIO *b,
- long (*cb) (struct bio_st *, int, const char *, int,
- long, long))
+void BIO_set_callback(BIO *b, BIO_callback_fn cb)
{
b->callback = cb;
}
+BIO_callback_fn_ex BIO_get_callback_ex(const BIO *b)
+{
+ return b->callback_ex;
+}
+
+void BIO_set_callback_ex(BIO *b, BIO_callback_fn_ex cb)
+{
+ b->callback_ex = cb;
+}
+
void BIO_set_callback_arg(BIO *b, char *arg)
{
b->cb_arg = arg;
return b->method->type;
}
+static int bio_call_callback(BIO *b, int oper, const char *argp, size_t len,
+ int argi, long argl, int inret, size_t *processed,
+ long *lret)
+{
+ long ret;
+ int bareoper;
+
+ if (b->callback_ex != NULL) {
+ return b->callback_ex(b, oper, argp, len, argi, argl, inret, processed,
+ lret);
+ }
+
+ /* Strip off the BIO_CB_RETURN flag */
+ bareoper = oper & ~BIO_CB_RETURN;
+ /*
+ * We have an old style callback, so we will have to do nasty casts and
+ * check for overflows.
+ */
+ if (bareoper == BIO_CB_READ || bareoper == BIO_CB_WRITE
+ || bareoper == BIO_CB_GETS) {
+ /* In this case |len| is set, and should be used instead of |argi| */
+ if (len > INT_MAX)
+ return 0;
+
+ argi = (int)len;
+
+ if (inret && (oper & BIO_CB_RETURN)) {
+ if (*processed > INT_MAX)
+ return 0;
+ inret = *processed;
+ }
+ }
+
+ ret = b->callback(b, oper, argp, argi, argl, inret);
+ if (bareoper == BIO_CB_CTRL)
+ return 1;
+
+ if (ret > INT_MAX || ret < INT_MIN)
+ return 0;
+
+ if (lret != NULL)
+ *lret = ret;
+
+ if (ret >= 0) {
+ *processed = (size_t)ret;
+ ret = 1;
+ }
+
+ return (int)ret;
+}
+
int BIO_read(BIO *b, void *out, int outl)
{
- int i;
- long (*cb) (BIO *, int, const char *, int, long, long);
+ size_t read;
+ int ret;
+
+ if (outl < 0)
+ return 0;
+
+ ret = BIO_read_ex(b, out, (size_t)outl, &read);
+
+ if (ret > 0) {
+ /* *read should always be <= outl */
+ ret = (int)read;
+ }
+
+ return ret;
+}
+
+int BIO_read_ex(BIO *b, void *out, size_t outl, size_t *read)
+{
+ int ret;
if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL)) {
- BIOerr(BIO_F_BIO_READ, BIO_R_UNSUPPORTED_METHOD);
+ BIOerr(BIO_F_BIO_READ_EX, BIO_R_UNSUPPORTED_METHOD);
return (-2);
}
- cb = b->callback;
- if ((cb != NULL) &&
- ((i = (int)cb(b, BIO_CB_READ, out, outl, 0L, 1L)) <= 0))
- return (i);
+ if ((b->callback != NULL || b->callback_ex != NULL) &&
+ ((ret = bio_call_callback(b, BIO_CB_READ, out, outl, 0, 0L, 1L, read,
+ NULL)) <= 0))
+ return ret;
if (!b->init) {
- BIOerr(BIO_F_BIO_READ, BIO_R_UNINITIALIZED);
- return (-2);
+ BIOerr(BIO_F_BIO_READ_EX, BIO_R_UNINITIALIZED);
+ return -2;
}
- i = b->method->bread(b, out, outl);
+ ret = b->method->bread(b, out, outl, read);
- if (i > 0)
- b->num_read += (uint64_t)i;
+ if (ret > 0)
+ b->num_read += (uint64_t)*read;
- if (cb != NULL)
- i = (int)cb(b, BIO_CB_READ | BIO_CB_RETURN, out, outl, 0L, (long)i);
- return (i);
+ if (b->callback != NULL || b->callback_ex != NULL)
+ ret = bio_call_callback(b, BIO_CB_READ | BIO_CB_RETURN, out, outl, 0,
+ 0L, ret, read, NULL);
+
+ return ret;
}
int BIO_write(BIO *b, const void *in, int inl)
}
int (*BIO_meth_get_read(BIO_METHOD *biom)) (BIO *, char *, int)
+{
+ return biom->bread_old;
+}
+
+int (*BIO_meth_get_read_ex(BIO_METHOD *biom)) (BIO *, char *, size_t, size_t *)
{
return biom->bread;
}
+/* Conversion for old style bread to new style */
+int bread_conv(BIO *bio, char *out, size_t outl, size_t *read)
+{
+ int ret;
+
+ if (outl > INT_MAX)
+ return 0;
+
+ ret = bio->method->bread_old(bio, out, (int)outl);
+
+ if (ret <= 0) {
+ *read = 0;
+ return ret;
+ }
+
+ *read = (size_t)ret;
+
+ return 1;
+}
+
int BIO_meth_set_read(BIO_METHOD *biom,
int (*bread) (BIO *, char *, int))
+{
+ biom->bread_old = bread;
+ biom->bread = bread_conv;
+ return 1;
+}
+
+int BIO_meth_set_read_ex(BIO_METHOD *biom,
+ int (*bread) (BIO *, char *, size_t, size_t *))
{
biom->bread = bread;
return 1;
BIO_TYPE_ACCEPT,
"socket accept",
acpt_write,
+ /* TODO: Convert to new style read function */
+ bread_conv,
acpt_read,
acpt_puts,
NULL, /* connect_gets, */
BIO_TYPE_BIO,
"BIO pair",
bio_write,
+ /* TODO: Convert to new style read function */
+ bread_conv,
bio_read,
bio_puts,
NULL /* no bio_gets */ ,
BIO_TYPE_CONNECT,
"socket connect",
conn_write,
+ /* TODO: Convert to new style read function */
+ bread_conv,
conn_read,
conn_puts,
NULL, /* connect_gets, */
BIO_TYPE_DGRAM,
"datagram socket",
dgram_write,
+ /* TODO: Convert to new style read function */
+ bread_conv,
dgram_read,
dgram_puts,
NULL, /* dgram_gets, */
static const BIO_METHOD methods_fdp = {
BIO_TYPE_FD, "file descriptor",
fd_write,
+ /* TODO: Convert to new style read function */
+ bread_conv,
fd_read,
fd_puts,
fd_gets,
BIO_TYPE_FILE,
"FILE pointer",
file_write,
+ /* TODO: Convert to new style read function */
+ bread_conv,
file_read,
file_puts,
file_gets,
BIO_TYPE_MEM, "syslog",
slg_write,
NULL,
+ NULL,
slg_puts,
NULL,
slg_ctrl,
BIO_TYPE_MEM,
"memory buffer",
mem_write,
+ /* TODO: Convert to new style read function */
+ bread_conv,
mem_read,
mem_puts,
mem_gets,
BIO_TYPE_MEM,
"secure memory buffer",
mem_write,
+ /* TODO: Convert to new style read function */
+ bread_conv,
mem_read,
mem_puts,
mem_gets,
BIO_TYPE_NULL,
"NULL",
null_write,
+ /* TODO: Convert to new style read function */
+ bread_conv,
null_read,
null_puts,
null_gets,
BIO_TYPE_SOCKET,
"socket",
sock_write,
+ /* TODO: Convert to new style read function */
+ bread_conv,
sock_read,
sock_puts,
NULL, /* sock_gets, */
static const BIO_METHOD methods_b64 = {
BIO_TYPE_BASE64, "base64 encoding",
b64_write,
+ /* TODO: Convert to new style read function */
+ bread_conv,
b64_read,
b64_puts,
NULL, /* b64_gets, */
static const BIO_METHOD methods_enc = {
BIO_TYPE_CIPHER, "cipher",
enc_write,
+ /* TODO: Convert to new style read function */
+ bread_conv,
enc_read,
NULL, /* enc_puts, */
NULL, /* enc_gets, */
static const BIO_METHOD methods_md = {
BIO_TYPE_MD, "message digest",
md_write,
+ /* TODO: Convert to new style read function */
+ bread_conv,
md_read,
NULL, /* md_puts, */
md_gets,
static const BIO_METHOD methods_ok = {
BIO_TYPE_CIPHER, "reliable",
ok_write,
+ /* TODO: Convert to new style read function */
+ bread_conv,
ok_read,
NULL, /* ok_puts, */
NULL, /* ok_gets, */
int type;
const char *name;
int (*bwrite) (BIO *, const char *, int);
- int (*bread) (BIO *, char *, int);
+ int (*bread) (BIO *, char *, size_t, size_t *);
+ int (*bread_old) (BIO *, char *, int);
int (*bputs) (BIO *, const char *);
int (*bgets) (BIO *, char *, int);
long (*ctrl) (BIO *, int, long, void *);
void bio_free_ex_data(BIO *bio);
void bio_cleanup(void);
+
+
+/* Old style to new style BIO_METHOD conversion functions */
+int bread_conv(BIO *bio, char *out, size_t outl, size_t *read);
typedef long (*BIO_callback_fn)(BIO *b, int oper, const char *argp, int argi,
long argl, long ret);
+typedef long (*BIO_callback_fn_ex)(BIO *b, int oper, const char *argp,
+ size_t len, int argi,
+ long argl, int ret, size_t *processed,
+ long *lret);
BIO_callback_fn BIO_get_callback(const BIO *b);
void BIO_set_callback(BIO *b, BIO_callback_fn callback);
+
+BIO_callback_fn_ex BIO_get_callback_ex(const BIO *b);
+void BIO_set_callback_ex(BIO *b, BIO_callback_fn_ex callback);
+
char *BIO_get_callback_arg(const BIO *b);
void BIO_set_callback_arg(BIO *b, char *arg);
void BIO_vfree(BIO *a);
int BIO_up_ref(BIO *a);
int BIO_read(BIO *b, void *data, int len);
+int BIO_read_ex(BIO *b, void *out, size_t outl, size_t *read);
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);
int BIO_meth_set_write(BIO_METHOD *biom,
int (*write) (BIO *, const char *, int));
int (*BIO_meth_get_read(BIO_METHOD *biom)) (BIO *, char *, int);
+int (*BIO_meth_get_read_ex(BIO_METHOD *biom)) (BIO *, char *, size_t, size_t *);
int BIO_meth_set_read(BIO_METHOD *biom,
int (*read) (BIO *, char *, int));
+int BIO_meth_set_read_ex(BIO_METHOD *biom,
+ int (*bread) (BIO *, char *, size_t, size_t *));
int (*BIO_meth_get_puts(BIO_METHOD *biom)) (BIO *, const char *);
int BIO_meth_set_puts(BIO_METHOD *biom,
int (*puts) (BIO *, const char *));
# define BIO_F_BIO_PARSE_HOSTSERV 136
# define BIO_F_BIO_PUTS 110
# define BIO_F_BIO_READ 111
+# define BIO_F_BIO_READ_EX 105
# define BIO_F_BIO_SOCKET 140
# define BIO_F_BIO_SOCKET_NBIO 142
# define BIO_F_BIO_SOCK_INFO 141
#include "ssl_locl.h"
static int ssl_write(BIO *h, const char *buf, int num);
-static int ssl_read(BIO *h, char *buf, int size);
+static int ssl_read(BIO *b, char *out, size_t outl, size_t *read);
static int ssl_puts(BIO *h, const char *str);
static long ssl_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int ssl_new(BIO *h);
BIO_TYPE_SSL, "ssl",
ssl_write,
ssl_read,
+ NULL,
ssl_puts,
NULL, /* ssl_gets, */
ssl_ctrl,
return 1;
}
-static int ssl_read(BIO *b, char *out, int outl)
+static int ssl_read(BIO *b, char *out, size_t outl, size_t *read)
{
int ret = 1;
BIO_SSL *sb;
BIO_clear_retry_flags(b);
+ if (outl > INT_MAX)
+ return -1;
+
ret = SSL_read(ssl, out, outl);
switch (SSL_get_error(ssl, ret)) {
}
BIO_set_retry_reason(b, retry_reason);
- return (ret);
+
+ if (ret < 0)
+ return ret;
+
+ *read = (size_t)ret;
+
+ return 1;
}
static int ssl_write(BIO *b, const char *out, int outl)
OCSP_RESPID_match 4159 1_1_0a EXIST::FUNCTION:OCSP
ASN1_ITEM_lookup 4160 1_1_1 EXIST::FUNCTION:
ASN1_ITEM_get 4161 1_1_1 EXIST::FUNCTION:
+BIO_read_ex 4162 1_1_1 EXIST::FUNCTION:
+BIO_set_callback_ex 4163 1_1_1 EXIST::FUNCTION:
+BIO_get_callback_ex 4164 1_1_1 EXIST::FUNCTION:
+BIO_meth_set_read_ex 4165 1_1_1 EXIST::FUNCTION:
+BIO_meth_get_read_ex 4166 1_1_1 EXIST::FUNCTION: