]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
further fix up parsing hex strings with spaces in odd places (it rhymes!)
authorBert Hubert <bert.hubert@netherlabs.nl>
Fri, 21 Jan 2011 12:49:09 +0000 (12:49 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Fri, 21 Jan 2011 12:49:09 +0000 (12:49 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1902 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/rcpgenerator.cc

index 4f6d820eb7fb8b336d566583c64882647fa7670c..12eb96911c74d8a55440b3941d692364ebcdeef1 100644 (file)
@@ -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)