From c4da11fcf6e39c9916827024e83be5d069085aec Mon Sep 17 00:00:00 2001 From: Axel Viala Date: Thu, 18 Aug 2022 12:31:04 +0200 Subject: [PATCH] DNSName constructor use memchr instead of strchr. 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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pdns/dnsname.cc b/pdns/dnsname.cc index a44f6d09f6..4dde8c3982 100644 --- a/pdns/dnsname.cc +++ b/pdns/dnsname.cc @@ -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; -- 2.47.2