Catch non-bytestrings from ALPN callbacks.
diff --git a/OpenSSL/SSL.py b/OpenSSL/SSL.py
index 1e40917..cc2472f 100644
--- a/OpenSSL/SSL.py
+++ b/OpenSSL/SSL.py
@@ -5,6 +5,7 @@
from errno import errorcode
from six import text_type as _text_type
+from six import binary_type as _binary_type
from six import integer_types as integer_types
from six import int2byte, indexbytes
@@ -1004,6 +1005,9 @@
# Call the callback
outstr = callback(conn, protolist)
+ if not isinstance(outstr, _binary_type):
+ raise TypeError("ALPN callback must return a bytestring.")
+
# Save our callback arguments on the connection object to make sure
# that they don't get freed before OpenSSL can use them. Then,
# return them in the appropriate output parameters.