chenBright commented on code in PR #3741:
URL: https://github.com/apache/brpc/pull/3741#discussion_r4651599007


##########
src/brpc/policy/domain_naming_service.cpp:
##########
@@ -44,15 +45,29 @@ int DomainNamingService::GetServers(const char* dns_name,
     // Should be enough to hold host name
     char buf[256];
     size_t i = 0;
-    for (; i < sizeof(buf) - 1 && dns_name[i] != '\0'
-             && dns_name[i] != ':' && dns_name[i] != '/'; ++i) {
-        buf[i] = dns_name[i];
-    }
-    if (i == sizeof(buf) - 1) {
-        LOG(ERROR) << "dns_name=`" << dns_name << "' is too long";
-        return -1;
+    if (dns_name[0] == '[') {
+        // IPv6 address such as `[::1]:8080'. Keep the brackets, which
+        // butil::str2endpoint() expects.
+        const char* close = strchr(dns_name, ']');
+        if (close == nullptr ||
+            static_cast<size_t>(close - dns_name) + 1 >= sizeof(buf) ||
+            (close[1] != '\0' && close[1] != ':' && close[1] != '/')) {
+            LOG(ERROR) << "Invalid ipv6 address in `" << dns_name << '\'';

Review Comment:
   `http://[::1]?q=1` is a valid URL with an empty path. The load-balancing 
entry point passes `[::1]?q=1` here unchanged, and the current check returns 
`-1`; `[::1]:8080#part` fails the check after the port. Please recognize `?` 
and `#` in both places, and cover the default and explicit port cases 
respectively.



##########
src/brpc/policy/domain_naming_service.cpp:
##########
@@ -79,6 +94,17 @@ int DomainNamingService::GetServers(const char* dns_name,
         return -1;
     }
 
+    if (buf[0] == '[') {
+        // An address, not a name: nothing to resolve.
+        butil::EndPoint point;
+        if (butil::str2endpoint(buf, port, &point) != 0) {

Review Comment:
   The `port` received by `str2endpoint` has already lost its original value. 
On 64-bit Linux/GCC, `[::1]:4294967377` passes the range check and is published 
as `[::1]:81`. Please check `0..65535` while the value is still a `long` before 
converting it to `int`, and add this regression case.



##########
src/brpc/policy/domain_naming_service.cpp:
##########
@@ -79,6 +94,17 @@ int DomainNamingService::GetServers(const char* dns_name,
         return -1;
     }
 
+    if (buf[0] == '[') {
+        // An address, not a name: nothing to resolve.
+        butil::EndPoint point;
+        if (butil::str2endpoint(buf, port, &point) != 0) {
+            LOG(ERROR) << "Invalid ipv6 address in `" << dns_name << '\'';
+            return -1;
+        }
+        servers->push_back(ServerNode(point, std::string()));
+        return 0;

Review Comment:
   This node is also used for `https://[::1]:8443`. When `VERIFY_PEER` is 
enabled, `SetHttpsPeerName` automatically fills in `[::1]`, causing 
`ssl_helper` to use DNS name verification, so the certificate's IP SAN `::1` 
cannot match. Please remove the IPv6 brackets when automatically deriving the 
TLS identity, skip automatic SNI for IP literals, and cover an `rr` call with a 
certificate containing an IP SAN.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to