From: Remi Gacogne Date: Thu, 30 Jan 2020 14:11:53 +0000 (+0100) Subject: DNSName: Don't call strlen() when the length is already known X-Git-Tag: auth-4.3.0-beta2~30^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F8792%2Fhead;p=thirdparty%2Fpdns.git DNSName: Don't call strlen() when the length is already known --- diff --git a/pdns/dnslabeltext.rl b/pdns/dnslabeltext.rl index fe64966fd0..826f666845 100644 --- a/pdns/dnslabeltext.rl +++ b/pdns/dnslabeltext.rl @@ -83,7 +83,7 @@ vector segmentDNSText(const string& input ) }; -DNSName::string_t segmentDNSNameRaw(const char* realinput) +DNSName::string_t segmentDNSNameRaw(const char* realinput, size_t inputlen) { %%{ machine dnsnameraw; @@ -100,7 +100,6 @@ DNSName::string_t segmentDNSNameRaw(const char* realinput) return ret; } - unsigned int inputlen=strlen(realinput); ret.reserve(inputlen+1); const char *p = realinput, *pe = realinput + inputlen; diff --git a/pdns/dnsname.cc b/pdns/dnsname.cc index b2936ec757..c262d28202 100644 --- a/pdns/dnsname.cc +++ b/pdns/dnsname.cc @@ -41,7 +41,7 @@ std::ostream & operator<<(std::ostream &os, const DNSName& d) return os < 255) { throw std::range_error("name too long"); } diff --git a/pdns/dnsname.hh b/pdns/dnsname.hh index 5028273070..ee04ea610a 100644 --- a/pdns/dnsname.hh +++ b/pdns/dnsname.hh @@ -62,8 +62,9 @@ class DNSName { public: DNSName() {} //!< Constructs an *empty* DNSName, NOT the root! - explicit DNSName(const char* p); //!< Constructs from a human formatted, escaped presentation - explicit DNSName(const std::string& str) : DNSName(str.c_str()) {}; //!< Constructs from a human formatted, escaped presentation + explicit DNSName(const char* p): DNSName(p, strlen(p)) {} //!< Constructs from a human formatted, escaped presentation + explicit DNSName(const char* p, size_t len); //!< Constructs from a human formatted, escaped presentation + explicit DNSName(const std::string& str) : DNSName(str.c_str(), str.length()) {}; //!< Constructs from a human formatted, escaped presentation DNSName(const char* p, int len, int offset, bool uncompress, uint16_t* qtype=nullptr, uint16_t* qclass=nullptr, unsigned int* consumed=nullptr, uint16_t minOffset=0); //!< Construct from a DNS Packet, taking the first question if offset=12. If supplied, consumed is set to the number of bytes consumed from the packet, which will not be equal to the wire length of the resulting name in case of compression. bool isPartOf(const DNSName& rhs) const; //!< Are we part of the rhs name? @@ -468,7 +469,7 @@ namespace std { }; } -DNSName::string_t segmentDNSNameRaw(const char* input); // from ragel +DNSName::string_t segmentDNSNameRaw(const char* input, size_t inputlen); // from ragel bool DNSName::operator==(const DNSName& rhs) const { if(rhs.empty() != empty() || rhs.d_storage.size() != d_storage.size()) diff --git a/pdns/dnswriter.hh b/pdns/dnswriter.hh index 16048f16e7..fbfcd4739a 100644 --- a/pdns/dnswriter.hh +++ b/pdns/dnswriter.hh @@ -173,5 +173,4 @@ private: typedef vector > labelparts_t; // bool labeltokUnescape(labelparts_t& parts, const DNSName& label); std::vector segmentDNSText(const string& text); // from dnslabeltext.rl -std::deque segmentDNSName(const string& input ); // from dnslabeltext.rl #endif