]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
DNSName constructor use memchr instead of strchr.
authorAxel Viala <axel.viala@darnuria.eu>
Thu, 18 Aug 2022 10:31:04 +0000 (12:31 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 30 Nov 2022 13:21:54 +0000 (14:21 +0100)
Also check length before dereferencing.
Rational for this change:

- Why using strchr if we have a length?
- Accepting char * p that doesn't contains `\0`.

pdns/dnsname.cc

index a44f6d09f60c4a34a174c88e97a28b52c940fe80..4dde8c3982faa3541480563bf45db77b3420620f 100644 (file)
@@ -55,10 +55,10 @@ void DNSName::throwSafeRangeError(const std::string& msg, const char* buf, size_
 
 DNSName::DNSName(const char* p, size_t length)
 {
-  if(p[0]==0 || (p[0]=='.' && p[1]==0)) {
+  if(length == 0 || p[0]==0 || (p[0]=='.' && p[1]==0)) {
     d_storage.assign(1, (char)0);
   } else {
-    if(!strchr(p, '\\')) {
+    if(!std::memchr(p, '\\', length)) {
       unsigned char lenpos=0;
       unsigned char labellen=0;
       size_t plen=length;