This is an automated email from the ASF dual-hosted git repository.

chenBright pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git


The following commit(s) were added to refs/heads/master by this push:
     new 36c2d12e Validate remote file service names before parsing (#3608)
36c2d12e is described below

commit 36c2d12e0f56b2a306f66e189d6f399b875d9c95
Author: songgaoye <[email protected]>
AuthorDate: Fri Oct 16 14:26:48 2026 +0800

    Validate remote file service names before parsing (#3608)
    
    * Validate remote file service names before parsing
    
    * Use range-based loop in naming service test
---
 src/brpc/policy/remote_file_naming_service.cpp |  7 ++++++-
 test/brpc_naming_service_unittest.cpp          | 12 ++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/brpc/policy/remote_file_naming_service.cpp 
b/src/brpc/policy/remote_file_naming_service.cpp
index b2e92954..a2a83fe4 100644
--- a/src/brpc/policy/remote_file_naming_service.cpp
+++ b/src/brpc/policy/remote_file_naming_service.cpp
@@ -67,7 +67,12 @@ int RemoteFileNamingService::GetServers(const char 
*service_name_cstr,
         butil::StringPiece proto;
         if (pos != butil::StringPiece::npos) {
             proto = tmpname.substr(0, pos);
-            for (pos += 3; tmpname[pos] == '/'; ++pos) {}
+            for (pos += 3; pos < tmpname.size() && tmpname[pos] == '/'; ++pos) 
{}
+            if (pos == tmpname.size()) {
+                LOG(ERROR) << "No server address in service_name="
+                           << service_name_cstr;
+                return -1;
+            }
             tmpname.remove_prefix(pos);
         } else {
             proto = "http";
diff --git a/test/brpc_naming_service_unittest.cpp 
b/test/brpc_naming_service_unittest.cpp
index 2c5ad76d..a01e033f 100644
--- a/test/brpc_naming_service_unittest.cpp
+++ b/test/brpc_naming_service_unittest.cpp
@@ -289,6 +289,18 @@ TEST(NamingServiceTest, remotefile) {
     }
 }
 
+TEST(NamingServiceTest, remotefile_invalid_url) {
+    const char* service_names[] = {
+        "http://";, "bns://", "http:////";
+    };
+    for (const char* service_name : service_names) {
+        brpc::policy::RemoteFileNamingService rfns;
+        std::vector<brpc::ServerNode> servers;
+        EXPECT_EQ(-1, rfns.GetServers(service_name, &servers));
+        EXPECT_TRUE(servers.empty());
+    }
+}
+
 // Build a JSON array nested `depth' levels deep, e.g. depth=2 -> "[[]]".
 static std::string MakeDeeplyNestedJson(int depth) {
     return std::string(depth, '[') + std::string(depth, ']');


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to