@cryptotaxi247 / netdata-1 / commits / badcabc70

Add missing control to streaming (#13112)

fix_tls_stream: Add call to SSL_get_error to avoid an infinite loop

thiagoftsm committed Jun 15, 2022 at 15:03 UTC badcabc70ff006213a47db856430caeecfbae8a0
1 file changed +10
streaming/receiver.c
+10
@@ -217,9 +217,19 @@ static int read_stream(struct receiver_state *r, FILE *fp, char* buffer, size_t
217 // we need to receive data with LF to parse compression header
218 size_t ofs = 0;
219 int res = 0;
220 + errno = 0;
221 while (ofs < size) {
222 do {
223 res = SSL_read(r->ssl.conn, buffer + ofs, 1);
224 + // When either SSL_ERROR_SYSCALL (OpenSSL < 3.0) or SSL_ERROR_SSL(OpenSSL > 3.0) happens,
225 + // the connection was lost https://www.openssl.org/docs/man3.0/man3/SSL_get_error.html,
226 + // without the test we will have an infinite loop https://github.com/netdata/netdata/issues/13092
227 + int local_ssl_err = SSL_get_error(r->ssl.conn, res);
228 + if (local_ssl_err == SSL_ERROR_SYSCALL || local_ssl_err == SSL_ERROR_SSL) {
229 + error("The SSL connection has error SSL_ERROR_SYSCALL(%d) and system is registering errno = %d",
230 + local_ssl_err, errno);
231 + return 1;
232 + }
233 } while (res == 0);
234
235 if (res < 0)