Skip to content

Commit 3555caa

Browse files
Chip Turnerjtolmer
authored andcommitted
Fix mysql issue with openssl error codes
Summary: mysql wasn't using OpenSSL error codes correctly; it was using the return value of SSL_get_error rather than ERR_get_error, which made for nonsensical errors. Before this patch, with a cert signed by an unknown CA, this was the error: ERROR 2026 (HY000): SSL connection error: error:00000001:lib(0):func(0):reason(1) after: ERROR 2026 (HY000): SSL connection error: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed Test Plan: jenkins Reviewers: steaphan, brianp, santoshb Reviewed By: brianp, santoshb
1 parent e9f910b commit 3555caa

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

vio/viossl.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ report_errors(SSL* ssl)
3737

3838
DBUG_ENTER("report_errors");
3939

40-
while ((l= ERR_get_error_line_data(&file,&line,&data,&flags)))
40+
/* Peek at the error queue; don't use get_error so that the error is
41+
preserved for our caller. */
42+
if ((l= ERR_peek_error_line_data(&file,&line,&data,&flags)))
4143
{
4244
DBUG_PRINT("error", ("OpenSSL: %s:%s:%d:%s\n", ERR_error_string(l,buf),
4345
file,line,(flags&ERR_TXT_STRING)?data:"")) ;
@@ -143,20 +145,24 @@ static my_bool ssl_should_retry(Vio *vio, int ret,
143145
break;
144146
default:
145147
#ifndef DBUG_OFF /* Debug build */
146-
/* Note: the OpenSSL error queue gets cleared in report_errors(). */
147148
report_errors(ssl);
148-
#else /* Release build */
149-
# ifndef HAVE_YASSL
150-
/* OpenSSL: clear the error queue. */
151-
ERR_clear_error();
152-
# endif
153149
#endif
154150
should_retry= FALSE;
155151
ssl_set_sys_error(ssl_error);
156152
break;
157153
}
158154

159-
*ssl_errno_holder= ssl_error;
155+
/*
156+
ERR_get_error() is actually the error we generally want to
157+
display if SSL_get_error indicates it is an SSL error (instead
158+
of, say, a network issue)
159+
*/
160+
if (ssl_error == SSL_ERROR_SSL) {
161+
*ssl_errno_holder= ERR_get_error();
162+
} else {
163+
*ssl_errno_holder= ssl_error;
164+
}
165+
ERR_clear_error();
160166

161167
return should_retry;
162168
}
@@ -397,6 +403,7 @@ static int ssl_do(struct st_VioSSLFd *ptr, Vio *vio, long timeout,
397403
{
398404
DBUG_PRINT("error", ("SSL_new failure"));
399405
*ssl_errno_holder= ERR_get_error();
406+
ERR_clear_error();
400407
DBUG_RETURN(1);
401408
}
402409
DBUG_PRINT("info", ("ssl: 0x%lx timeout: %ld", (long) ssl, timeout));

0 commit comments

Comments
 (0)