|
1 | 1 | /*
|
2 |
| - * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. |
| 2 | + * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved. |
3 | 3 | * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
4 | 4 | * Copyright 2005 Nokia. All rights reserved.
|
5 | 5 | *
|
@@ -2236,6 +2236,30 @@ static void print_stats(BIO *bio, SSL_CTX *ssl_ctx)
|
2236 | 2236 | SSL_CTX_sess_get_cache_size(ssl_ctx));
|
2237 | 2237 | }
|
2238 | 2238 |
|
| 2239 | +static long int count_reads_callback(BIO *bio, int cmd, const char *argp, |
| 2240 | + int argi, long int argl, long int ret) |
| 2241 | +{ |
| 2242 | + unsigned int *p_counter = (unsigned int *)BIO_get_callback_arg(bio); |
| 2243 | + |
| 2244 | + switch (cmd) { |
| 2245 | + case BIO_CB_READ: /* No break here */ |
| 2246 | + case BIO_CB_GETS: |
| 2247 | + if (p_counter != NULL) |
| 2248 | + ++*p_counter; |
| 2249 | + break; |
| 2250 | + default: |
| 2251 | + break; |
| 2252 | + } |
| 2253 | + |
| 2254 | + if (s_debug) { |
| 2255 | + BIO_set_callback_arg(bio, (char *)bio_s_out); |
| 2256 | + ret = bio_dump_callback(bio, cmd, argp, argi, argl, ret); |
| 2257 | + BIO_set_callback_arg(bio, (char *)p_counter); |
| 2258 | + } |
| 2259 | + |
| 2260 | + return ret; |
| 2261 | +} |
| 2262 | + |
2239 | 2263 | static int sv_body(int s, int stype, int prot, unsigned char *context)
|
2240 | 2264 | {
|
2241 | 2265 | char *buf = NULL;
|
@@ -2353,10 +2377,7 @@ static int sv_body(int s, int stype, int prot, unsigned char *context)
|
2353 | 2377 | SSL_set_accept_state(con);
|
2354 | 2378 | /* SSL_set_fd(con,s); */
|
2355 | 2379 |
|
2356 |
| - if (s_debug) { |
2357 |
| - BIO_set_callback(SSL_get_rbio(con), bio_dump_callback); |
2358 |
| - BIO_set_callback_arg(SSL_get_rbio(con), (char *)bio_s_out); |
2359 |
| - } |
| 2380 | + BIO_set_callback(SSL_get_rbio(con), count_reads_callback); |
2360 | 2381 | if (s_msg) {
|
2361 | 2382 | #ifndef OPENSSL_NO_SSL_TRACE
|
2362 | 2383 | if (s_msg == 2)
|
@@ -2648,7 +2669,25 @@ static int sv_body(int s, int stype, int prot, unsigned char *context)
|
2648 | 2669 | */
|
2649 | 2670 | if ((!async || !SSL_waiting_for_async(con))
|
2650 | 2671 | && !SSL_is_init_finished(con)) {
|
| 2672 | + /* |
| 2673 | + * Count number of reads during init_ssl_connection. |
| 2674 | + * It helps us to distinguish configuration errors from errors |
| 2675 | + * caused by a client. |
| 2676 | + */ |
| 2677 | + unsigned int read_counter = 0; |
| 2678 | + |
| 2679 | + BIO_set_callback_arg(SSL_get_rbio(con), (char *)&read_counter); |
2651 | 2680 | i = init_ssl_connection(con);
|
| 2681 | + BIO_set_callback_arg(SSL_get_rbio(con), NULL); |
| 2682 | + |
| 2683 | + /* |
| 2684 | + * If initialization fails without reads, then |
| 2685 | + * there was a fatal error in configuration. |
| 2686 | + */ |
| 2687 | + if (i <= 0 && read_counter == 0) { |
| 2688 | + ret = -1; |
| 2689 | + goto err; |
| 2690 | + } |
2652 | 2691 |
|
2653 | 2692 | if (i < 0) {
|
2654 | 2693 | ret = 0;
|
|
0 commit comments