From 4e75f84ac9a0ad451d096d8c9cad58fd3b5574dd Mon Sep 17 00:00:00 2001 From: Bert Hubert Date: Fri, 21 Jan 2011 12:49:09 +0000 Subject: [PATCH] further fix up parsing hex strings with spaces in odd places (it rhymes!) git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1902 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- pdns/rcpgenerator.cc | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/pdns/rcpgenerator.cc b/pdns/rcpgenerator.cc index 4f6d820eb7..12eb96911c 100644 --- a/pdns/rcpgenerator.cc +++ b/pdns/rcpgenerator.cc @@ -223,21 +223,31 @@ static inline uint8_t hextodec(uint8_t val) } -void HEXDecode(const char* begin, const char* end, string& val) +void HEXDecode(const char* begin, const char* end, string& out) { if(end - begin == 1 && *begin=='-') { - val.clear(); + out.clear(); return; } - - if((end - begin)%2) - throw RecordTextException("Hexadecimal blob with odd number of characters"); - - int limit=(int)(end-begin)/2; - val.resize(limit); - for(int n=0; n < limit; ++n) { - val[n] = hextodec(begin[2*n])*16 + hextodec(begin[2*n+1]); + out.clear(); + out.reserve((end-begin)/2); + uint8_t mode=0, val=0; + for(; begin != end; ++begin) { + if(!isalnum(*begin)) + continue; + if(mode==0) { + val = 16*hextodec(*begin); + mode=1; + } else { + val += hextodec(*begin); + out.append(1, (char) val); + mode = 0; + val = 0; + } } + if(mode) + out.append(1, (char) val); + } void RecordTextReader::xfrHexBlob(string& val, bool keepReading) -- 2.47.2