Home page logo
/

nmap-dev logo Nmap Development mailing list archives

[PATCH] Remove unnecessary bitwise ANDs in nmap_dns.cc
From: "Kris Katterjohn" <kjak () ispwest com>
Date: Wed, 22 Feb 2006 06:43:16 -0800

These pointers to/arrays of unsigned char's are currently being ANDed with 0xFF,
which isn't necessary because 0xFF is the highest value for unsigned char's.

I'm kinda in a hurry this morning, but I don't think I forgot anything.

Thanks,
Kris Katterjohn

--- nmap_dns.cc.orig    2006-02-22 08:36:51.000000000 -0600
+++ nmap_dns.cc 2006-02-22 08:41:09.000000000 -0600
@@ -443,7 +443,7 @@ int advance_past_dns_name(unsigned char 
 
     // Compression is OK
     compression = curbuf+2;
-    curbuf = ((buf[curbuf+1] & 0xFF) + ((buf[curbuf] & 0xFF) << 8)) & 0x3FFF;
+    curbuf = (buf[curbuf+1] + (buf[curbuf] << 8)) & 0x3FFF;
     if (curbuf < 0 || curbuf >= buflen) return -1;
   }
 
@@ -485,7 +485,7 @@ void read_evt_handler(nsock_pool nsp, ns
   // Size of header is 12, and we must have additional data as well
   if (buflen <= 12) return;
 
-  packet_id = (buf[1] & 0xFF) + ((buf[0] & 0xFF) << 8);
+  packet_id = buf[1] + (buf[0] << 8);
 
   // Check that this is a response, standard query, and that no truncation was performed
   // 0xFA == 11111010 (we're not concerned with AA or RD bits)
@@ -493,14 +493,14 @@ void read_evt_handler(nsock_pool nsp, ns
 
   // Check that Recursion is available, the zero field is all zeros
   // and there is no error condition:
-  if ((buf[3] & 0xFF) != 0x80) {
+  if (buf[3] != 0x80) {
     if ((buf[3] & 0xF) == 2) errcode = 2;
     else if ((buf[3] & 0xF) == 3) errcode = 3;
     else return;
   }
 
-  queries = (buf[5] & 0xFF) + ((buf[4] & 0xFF) << 8);
-  answers = (buf[7] & 0xFF) + ((buf[6] & 0xFF) << 8);
+  queries = buf[5] + (buf[4] << 8);
+  answers = buf[7] + (buf[6] << 8);
 
   // With a normal resolution, we should have 1+ queries and 1+ answers.
   // If the domain doesn't resolve (NXDOMAIN or SERVFAIL) we should have
@@ -549,9 +549,9 @@ void read_evt_handler(nsock_pool nsp, ns
     // RDLENGTH (2) fields
     if (curbuf + 10 >= buflen) return;
 
-    atype = (buf[curbuf+1] & 0xFF) + ((buf[curbuf+0] & 0xFF) << 8);
-    aclass = (buf[curbuf+3] & 0xFF) + ((buf[curbuf+2] & 0xFF) << 8);
-    rdlen = (buf[curbuf+9] & 0xFF) + ((buf[curbuf+8] & 0xFF) << 8);
+    atype = buf[curbuf+1] + (buf[curbuf+0] << 8);
+    aclass = buf[curbuf+3] + (buf[curbuf+2] << 8);
+    rdlen = buf[curbuf+9] + (buf[curbuf+8] << 8);
     curbuf += 10;
 
     if (atype == 12 && aclass == 1) {




_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev


  By Date           By Thread  

Current thread:
  • [PATCH] Remove unnecessary bitwise ANDs in nmap_dns.cc Kris Katterjohn (Feb 22)
[ Nmap | Sec Tools | Mailing Lists | Site News | About/Contact | Advertising | Privacy ]
AlienVault