Skip to content

Commit 27f9db9

Browse files
chundonglinlinxiaozhihongwinlinvip
authored
SSL: Fix SSL_get_error get the error of other coroutine. v5.0.155, v6.0.46 (#3513)
--------- Co-authored-by: john <[email protected]> Co-authored-by: winlin <[email protected]>
1 parent 665c30a commit 27f9db9

9 files changed

+22
-17
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
[![](https://badgen.net/badge/srs/stackoverflow/orange?icon=terminal)](https://stackoverflow.com/questions/tagged/simple-realtime-server)
1515
[![](https://opencollective.com/srs-server/tiers/badge.svg)](https://opencollective.com/srs-server/contribute)
1616
[![](https://img.shields.io/docker/pulls/ossrs/srs)](https://hub.docker.com/r/ossrs/srs/tags)
17-
[![](https://ossrs.net/wiki/images/do-btn-srs-125x20.svg)](https://cloud.digitalocean.com/droplets/new?appId=104916642&size=s-1vcpu-1gb&region=sgp1&image=ossrs-srs&type=applications)
17+
[![](https://ossrs.net/wiki/images/do-btn-srs-125x20.svg)](https://cloud.digitalocean.com/droplets/new?appId=133468816&size=s-1vcpu-512mb-10gb&region=sgp1&image=ossrs-srs&type=applications)
1818
[![](https://api.securityscorecards.dev/projects/github.com/ossrs/srs/badge)](https://api.securityscorecards.dev/projects/github.com/ossrs/srs)
1919
[![](https://bestpractices.coreinfrastructure.org/projects/5619/badge)](https://bestpractices.coreinfrastructure.org/projects/5619)
2020

trunk/doc/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The changelog for SRS.
88

99
## SRS 6.0 Changelog
1010

11+
* v6.0, 2023-05-29, Merge [#3513](https://github.com/ossrs/srs/pull/3513): SSL: Fix SSL_get_error get the error of other coroutine. v6.0.46 (#3513)
1112
* v6.0, 2023-05-14, Merge [#3534](https://github.com/ossrs/srs/pull/3534): Replace sprintf with snprintf to eliminate compile warnings. v6.0.45 (#3534)
1213
* v6.0, 2023-05-13, Merge [#3541](https://github.com/ossrs/srs/pull/3541): asan: Fix memory leak in asan by releasing global IPs when run_directly_or_daemon fails. v6.0.44 (#3541)
1314
* v6.0, 2023-05-12, Merge [#3539](https://github.com/ossrs/srs/pull/3539): WHIP: Improve HTTP DELETE for notifying server unpublish event. v6.0.43 (#3539)
@@ -59,6 +60,7 @@ The changelog for SRS.
5960

6061
## SRS 5.0 Changelog
6162

63+
* v5.0, 2023-05-29, Merge [#3513](https://github.com/ossrs/srs/pull/3513): SSL: Fix SSL_get_error get the error of other coroutine. v5.0.155 (#3513)
6264
* v5.0, 2023-05-13, Merge [#3541](https://github.com/ossrs/srs/pull/3541): asan: Fix memory leak in asan by releasing global IPs when run_directly_or_daemon fails. v5.0.154 (#3541)
6365
* v5.0, 2023-05-12, Merge [#3539](https://github.com/ossrs/srs/pull/3539): WHIP: Improve HTTP DELETE for notifying server unpublish event. v5.0.153 (#3539)
6466
* v5.0, 2023-03-27, Merge [#3450](https://github.com/ossrs/srs/pull/3450): WebRTC: Error message carries the SDP when failed. v5.0.151 (#3450)

trunk/src/app/srs_app_conn.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ srs_error_t SrsSslConnection::handshake(string key_file, string crt_file)
798798
return srs_error_new(ERROR_HTTPS_HANDSHAKE, "BIO_write r0=%d, data=%p, size=%d", r0, buf, nn);
799799
}
800800

801-
r0 = SSL_do_handshake(ssl); r1 = SSL_get_error(ssl, r0);
801+
r0 = SSL_do_handshake(ssl); r1 = SSL_get_error(ssl, r0); ERR_clear_error();
802802
if (r0 != -1 || r1 != SSL_ERROR_WANT_READ) {
803803
return srs_error_new(ERROR_HTTPS_HANDSHAKE, "handshake r0=%d, r1=%d", r0, r1);
804804
}
@@ -840,7 +840,7 @@ srs_error_t SrsSslConnection::handshake(string key_file, string crt_file)
840840
return srs_error_new(ERROR_HTTPS_HANDSHAKE, "BIO_write r0=%d, data=%p, size=%d", r0, buf, nn);
841841
}
842842

843-
r0 = SSL_do_handshake(ssl); r1 = SSL_get_error(ssl, r0);
843+
r0 = SSL_do_handshake(ssl); r1 = SSL_get_error(ssl, r0); ERR_clear_error();
844844
if (r0 == 1 && r1 == SSL_ERROR_NONE) {
845845
break;
846846
}
@@ -908,7 +908,7 @@ srs_error_t SrsSslConnection::read(void* plaintext, size_t nn_plaintext, ssize_t
908908
srs_error_t err = srs_success;
909909

910910
while (true) {
911-
int r0 = SSL_read(ssl, plaintext, nn_plaintext); int r1 = SSL_get_error(ssl, r0);
911+
int r0 = SSL_read(ssl, plaintext, nn_plaintext); int r1 = SSL_get_error(ssl, r0); ERR_clear_error();
912912
int r2 = BIO_ctrl_pending(bio_in); int r3 = SSL_is_init_finished(ssl);
913913

914914
// OK, got data.
@@ -966,7 +966,7 @@ srs_error_t SrsSslConnection::write(void* plaintext, size_t nn_plaintext, ssize_
966966
for (char* p = (char*)plaintext; p < (char*)plaintext + nn_plaintext;) {
967967
int left = (int)nn_plaintext - (p - (char*)plaintext);
968968
int r0 = SSL_write(ssl, (const void*)p, left);
969-
int r1 = SSL_get_error(ssl, r0);
969+
int r1 = SSL_get_error(ssl, r0); ERR_clear_error();
970970
if (r0 <= 0) {
971971
return srs_error_new(ERROR_HTTPS_WRITE, "https: write data=%p, size=%d, r0=%d, r1=%d", p, left, r0, r1);
972972
}

trunk/src/app/srs_app_conn.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <map>
1515

1616
#include <openssl/ssl.h>
17+
#include <openssl/err.h>
1718

1819
#include <srs_app_st.hpp>
1920
#include <srs_protocol_kbps.hpp>

trunk/src/app/srs_app_rtc_dtls.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void ssl_on_info(const SSL* dtls, int where, int ret)
7777
method = "undefined";
7878
}
7979

80-
int r1 = SSL_get_error(dtls, ret);
80+
int r1 = SSL_get_error(dtls, ret); ERR_clear_error();
8181
if (where & SSL_CB_LOOP) {
8282
srs_info("DTLS: method=%s state=%s(%s), where=%d, ret=%d, r1=%d", method, SSL_state_string(dtls),
8383
SSL_state_string_long(dtls), where, ret, r1);
@@ -528,7 +528,7 @@ srs_error_t SrsDtlsImpl::do_on_dtls(char* data, int nb_data)
528528
for (int i = 0; i < 1024 && BIO_ctrl_pending(bio_in) > 0; i++) {
529529
char buf[8092];
530530
int r0 = SSL_read(dtls, buf, sizeof(buf));
531-
int r1 = SSL_get_error(dtls, r0);
531+
int r1 = SSL_get_error(dtls, r0); ERR_clear_error();
532532

533533
if (r0 <= 0) {
534534
// SSL_ERROR_ZERO_RETURN
@@ -580,7 +580,7 @@ srs_error_t SrsDtlsImpl::do_handshake()
580580

581581
// Do handshake and get the result.
582582
int r0 = SSL_do_handshake(dtls);
583-
int r1 = SSL_get_error(dtls, r0);
583+
int r1 = SSL_get_error(dtls, r0); ERR_clear_error();
584584

585585
// Fatal SSL error, for example, no available suite when peer is DTLS 1.0 while we are DTLS 1.2.
586586
if (r0 < 0 && (r1 != SSL_ERROR_NONE && r1 != SSL_ERROR_WANT_READ && r1 != SSL_ERROR_WANT_WRITE)) {
@@ -864,7 +864,7 @@ srs_error_t SrsDtlsClientImpl::cycle()
864864
}
865865

866866
// The timeout is 0, so there must be a ARQ packet to transmit in openssl.
867-
r0 = BIO_reset(bio_out); int r1 = SSL_get_error(dtls, r0);
867+
r0 = BIO_reset(bio_out); int r1 = SSL_get_error(dtls, r0); ERR_clear_error();
868868
if (r0 != 1) {
869869
return srs_error_new(ERROR_OpenSslBIOReset, "BIO_reset r0=%d, r1=%d", r0, r1);
870870
}
@@ -873,7 +873,7 @@ srs_error_t SrsDtlsClientImpl::cycle()
873873
// had expired, it returns 0. Otherwise, it retransmits the previous flight of handshake
874874
// messages and returns 1. If too many timeouts had expired without progress or an error
875875
// occurs, it returns -1.
876-
r0 = DTLSv1_handle_timeout(dtls); r1 = SSL_get_error(dtls, r0);
876+
r0 = DTLSv1_handle_timeout(dtls); r1 = SSL_get_error(dtls, r0); ERR_clear_error();
877877
if (r0 == 0) {
878878
continue; // No timeout had expired.
879879
}

trunk/src/core/srs_core_version5.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
#define VERSION_MAJOR 5
1111
#define VERSION_MINOR 0
12-
#define VERSION_REVISION 154
12+
#define VERSION_REVISION 155
1313

1414
#endif

trunk/src/core/srs_core_version6.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
#define VERSION_MAJOR 6
1111
#define VERSION_MINOR 0
12-
#define VERSION_REVISION 45
12+
#define VERSION_REVISION 46
1313

1414
#endif

trunk/src/protocol/srs_protocol_http_client.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ srs_error_t SrsSslClient::handshake()
9090
SSL_set_mode(ssl, SSL_MODE_ENABLE_PARTIAL_WRITE);
9191

9292
// Send ClientHello.
93-
int r0 = SSL_do_handshake(ssl); int r1 = SSL_get_error(ssl, r0);
93+
int r0 = SSL_do_handshake(ssl); int r1 = SSL_get_error(ssl, r0); ERR_clear_error();
9494
if (r0 != -1 || r1 != SSL_ERROR_WANT_READ) {
9595
return srs_error_new(ERROR_HTTPS_HANDSHAKE, "handshake r0=%d, r1=%d", r0, r1);
9696
}
@@ -121,7 +121,8 @@ srs_error_t SrsSslClient::handshake()
121121
return srs_error_new(ERROR_HTTPS_HANDSHAKE, "BIO_write r0=%d, data=%p, size=%d", r0, buf, nn);
122122
}
123123

124-
if ((r0 = SSL_do_handshake(ssl)) != -1 || (r1 = SSL_get_error(ssl, r0)) != SSL_ERROR_WANT_READ) {
124+
r0 = SSL_do_handshake(ssl); r1 = SSL_get_error(ssl, r0); ERR_clear_error();
125+
if (r0 != -1 || r1 != SSL_ERROR_WANT_READ) {
125126
return srs_error_new(ERROR_HTTPS_HANDSHAKE, "handshake r0=%d, r1=%d", r0, r1);
126127
}
127128

@@ -159,7 +160,7 @@ srs_error_t SrsSslClient::handshake()
159160
return srs_error_new(ERROR_HTTPS_HANDSHAKE, "BIO_write r0=%d, data=%p, size=%d", r0, buf, nn);
160161
}
161162

162-
r0 = SSL_do_handshake(ssl); r1 = SSL_get_error(ssl, r0);
163+
r0 = SSL_do_handshake(ssl); r1 = SSL_get_error(ssl, r0); ERR_clear_error();
163164
if (r0 == 1 && r1 == SSL_ERROR_NONE) {
164165
break;
165166
}
@@ -180,7 +181,7 @@ srs_error_t SrsSslClient::read(void* plaintext, size_t nn_plaintext, ssize_t* nr
180181
srs_error_t err = srs_success;
181182

182183
while (true) {
183-
int r0 = SSL_read(ssl, plaintext, nn_plaintext); int r1 = SSL_get_error(ssl, r0);
184+
int r0 = SSL_read(ssl, plaintext, nn_plaintext); int r1 = SSL_get_error(ssl, r0); ERR_clear_error();
184185
int r2 = BIO_ctrl_pending(bio_in); int r3 = SSL_is_init_finished(ssl);
185186

186187
// OK, got data.
@@ -228,7 +229,7 @@ srs_error_t SrsSslClient::write(void* plaintext, size_t nn_plaintext, ssize_t* n
228229
for (char* p = (char*)plaintext; p < (char*)plaintext + nn_plaintext;) {
229230
int left = (int)nn_plaintext - (p - (char*)plaintext);
230231
int r0 = SSL_write(ssl, (const void*)p, left);
231-
int r1 = SSL_get_error(ssl, r0);
232+
int r1 = SSL_get_error(ssl, r0); ERR_clear_error();
232233
if (r0 <= 0) {
233234
return srs_error_new(ERROR_HTTPS_WRITE, "https: write data=%p, size=%d, r0=%d, r1=%d", p, left, r0, r1);
234235
}

trunk/src/protocol/srs_protocol_http_client.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <map>
1414

1515
#include <openssl/ssl.h>
16+
#include <openssl/err.h>
1617

1718
#include <srs_protocol_st.hpp>
1819
#include <srs_protocol_http_stack.hpp>

0 commit comments

Comments
 (0)