aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Benjamin <davidben@google.com>2017-04-17 09:42:03 -0400
committerDaniel Stenberg <daniel@haxx.se>2017-04-17 23:20:22 +0200
commit47b2f89d7c7e1440a344e6e82a9390e0f912d2f8 (patch)
tree70ed51ae63a782b4a32589e45d6bffe49d94ef14
parentaaa7e05c786290e212035079060911020ff4d3ba (diff)
openssl: make SSL_ERROR_to_str more future-proof
Rather than making assumptions about the values, use a switch-case. Closes #1424
-rw-r--r--lib/vtls/openssl.c50
1 files changed, 34 insertions, 16 deletions
diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c
index 5c4e34e91..35489f845 100644
--- a/lib/vtls/openssl.c
+++ b/lib/vtls/openssl.c
@@ -164,22 +164,40 @@ static unsigned long OpenSSL_version_num(void)
static const char *SSL_ERROR_to_str(int err)
{
- static const char * const str[] = {
- "SSL_ERROR_NONE", /* 0 */
- "SSL_ERROR_SSL", /* 1 */
- "SSL_ERROR_WANT_READ", /* 2 */
- "SSL_ERROR_WANT_WRITE", /* 3 */
- "SSL_ERROR_WANT_X509_LOOKUP", /* 4 */
- "SSL_ERROR_SYSCALL", /* 5 */
- "SSL_ERROR_ZERO_RETURN", /* 6 */
- "SSL_ERROR_WANT_CONNECT", /* 7 */
- "SSL_ERROR_WANT_ACCEPT", /* 8 */
- "SSL_ERROR_WANT_ASYNC", /* 9 */
- "SSL_ERROR_WANT_ASYNC_JOB", /* 10 */
- "SSL_ERROR_WANT_EARLY", /* 11 */
- };
- return ((err >= 0 && err < (int)(sizeof str / sizeof str[0])) ?
- str[err] : "SSL_ERROR unknown");
+ switch(err) {
+ case SSL_ERROR_NONE:
+ return "SSL_ERROR_NONE";
+ case SSL_ERROR_SSL:
+ return "SSL_ERROR_SSL";
+ case SSL_ERROR_WANT_READ:
+ return "SSL_ERROR_WANT_READ";
+ case SSL_ERROR_WANT_WRITE:
+ return "SSL_ERROR_WANT_WRITE";
+ case SSL_ERROR_WANT_X509_LOOKUP:
+ return "SSL_ERROR_WANT_X509_LOOKUP";
+ case SSL_ERROR_SYSCALL:
+ return "SSL_ERROR_SYSCALL";
+ case SSL_ERROR_ZERO_RETURN:
+ return "SSL_ERROR_ZERO_RETURN";
+ case SSL_ERROR_WANT_CONNECT:
+ return "SSL_ERROR_WANT_CONNECT";
+ case SSL_ERROR_WANT_ACCEPT:
+ return "SSL_ERROR_WANT_ACCEPT";
+#if defined(SSL_ERROR_WANT_ASYNC)
+ case SSL_ERROR_WANT_ASYNC:
+ return "SSL_ERROR_WANT_ASYNC";
+#endif
+#if defined(SSL_ERROR_WANT_ASYNC_JOB)
+ case SSL_ERROR_WANT_ASYNC_JOB:
+ return "SSL_ERROR_WANT_ASYNC_JOB";
+#endif
+#if defined(SSL_ERROR_WANT_EARLY)
+ case SSL_ERROR_WANT_EARLY:
+ return "SSL_ERROR_WANT_EARLY";
+#endif
+ default:
+ return "SSL_ERROR unknown";
+ }
}
static int passwd_callback(char *buf, int num, int encrypting,