This is an automated email from the ASF dual-hosted git repository. lorinlee pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-brpc.git
The following commit(s) were added to refs/heads/master by this push: new 3a3f856e fix: domain name length new 01474e53 Merge pull request #1965 from wayslog/fix/hostname2endpoint 3a3f856e is described below commit 3a3f856e22d4ae7df91c67011120e924e23bc6b2 Author: xuesong.zhao <xuesong.z...@shopee.com> AuthorDate: Tue Oct 25 19:36:36 2022 +0800 fix: domain name length --- src/butil/endpoint.cpp | 11 ++++++++--- src/butil/endpoint.h | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/butil/endpoint.cpp b/src/butil/endpoint.cpp index 498f42e5..a696aa42 100644 --- a/src/butil/endpoint.cpp +++ b/src/butil/endpoint.cpp @@ -304,12 +304,17 @@ int str2endpoint(const char* ip_str, int port, EndPoint* point) { int hostname2endpoint(const char* str, EndPoint* point) { // Should be enough to hold ip address - char buf[64]; + // The definitive descriptions of the rules for forming domain names appear in RFC 1035, RFC 1123, RFC 2181, + // and RFC 5892. The full domain name may not exceed the length of 253 characters in its textual representation + // (Domain Names - Domain Concepts and Facilities. IETF. doi:10.17487/RFC1034. RFC 1034.). + // For cacheline optimize, use buf size as 256; + char buf[256]; size_t i = 0; - for (; i < sizeof(buf) - 1 && str[i] != '\0' && str[i] != ':'; ++i) { + for (; i < MAX_DOMAIN_LENGTH && str[i] != '\0' && str[i] != ':'; ++i) { buf[i] = str[i]; } - if (i == sizeof(buf) - 1) { + + if (i >= MAX_DOMAIN_LENGTH || str[i] != ':') { return -1; } diff --git a/src/butil/endpoint.h b/src/butil/endpoint.h index 11831961..3b9cdf44 100644 --- a/src/butil/endpoint.h +++ b/src/butil/endpoint.h @@ -34,6 +34,7 @@ typedef struct in_addr ip_t; static const ip_t IP_ANY = { INADDR_ANY }; static const ip_t IP_NONE = { INADDR_NONE }; +static const int MAX_DOMAIN_LENGTH = 253; // Convert |ip| to an integral inline in_addr_t ip2int(ip_t ip) { return ip.s_addr; } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org For additional commands, e-mail: dev-h...@brpc.apache.org