Skip to content

Commit e82dc11

Browse files
ossrs-aiwinlinvip
authored andcommitted
Bridge: Fix heap-use-after-free in SrsCompositeBridge iterator. v6.0.183 (#4535)
1 parent fcb2992 commit e82dc11

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

trunk/doc/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The changelog for SRS.
77
<a name="v6-changes"></a>
88

99
## SRS 6.0 Changelog
10+
* v6.0, 2025-10-21, Merge [#4535](https://github.com/ossrs/srs/issues/4535): Bridge: Fix heap-use-after-free in SrsCompositeBridge iterator. v6.0.183 (#4535)
1011
* v6.0, 2025-10-17, Merge [#4534](https://github.com/ossrs/srs/pull/4534): HLS: Fix a iterator bug in hls_ctx cleanup function. v6.0.182 (#4534)
1112
* v6.0, 2025-10-14, Disable sanitizer by default to fix memory leak. (#4364) v6.0.181
1213
* v6.0, 2025-10-01, SRT: Support configurable default_streamid option. v6.0.180

trunk/src/app/srs_app_stream_bridge.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,10 @@ srs_error_t SrsCompositeBridge::initialize(SrsRequest* r)
173173
{
174174
srs_error_t err = srs_success;
175175

176-
for (vector<ISrsStreamBridge*>::iterator it = bridges_.begin(); it != bridges_.end(); ++it) {
176+
// Make a copy of bridges to avoid iterator invalidation if bridges_ is modified during iteration.
177+
// See https://github.com/ossrs/srs/issues/4535
178+
vector<ISrsStreamBridge*> bridges_copy = bridges_;
179+
for (vector<ISrsStreamBridge*>::iterator it = bridges_copy.begin(); it != bridges_copy.end(); ++it) {
177180
ISrsStreamBridge* bridge = *it;
178181
if ((err = bridge->initialize(r)) != srs_success) {
179182
return err;
@@ -187,7 +190,10 @@ srs_error_t SrsCompositeBridge::on_publish()
187190
{
188191
srs_error_t err = srs_success;
189192

190-
for (vector<ISrsStreamBridge*>::iterator it = bridges_.begin(); it != bridges_.end(); ++it) {
193+
// Make a copy of bridges to avoid iterator invalidation if bridges_ is modified during iteration.
194+
// See https://github.com/ossrs/srs/issues/4535
195+
vector<ISrsStreamBridge*> bridges_copy = bridges_;
196+
for (vector<ISrsStreamBridge*>::iterator it = bridges_copy.begin(); it != bridges_copy.end(); ++it) {
191197
ISrsStreamBridge* bridge = *it;
192198
if ((err = bridge->on_publish()) != srs_success) {
193199
return err;
@@ -199,7 +205,10 @@ srs_error_t SrsCompositeBridge::on_publish()
199205

200206
void SrsCompositeBridge::on_unpublish()
201207
{
202-
for (vector<ISrsStreamBridge*>::iterator it = bridges_.begin(); it != bridges_.end(); ++it) {
208+
// Make a copy of bridges to avoid iterator invalidation if bridges_ is modified during iteration.
209+
// See https://github.com/ossrs/srs/issues/4535
210+
vector<ISrsStreamBridge*> bridges_copy = bridges_;
211+
for (vector<ISrsStreamBridge*>::iterator it = bridges_copy.begin(); it != bridges_copy.end(); ++it) {
203212
ISrsStreamBridge* bridge = *it;
204213
bridge->on_unpublish();
205214
}

trunk/src/core/srs_core_version6.hpp

Lines changed: 1 addition & 1 deletion
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 182
12+
#define VERSION_REVISION 183
1313

1414
#endif

0 commit comments

Comments
 (0)