From febd45d514b49934784f5d6f2ef3e628b15e666a Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 10 Aug 2022 10:20:47 +0800 Subject: [PATCH] Fix server id generator bug. v4.0.254 --- trunk/doc/CHANGELOG.md | 1 + trunk/src/app/srs_app_latest_version.cpp | 10 +++++++--- trunk/src/core/srs_core_version4.hpp | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/trunk/doc/CHANGELOG.md b/trunk/doc/CHANGELOG.md index 396350b84..fbf6a3a7b 100644 --- a/trunk/doc/CHANGELOG.md +++ b/trunk/doc/CHANGELOG.md @@ -8,6 +8,7 @@ The changelog for SRS. ## SRS 4.0 Changelog +* v4.0, 2022-08-10, Fix server id generator bug. v4.0.254 * v4.0, 2022-06-29, Update SRS image for r.ossrs.net. v4.0.253 * v4.0, 2022-06-11, For [#3058](https://github.com/ossrs/srs/pull/3058): Docker: Support x86_64, armv7 and aarch64 docker image (#3058). v4.0.252 * v4.0, 2022-03-19, For [#2893](https://github.com/ossrs/srs/pull/2893): SRT: Decouple publish with play url (#2893). v4.0.251 diff --git a/trunk/src/app/srs_app_latest_version.cpp b/trunk/src/app/srs_app_latest_version.cpp index 58d0e3d6c..aacb81e32 100644 --- a/trunk/src/app/srs_app_latest_version.cpp +++ b/trunk/src/app/srs_app_latest_version.cpp @@ -193,11 +193,15 @@ srs_error_t SrsLatestVersion::start() uuid_t uuid; uuid_generate_time(uuid); - char buf[32]; + // Must reserve last 1 byte for the trailing '\0', because we expect the size of uuid string is 32 bytes. + char buf[32 + 1]; + srs_assert(16 == sizeof(uuid_t)); + for (int i = 0; i < 16; i++) { - snprintf(buf + i * 2, sizeof(buf), "%02x", uuid[i]); + int r0 = snprintf(buf + i * 2, sizeof(buf) - i * 2, "%02x", uuid[i]); + srs_assert(r0 > 0 && r0 < sizeof(buf) - i * 2); } - server_id_ = string(buf, sizeof(buf)); + server_id_ = buf; } return trd_->start(); diff --git a/trunk/src/core/srs_core_version4.hpp b/trunk/src/core/srs_core_version4.hpp index ba42c8745..176ca9d78 100644 --- a/trunk/src/core/srs_core_version4.hpp +++ b/trunk/src/core/srs_core_version4.hpp @@ -9,6 +9,6 @@ #define VERSION_MAJOR 4 #define VERSION_MINOR 0 -#define VERSION_REVISION 253 +#define VERSION_REVISION 254 #endif