From a441aec3efc64c2d9d9e99f0b7ffaa5651446801 Mon Sep 17 00:00:00 2001 From: dijunkun Date: Tue, 24 Feb 2026 11:10:40 +0800 Subject: [PATCH] [fix] fix SDP parsing offset bug in GetIceUsername --- src/common/common.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/common/common.h b/src/common/common.h index 42fb278..722619f 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -5,7 +5,7 @@ int CommonDummy(); -constexpr size_t HASH_STRING_PIECE(const char *string_piece) { +constexpr size_t HASH_STRING_PIECE(const char* string_piece) { std::size_t result = 0; while (*string_piece) { result = (result * 131) + *string_piece++; @@ -13,17 +13,20 @@ constexpr size_t HASH_STRING_PIECE(const char *string_piece) { return result; } -constexpr size_t operator"" _H(const char *string_piece, size_t) { +constexpr size_t operator"" _H(const char* string_piece, size_t) { return HASH_STRING_PIECE(string_piece); } -inline const std::string GetIceUsername(const std::string &sdp) { +inline const std::string GetIceUsername(const std::string& sdp) { std::string result = ""; std::string start = "ice-ufrag:"; std::string end = "\r\n"; size_t startPos = sdp.find(start); - size_t endPos = sdp.find(end); + size_t endPos = std::string::npos; + if (startPos != std::string::npos) { + endPos = sdp.find(end, startPos + start.length()); + } if (startPos != std::string::npos && endPos != std::string::npos) { result = sdp.substr(startPos + start.length(),