Here is a straightforward diff that converts BIO_new(), BIO_set() and the
BIO_{f,s}_*() functions to match OpenSSL wrt const. This was part of a
larger diff that was run through a bulk by sthen and produced no fallout.

Three remarks:

* Before BIO_set() was merged into BIO_new() and removed from OpenSSL, it
  was converted to const as below, which is necessary for BIO_new(). This
  seems the simplest way of dealing with this for now. There are almost
  no consumers of this function anyway, so I don't see why not.

  Another option would be to leave BIO_set() untouched and to inline (a
  simplified version of) it into BIO_new().

* The omission of BIO_s_mem() in this diff is an oversight on my part. It
  wasn't part of sthen's bulk. Since it is used quite a bit according to
  codesearch, I prefer to avoid potential ports fallout and take care of
  it later.

* BIO_f_ssl() is the last const difference between libssl and OpenSSL.

Index: lib/libcrypto/asn1/asn1.h
===================================================================
RCS file: /var/cvs/src/lib/libcrypto/asn1/asn1.h,v
retrieving revision 1.47
diff -u -p -r1.47 asn1.h
--- lib/libcrypto/asn1/asn1.h   25 Apr 2018 12:07:40 -0000      1.47
+++ lib/libcrypto/asn1/asn1.h   30 Apr 2018 18:52:00 -0000
@@ -1187,7 +1187,7 @@ void ASN1_PCTX_set_oid_flags(ASN1_PCTX *
 unsigned long ASN1_PCTX_get_str_flags(const ASN1_PCTX *p);
 void ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags);
 
-BIO_METHOD *BIO_f_asn1(void);
+const BIO_METHOD *BIO_f_asn1(void);
 
 BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it);
 
Index: lib/libcrypto/asn1/bio_asn1.c
===================================================================
RCS file: /var/cvs/src/lib/libcrypto/asn1/bio_asn1.c,v
retrieving revision 1.12
diff -u -p -r1.12 bio_asn1.c
--- lib/libcrypto/asn1/bio_asn1.c       23 Dec 2015 01:46:33 -0000      1.12
+++ lib/libcrypto/asn1/bio_asn1.c       30 Apr 2018 18:52:00 -0000
@@ -125,7 +125,7 @@ static int asn1_bio_setup_ex(BIO *b, BIO
     asn1_ps_func *setup, asn1_bio_state_t ex_state,
     asn1_bio_state_t other_state);
 
-static BIO_METHOD methods_asn1 = {
+static const BIO_METHOD methods_asn1 = {
        .type = BIO_TYPE_ASN1,
        .name = "asn1",
        .bwrite = asn1_bio_write,
@@ -138,7 +138,7 @@ static BIO_METHOD methods_asn1 = {
        .callback_ctrl = asn1_bio_callback_ctrl
 };
 
-BIO_METHOD *
+const BIO_METHOD *
 BIO_f_asn1(void)
 {
        return (&methods_asn1);
Index: lib/libcrypto/bio/bf_buff.c
===================================================================
RCS file: /var/cvs/src/lib/libcrypto/bio/bf_buff.c,v
retrieving revision 1.24
diff -u -p -r1.24 bf_buff.c
--- lib/libcrypto/bio/bf_buff.c 29 Jan 2017 17:49:22 -0000      1.24
+++ lib/libcrypto/bio/bf_buff.c 30 Apr 2018 18:52:00 -0000
@@ -73,7 +73,7 @@ static int buffer_free(BIO *data);
 static long buffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
 #define DEFAULT_BUFFER_SIZE    4096
 
-static BIO_METHOD methods_buffer = {
+static const BIO_METHOD methods_buffer = {
        .type = BIO_TYPE_BUFFER,
        .name = "buffer",
        .bwrite = buffer_write,
@@ -86,7 +86,7 @@ static BIO_METHOD methods_buffer = {
        .callback_ctrl = buffer_callback_ctrl
 };
 
-BIO_METHOD *
+const BIO_METHOD *
 BIO_f_buffer(void)
 {
        return (&methods_buffer);
Index: lib/libcrypto/bio/bf_nbio.c
===================================================================
RCS file: /var/cvs/src/lib/libcrypto/bio/bf_nbio.c,v
retrieving revision 1.19
diff -u -p -r1.19 bf_nbio.c
--- lib/libcrypto/bio/bf_nbio.c 7 Feb 2015 13:19:15 -0000       1.19
+++ lib/libcrypto/bio/bf_nbio.c 30 Apr 2018 18:52:00 -0000
@@ -80,7 +80,7 @@ typedef struct nbio_test_st {
        int lwn;
 } NBIO_TEST;
 
-static BIO_METHOD methods_nbiof = {
+static const BIO_METHOD methods_nbiof = {
        .type = BIO_TYPE_NBIO_TEST,
        .name = "non-blocking IO test filter",
        .bwrite = nbiof_write,
@@ -93,7 +93,7 @@ static BIO_METHOD methods_nbiof = {
        .callback_ctrl = nbiof_callback_ctrl
 };
 
-BIO_METHOD *
+const BIO_METHOD *
 BIO_f_nbio_test(void)
 {
        return (&methods_nbiof);
Index: lib/libcrypto/bio/bf_null.c
===================================================================
RCS file: /var/cvs/src/lib/libcrypto/bio/bf_null.c,v
retrieving revision 1.11
diff -u -p -r1.11 bf_null.c
--- lib/libcrypto/bio/bf_null.c 11 Jul 2014 08:44:47 -0000      1.11
+++ lib/libcrypto/bio/bf_null.c 30 Apr 2018 18:52:00 -0000
@@ -73,7 +73,7 @@ static int nullf_new(BIO *h);
 static int nullf_free(BIO *data);
 static long nullf_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
 
-static BIO_METHOD methods_nullf = {
+static const BIO_METHOD methods_nullf = {
        .type = BIO_TYPE_NULL_FILTER,
        .name = "NULL filter",
        .bwrite = nullf_write,
@@ -86,7 +86,7 @@ static BIO_METHOD methods_nullf = {
        .callback_ctrl = nullf_callback_ctrl
 };
 
-BIO_METHOD *
+const BIO_METHOD *
 BIO_f_null(void)
 {
        return (&methods_nullf);
Index: lib/libcrypto/bio/bio.h
===================================================================
RCS file: /var/cvs/src/lib/libcrypto/bio/bio.h,v
retrieving revision 1.40
diff -u -p -r1.40 bio.h
--- lib/libcrypto/bio/bio.h     17 Mar 2018 15:05:55 -0000      1.40
+++ lib/libcrypto/bio/bio.h     30 Apr 2018 18:52:00 -0000
@@ -286,7 +286,7 @@ typedef struct bio_method_st {
 } BIO_METHOD;
 
 struct bio_st {
-       BIO_METHOD *method;
+       const BIO_METHOD *method;
        /* bio, mode, argp, argi, argl, ret */
        long (*callback)(struct bio_st *, int, const char *, int, long, long);
        char *cb_arg; /* first argument for the callback */
@@ -601,8 +601,8 @@ BIO_METHOD *BIO_s_file(void );
 BIO *BIO_new_file(const char *filename, const char *mode);
 BIO *BIO_new_fp(FILE *stream, int close_flag);
 # define BIO_s_file_internal   BIO_s_file
-BIO *  BIO_new(BIO_METHOD *type);
-int    BIO_set(BIO *a, BIO_METHOD *type);
+BIO    *BIO_new(const BIO_METHOD *type);
+int    BIO_set(BIO *a, const BIO_METHOD *type);
 int    BIO_free(BIO *a);
 int    BIO_up_ref(BIO *bio);
 void   *BIO_get_data(BIO *a);
@@ -643,16 +643,16 @@ long BIO_debug_callback(BIO *bio, int cm
 
 BIO_METHOD *BIO_s_mem(void);
 BIO *BIO_new_mem_buf(void *buf, int len);
-BIO_METHOD *BIO_s_socket(void);
-BIO_METHOD *BIO_s_connect(void);
-BIO_METHOD *BIO_s_accept(void);
-BIO_METHOD *BIO_s_fd(void);
-BIO_METHOD *BIO_s_log(void);
-BIO_METHOD *BIO_s_bio(void);
-BIO_METHOD *BIO_s_null(void);
-BIO_METHOD *BIO_f_null(void);
-BIO_METHOD *BIO_f_buffer(void);
-BIO_METHOD *BIO_f_nbio_test(void);
+const BIO_METHOD *BIO_s_socket(void);
+const BIO_METHOD *BIO_s_connect(void);
+const BIO_METHOD *BIO_s_accept(void);
+const BIO_METHOD *BIO_s_fd(void);
+const BIO_METHOD *BIO_s_log(void);
+const BIO_METHOD *BIO_s_bio(void);
+const BIO_METHOD *BIO_s_null(void);
+const BIO_METHOD *BIO_f_null(void);
+const BIO_METHOD *BIO_f_buffer(void);
+const BIO_METHOD *BIO_f_nbio_test(void);
 #ifndef OPENSSL_NO_DGRAM
 BIO_METHOD *BIO_s_datagram(void);
 #endif
Index: lib/libcrypto/bio/bio_lib.c
===================================================================
RCS file: /var/cvs/src/lib/libcrypto/bio/bio_lib.c,v
retrieving revision 1.27
diff -u -p -r1.27 bio_lib.c
--- lib/libcrypto/bio/bio_lib.c 22 Feb 2018 16:38:43 -0000      1.27
+++ lib/libcrypto/bio/bio_lib.c 30 Apr 2018 18:52:00 -0000
@@ -79,7 +79,7 @@ BIO_get_new_index(void)
 }
 
 BIO *
-BIO_new(BIO_METHOD *method)
+BIO_new(const BIO_METHOD *method)
 {
        BIO *ret = NULL;
 
@@ -96,7 +96,7 @@ BIO_new(BIO_METHOD *method)
 }
 
 int
-BIO_set(BIO *bio, BIO_METHOD *method)
+BIO_set(BIO *bio, const BIO_METHOD *method)
 {
        bio->method = method;
        bio->callback = NULL;
Index: lib/libcrypto/bio/bss_acpt.c
===================================================================
RCS file: /var/cvs/src/lib/libcrypto/bio/bss_acpt.c,v
retrieving revision 1.27
diff -u -p -r1.27 bss_acpt.c
--- lib/libcrypto/bio/bss_acpt.c        29 Jan 2017 17:49:22 -0000      1.27
+++ lib/libcrypto/bio/bss_acpt.c        30 Apr 2018 18:52:00 -0000
@@ -100,7 +100,7 @@ static void BIO_ACCEPT_free(BIO_ACCEPT *
 #define ACPT_S_GET_ACCEPT_SOCKET       2
 #define ACPT_S_OK                      3
 
-static BIO_METHOD methods_acceptp = {
+static const BIO_METHOD methods_acceptp = {
        .type = BIO_TYPE_ACCEPT,
        .name = "socket accept",
        .bwrite = acpt_write,
@@ -111,7 +111,7 @@ static BIO_METHOD methods_acceptp = {
        .destroy = acpt_free
 };
 
-BIO_METHOD *
+const BIO_METHOD *
 BIO_s_accept(void)
 {
        return (&methods_acceptp);
Index: lib/libcrypto/bio/bss_bio.c
===================================================================
RCS file: /var/cvs/src/lib/libcrypto/bio/bss_bio.c,v
retrieving revision 1.23
diff -u -p -r1.23 bss_bio.c
--- lib/libcrypto/bio/bss_bio.c 29 Jan 2017 17:49:22 -0000      1.23
+++ lib/libcrypto/bio/bss_bio.c 30 Apr 2018 18:52:00 -0000
@@ -94,7 +94,7 @@ static int bio_puts(BIO *bio, const char
 static int bio_make_pair(BIO *bio1, BIO *bio2);
 static void bio_destroy_pair(BIO *bio);
 
-static BIO_METHOD methods_biop = {
+static const BIO_METHOD methods_biop = {
        .type = BIO_TYPE_BIO,
        .name = "BIO pair",
        .bwrite = bio_write,
@@ -105,7 +105,7 @@ static BIO_METHOD methods_biop = {
        .destroy = bio_free
 };
 
-BIO_METHOD *
+const BIO_METHOD *
 BIO_s_bio(void)
 {
        return &methods_biop;
Index: lib/libcrypto/bio/bss_conn.c
===================================================================
RCS file: /var/cvs/src/lib/libcrypto/bio/bss_conn.c,v
retrieving revision 1.33
diff -u -p -r1.33 bss_conn.c
--- lib/libcrypto/bio/bss_conn.c        29 Jan 2017 17:49:22 -0000      1.33
+++ lib/libcrypto/bio/bss_conn.c        30 Apr 2018 18:52:00 -0000
@@ -106,7 +106,7 @@ static void conn_close_socket(BIO *data)
 BIO_CONNECT *BIO_CONNECT_new(void);
 void BIO_CONNECT_free(BIO_CONNECT *a);
 
-static BIO_METHOD methods_connectp = {
+static const BIO_METHOD methods_connectp = {
        .type = BIO_TYPE_CONNECT,
        .name = "socket connect",
        .bwrite = conn_write,
@@ -319,7 +319,7 @@ BIO_CONNECT_free(BIO_CONNECT *a)
        free(a);
 }
 
-BIO_METHOD *
+const BIO_METHOD *
 BIO_s_connect(void)
 {
        return (&methods_connectp);
Index: lib/libcrypto/bio/bss_fd.c
===================================================================
RCS file: /var/cvs/src/lib/libcrypto/bio/bss_fd.c,v
retrieving revision 1.18
diff -u -p -r1.18 bss_fd.c
--- lib/libcrypto/bio/bss_fd.c  12 Feb 2015 03:54:07 -0000      1.18
+++ lib/libcrypto/bio/bss_fd.c  30 Apr 2018 18:52:00 -0000
@@ -74,7 +74,7 @@ static int fd_new(BIO *h);
 static int fd_free(BIO *data);
 int BIO_fd_should_retry(int s);
 
-static BIO_METHOD methods_fdp = {
+static const BIO_METHOD methods_fdp = {
        .type = BIO_TYPE_FD,
        .name = "file descriptor",
        .bwrite = fd_write,
@@ -86,7 +86,7 @@ static BIO_METHOD methods_fdp = {
        .destroy = fd_free
 };
 
-BIO_METHOD *
+const BIO_METHOD *
 BIO_s_fd(void)
 {
        return (&methods_fdp);
Index: lib/libcrypto/bio/bss_log.c
===================================================================
RCS file: /var/cvs/src/lib/libcrypto/bio/bss_log.c,v
retrieving revision 1.21
diff -u -p -r1.21 bss_log.c
--- lib/libcrypto/bio/bss_log.c 11 Jul 2014 08:44:47 -0000      1.21
+++ lib/libcrypto/bio/bss_log.c 30 Apr 2018 18:52:00 -0000
@@ -81,7 +81,7 @@ static void xopenlog(BIO* bp, char* name
 static void xsyslog(BIO* bp, int priority, const char* string);
 static void xcloselog(BIO* bp);
 
-static BIO_METHOD methods_slg = {
+static const BIO_METHOD methods_slg = {
        .type = BIO_TYPE_MEM,
        .name = "syslog",
        .bwrite = slg_write,
@@ -91,7 +91,7 @@ static BIO_METHOD methods_slg = {
        .destroy = slg_free
 };
 
-BIO_METHOD *
+const BIO_METHOD *
 BIO_s_log(void)
 {
        return (&methods_slg);
Index: lib/libcrypto/bio/bss_null.c
===================================================================
RCS file: /var/cvs/src/lib/libcrypto/bio/bss_null.c,v
retrieving revision 1.10
diff -u -p -r1.10 bss_null.c
--- lib/libcrypto/bio/bss_null.c        11 Jul 2014 08:44:47 -0000      1.10
+++ lib/libcrypto/bio/bss_null.c        30 Apr 2018 18:52:00 -0000
@@ -70,7 +70,7 @@ static long null_ctrl(BIO *h, int cmd, l
 static int null_new(BIO *h);
 static int null_free(BIO *data);
 
-static BIO_METHOD null_method = {
+static const BIO_METHOD null_method = {
        .type = BIO_TYPE_NULL,
        .name = "NULL",
        .bwrite = null_write,
@@ -82,7 +82,7 @@ static BIO_METHOD null_method = {
        .destroy = null_free
 };
 
-BIO_METHOD *
+const BIO_METHOD *
 BIO_s_null(void)
 {
        return (&null_method);
Index: lib/libcrypto/bio/bss_sock.c
===================================================================
RCS file: /var/cvs/src/lib/libcrypto/bio/bss_sock.c,v
retrieving revision 1.23
diff -u -p -r1.23 bss_sock.c
--- lib/libcrypto/bio/bss_sock.c        11 Jul 2014 08:44:47 -0000      1.23
+++ lib/libcrypto/bio/bss_sock.c        30 Apr 2018 18:52:00 -0000
@@ -73,7 +73,7 @@ static int sock_new(BIO *h);
 static int sock_free(BIO *data);
 int BIO_sock_should_retry(int s);
 
-static BIO_METHOD methods_sockp = {
+static const BIO_METHOD methods_sockp = {
        .type = BIO_TYPE_SOCKET,
        .name = "socket",
        .bwrite = sock_write,
@@ -84,7 +84,7 @@ static BIO_METHOD methods_sockp = {
        .destroy = sock_free
 };
 
-BIO_METHOD *
+const BIO_METHOD *
 BIO_s_socket(void)
 {
        return (&methods_sockp);
Index: lib/libssl/bio_ssl.c
===================================================================
RCS file: /var/cvs/src/lib/libssl/bio_ssl.c,v
retrieving revision 1.27
diff -u -p -r1.27 bio_ssl.c
--- lib/libssl/bio_ssl.c        7 Feb 2017 02:08:38 -0000       1.27
+++ lib/libssl/bio_ssl.c        30 Apr 2018 18:52:00 -0000
@@ -85,7 +85,7 @@ typedef struct bio_ssl_st {
        time_t last_time;
 } BIO_SSL;
 
-static BIO_METHOD methods_sslp = {
+static const BIO_METHOD methods_sslp = {
        .type = BIO_TYPE_SSL,
        .name = "ssl",
        .bwrite = ssl_write,
@@ -97,7 +97,7 @@ static BIO_METHOD methods_sslp = {
        .callback_ctrl = ssl_callback_ctrl,
 };
 
-BIO_METHOD *
+const BIO_METHOD *
 BIO_f_ssl(void)
 {
        return (&methods_sslp);
Index: lib/libssl/ssl.h
===================================================================
RCS file: /var/cvs/src/lib/libssl/ssl.h,v
retrieving revision 1.157
diff -u -p -r1.157 ssl.h
--- lib/libssl/ssl.h    25 Apr 2018 07:25:17 -0000      1.157
+++ lib/libssl/ssl.h    30 Apr 2018 18:52:00 -0000
@@ -1221,7 +1221,7 @@ int SSL_set_max_proto_version(SSL *ssl, 
 #define SSL_set_max_proto_version      SSL_set_max_proto_version
 #endif
 
-BIO_METHOD *BIO_f_ssl(void);
+const BIO_METHOD *BIO_f_ssl(void);
 BIO *BIO_new_ssl(SSL_CTX *ctx, int client);
 BIO *BIO_new_ssl_connect(SSL_CTX *ctx);
 BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx);

Reply via email to