Browse Source

[2749] Update rest of tree to use the modified io_utilities.h API

Mukund Sivaraman 11 years ago
parent
commit
c7aeb4bec3

+ 8 - 7
src/bin/dhcp6/dhcp6_srv.cc

@@ -604,9 +604,10 @@ Dhcpv6Srv::generateServerID() {
         seconds -= DUID_TIME_EPOCH;
         seconds -= DUID_TIME_EPOCH;
 
 
         OptionBuffer srvid(8 + iface->getMacLen());
         OptionBuffer srvid(8 + iface->getMacLen());
-        writeUint16(DUID::DUID_LLT, &srvid[0]);
-        writeUint16(HWTYPE_ETHERNET, &srvid[2]);
-        writeUint32(static_cast<uint32_t>(seconds), &srvid[4]);
+        writeUint16(DUID::DUID_LLT, &srvid[0], srvid.size());
+        writeUint16(HWTYPE_ETHERNET, &srvid[2], srvid.size() - 2);
+        writeUint32(static_cast<uint32_t>(seconds), &srvid[4],
+                    srvid.size() - 4);
         memcpy(&srvid[0] + 8, iface->getMac(), iface->getMacLen());
         memcpy(&srvid[0] + 8, iface->getMac(), iface->getMacLen());
 
 
         serverid_ = OptionPtr(new Option(Option::V6, D6O_SERVERID,
         serverid_ = OptionPtr(new Option(Option::V6, D6O_SERVERID,
@@ -620,8 +621,8 @@ Dhcpv6Srv::generateServerID() {
     // See Section 9.3 of RFC3315 for details.
     // See Section 9.3 of RFC3315 for details.
 
 
     OptionBuffer srvid(12);
     OptionBuffer srvid(12);
-    writeUint16(DUID::DUID_EN, &srvid[0]);
-    writeUint32(ENTERPRISE_ID_ISC, &srvid[2]);
+    writeUint16(DUID::DUID_EN, &srvid[0], srvid.size());
+    writeUint32(ENTERPRISE_ID_ISC, &srvid[2], srvid.size() - 2);
 
 
     // Length of the identifier is company specific. I hereby declare
     // Length of the identifier is company specific. I hereby declare
     // ISC "standard" of 6 bytes long pseudo-random numbers.
     // ISC "standard" of 6 bytes long pseudo-random numbers.
@@ -2344,10 +2345,10 @@ Dhcpv6Srv::unpackOptions(const OptionBuffer& buf,
     // The buffer being read comprises a set of options, each starting with
     // The buffer being read comprises a set of options, each starting with
     // a two-byte type code and a two-byte length field.
     // a two-byte type code and a two-byte length field.
     while (offset + 4 <= length) {
     while (offset + 4 <= length) {
-        uint16_t opt_type = isc::util::readUint16(&buf[offset]);
+        uint16_t opt_type = isc::util::readUint16(&buf[offset], 2);
         offset += 2;
         offset += 2;
 
 
-        uint16_t opt_len = isc::util::readUint16(&buf[offset]);
+        uint16_t opt_len = isc::util::readUint16(&buf[offset], 2);
         offset += 2;
         offset += 2;
 
 
         if (offset + opt_len > length) {
         if (offset + opt_len > length) {

+ 1 - 1
src/lib/asiodns/io_fetch.cc

@@ -162,7 +162,7 @@ struct IOFetchData {
     // we sent.
     // we sent.
     bool responseOK() {
     bool responseOK() {
         return (*remote_snd == *remote_rcv && cumulative >= 2 &&
         return (*remote_snd == *remote_rcv && cumulative >= 2 &&
-                readUint16(received->getData()) == qid);
+                readUint16(received->getData(), received->getLength()) == qid);
     }
     }
 };
 };
 
 

+ 5 - 2
src/lib/asiodns/tests/io_fetch_unittest.cc

@@ -280,7 +280,7 @@ public:
         cumulative_ += length;
         cumulative_ += length;
         bool complete = false;
         bool complete = false;
         if (cumulative_ > 2) {
         if (cumulative_ > 2) {
-            uint16_t dns_length = readUint16(receive_buffer_);
+            uint16_t dns_length = readUint16(receive_buffer_, sizeof (receive_buffer_));
             complete = ((dns_length + 2) == cumulative_);
             complete = ((dns_length + 2) == cumulative_);
         }
         }
 
 
@@ -310,7 +310,10 @@ public:
         send_buffer_.clear();
         send_buffer_.clear();
         send_buffer_.push_back(0);
         send_buffer_.push_back(0);
         send_buffer_.push_back(0);
         send_buffer_.push_back(0);
-        writeUint16(return_data_.size(), &send_buffer_[0]);
+        // send_buffer_.capacity() seems more logical below, but the
+        // code above fills in the first two bytes and size() becomes 2
+        // (sizeof uint16_t).
+        writeUint16(return_data_.size(), &send_buffer_[0], send_buffer_.size());
         copy(return_data_.begin(), return_data_.end(), back_inserter(send_buffer_));
         copy(return_data_.begin(), return_data_.end(), back_inserter(send_buffer_));
         if (return_data_.size() >= 2) {
         if (return_data_.size() >= 2) {
             send_buffer_[2] = qid_0;
             send_buffer_[2] = qid_0;

+ 1 - 1
src/lib/asiolink/tcp_socket.h

@@ -358,7 +358,7 @@ TCPSocket<C>::processReceivedData(const void* staging, size_t length,
         }
         }
 
 
         // Have enough data to interpret the packet count, so do so now.
         // Have enough data to interpret the packet count, so do so now.
-        expected = isc::util::readUint16(data);
+        expected = isc::util::readUint16(data, cumulative);
 
 
         // We have two bytes less of data to process.  Point to the start of the
         // We have two bytes less of data to process.  Point to the start of the
         // data and adjust the packet size.  Note that at this point,
         // data and adjust the packet size.  Note that at this point,

+ 3 - 3
src/lib/asiolink/tests/tcp_socket_unittest.cc

@@ -227,7 +227,7 @@ serverRead(tcp::socket& socket, TCPCallback& server_cb) {
         // If we have read at least two bytes, we can work out how much we
         // If we have read at least two bytes, we can work out how much we
         // should be reading.
         // should be reading.
         if (server_cb.cumulative() >= 2) {
         if (server_cb.cumulative() >= 2) {
-           server_cb.expected() = readUint16(server_cb.data());
+            server_cb.expected() = readUint16(server_cb.data(), server_cb.length());
             if ((server_cb.expected() + 2) == server_cb.cumulative()) {
             if ((server_cb.expected() + 2) == server_cb.cumulative()) {
 
 
                 // Amount of data read from socket equals the size of the
                 // Amount of data read from socket equals the size of the
@@ -261,7 +261,7 @@ TEST(TCPSocket, processReceivedData) {
     }
     }
 
 
     // Check that the method will handle various receive sizes.
     // Check that the method will handle various receive sizes.
-    writeUint16(PACKET_SIZE, inbuff);
+    writeUint16(PACKET_SIZE, inbuff, sizeof (inbuff));
 
 
     cumulative = 0;
     cumulative = 0;
     offset = 0;
     offset = 0;
@@ -408,7 +408,7 @@ TEST(TCPSocket, SequenceTest) {
     server_cb.length() = 0;
     server_cb.length() = 0;
     server_cb.cumulative() = 0;
     server_cb.cumulative() = 0;
 
 
-    writeUint16(sizeof(INBOUND_DATA), server_cb.data());
+    writeUint16(sizeof(INBOUND_DATA), server_cb.data(), 2);
     copy(INBOUND_DATA, (INBOUND_DATA + sizeof(INBOUND_DATA) - 1),
     copy(INBOUND_DATA, (INBOUND_DATA + sizeof(INBOUND_DATA) - 1),
         (server_cb.data() + 2));
         (server_cb.data() + 2));
     server_socket.async_send(asio::buffer(server_cb.data(),
     server_socket.async_send(asio::buffer(server_cb.data(),

+ 1 - 1
src/lib/asiolink/tests/udp_socket_unittest.cc

@@ -188,7 +188,7 @@ TEST(UDPSocket, processReceivedData) {
     // two bytes of the buffer.
     // two bytes of the buffer.
     uint16_t count = 0;
     uint16_t count = 0;
     for (uint32_t i = 0; i < (2 << 16); ++i, ++count) {
     for (uint32_t i = 0; i < (2 << 16); ++i, ++count) {
-        writeUint16(count, inbuff);
+        writeUint16(count, inbuff, sizeof (inbuff));
 
 
         // Set some random values
         // Set some random values
         cumulative = 5;
         cumulative = 5;

+ 4 - 4
src/lib/dhcp/libdhcp++.cc

@@ -223,10 +223,10 @@ size_t LibDHCP::unpackOptions6(const OptionBuffer& buf,
     // The buffer being read comprises a set of options, each starting with
     // The buffer being read comprises a set of options, each starting with
     // a two-byte type code and a two-byte length field.
     // a two-byte type code and a two-byte length field.
     while (offset + 4 <= length) {
     while (offset + 4 <= length) {
-        uint16_t opt_type = isc::util::readUint16(&buf[offset]);
+        uint16_t opt_type = isc::util::readUint16(&buf[offset], 2);
         offset += 2;
         offset += 2;
 
 
-        uint16_t opt_len = isc::util::readUint16(&buf[offset]);
+        uint16_t opt_len = isc::util::readUint16(&buf[offset], 2);
         offset += 2;
         offset += 2;
 
 
         if (offset + opt_len > length) {
         if (offset + opt_len > length) {
@@ -405,10 +405,10 @@ size_t LibDHCP::unpackVendorOptions6(const uint32_t vendor_id,
     // The buffer being read comprises a set of options, each starting with
     // The buffer being read comprises a set of options, each starting with
     // a two-byte type code and a two-byte length field.
     // a two-byte type code and a two-byte length field.
     while (offset + 4 <= length) {
     while (offset + 4 <= length) {
-        uint16_t opt_type = isc::util::readUint16(&buf[offset]);
+        uint16_t opt_type = isc::util::readUint16(&buf[offset], 2);
         offset += 2;
         offset += 2;
 
 
-        uint16_t opt_len = isc::util::readUint16(&buf[offset]);
+        uint16_t opt_len = isc::util::readUint16(&buf[offset], 2);
         offset += 2;
         offset += 2;
 
 
         if (offset + opt_len > length) {
         if (offset + opt_len > length) {

+ 4 - 4
src/lib/dhcp/option.cc

@@ -255,7 +255,7 @@ uint16_t Option::getUint16() {
                   << " that has size " << data_.size());
                   << " that has size " << data_.size());
     }
     }
 
 
-    return ( readUint16(&data_[0]) );
+    return (readUint16(&data_[0], data_.size()));
 }
 }
 
 
 uint32_t Option::getUint32() {
 uint32_t Option::getUint32() {
@@ -263,7 +263,7 @@ uint32_t Option::getUint32() {
         isc_throw(OutOfRange, "Attempt to read uint32 from option " << type_
         isc_throw(OutOfRange, "Attempt to read uint32 from option " << type_
                   << " that has size " << data_.size());
                   << " that has size " << data_.size());
     }
     }
-    return ( readUint32(&data_[0]) );
+    return (readUint32(&data_[0], data_.size()));
 }
 }
 
 
 void Option::setUint8(uint8_t value) {
 void Option::setUint8(uint8_t value) {
@@ -273,12 +273,12 @@ void Option::setUint8(uint8_t value) {
 
 
 void Option::setUint16(uint16_t value) {
 void Option::setUint16(uint16_t value) {
   data_.resize(2);
   data_.resize(2);
-  writeUint16(value, &data_[0]);
+  writeUint16(value, &data_[0], data_.size());
 }
 }
 
 
 void Option::setUint32(uint32_t value) {
 void Option::setUint32(uint32_t value) {
   data_.resize(4);
   data_.resize(4);
-  writeUint32(value, &data_[0]);
+  writeUint32(value, &data_[0], data_.size());
 }
 }
 
 
 bool Option::equal(const OptionPtr& other) const {
 bool Option::equal(const OptionPtr& other) const {

+ 1 - 1
src/lib/dhcp/option4_addrlst.cc

@@ -53,7 +53,7 @@ Option4AddrLst::Option4AddrLst(uint8_t type, OptionBufferConstIter first,
 
 
     while (first != last) {
     while (first != last) {
         const uint8_t* ptr = &(*first);
         const uint8_t* ptr = &(*first);
-        addAddress(IOAddress(readUint32(ptr)));
+        addAddress(IOAddress(readUint32(ptr, distance(first, last))));
         first += V4ADDRESS_LEN;
         first += V4ADDRESS_LEN;
     }
     }
 }
 }

+ 3 - 3
src/lib/dhcp/option6_ia.cc

@@ -72,12 +72,12 @@ void Option6IA::unpack(OptionBufferConstIter begin,
     if (distance(begin, end) < OPTION6_IA_LEN) {
     if (distance(begin, end) < OPTION6_IA_LEN) {
         isc_throw(OutOfRange, "Option " << type_ << " truncated");
         isc_throw(OutOfRange, "Option " << type_ << " truncated");
     }
     }
-    iaid_ = readUint32( &(*begin) );
+    iaid_ = readUint32(&(*begin), distance(begin, end));
     begin += sizeof(uint32_t);
     begin += sizeof(uint32_t);
-    t1_ = readUint32( &(*begin) );
+    t1_ = readUint32(&(*begin), distance(begin, end));
     begin += sizeof(uint32_t);
     begin += sizeof(uint32_t);
 
 
-    t2_ = readUint32( &(*begin) );
+    t2_ = readUint32(&(*begin), distance(begin, end));
     begin += sizeof(uint32_t);
     begin += sizeof(uint32_t);
 
 
     unpackOptions(OptionBuffer(begin, end));
     unpackOptions(OptionBuffer(begin, end));

+ 2 - 2
src/lib/dhcp/option6_iaaddr.cc

@@ -79,10 +79,10 @@ void Option6IAAddr::unpack(OptionBuffer::const_iterator begin,
     addr_ = IOAddress::fromBytes(AF_INET6, &(*begin));
     addr_ = IOAddress::fromBytes(AF_INET6, &(*begin));
     begin += V6ADDRESS_LEN;
     begin += V6ADDRESS_LEN;
 
 
-    preferred_ = readUint32( &(*begin) );
+    preferred_ = readUint32(&(*begin), distance(begin, end));
     begin += sizeof(uint32_t);
     begin += sizeof(uint32_t);
 
 
-    valid_ = readUint32( &(*begin) );
+    valid_ = readUint32(&(*begin), distance(begin, end));
     begin += sizeof(uint32_t);
     begin += sizeof(uint32_t);
 
 
     unpackOptions(OptionBuffer(begin, end));
     unpackOptions(OptionBuffer(begin, end));

+ 2 - 2
src/lib/dhcp/option6_iaprefix.cc

@@ -76,10 +76,10 @@ void Option6IAPrefix::unpack(OptionBuffer::const_iterator begin,
         isc_throw(OutOfRange, "Option " << type_ << " truncated");
         isc_throw(OutOfRange, "Option " << type_ << " truncated");
     }
     }
 
 
-    preferred_ = readUint32( &(*begin) );
+    preferred_ = readUint32(&(*begin), distance(begin, end));
     begin += sizeof(uint32_t);
     begin += sizeof(uint32_t);
 
 
-    valid_ = readUint32( &(*begin) );
+    valid_ = readUint32(&(*begin), distance(begin, end));
     begin += sizeof(uint32_t);
     begin += sizeof(uint32_t);
 
 
     prefix_len_ = *begin;
     prefix_len_ = *begin;

+ 4 - 4
src/lib/dhcp/option_data_types.h

@@ -298,12 +298,12 @@ public:
         case 2:
         case 2:
             // Calling readUint16 works either for unsigned
             // Calling readUint16 works either for unsigned
             // or signed types.
             // or signed types.
-            value = isc::util::readUint16(&(*buf.begin()));
+            value = isc::util::readUint16(&(*buf.begin()), buf.size());
             break;
             break;
         case 4:
         case 4:
             // Calling readUint32 works either for unsigned
             // Calling readUint32 works either for unsigned
             // or signed types.
             // or signed types.
-            value = isc::util::readUint32(&(*buf.begin()));
+            value = isc::util::readUint32(&(*buf.begin()), buf.size());
             break;
             break;
         default:
         default:
             // This should not happen because we made checks on data types
             // This should not happen because we made checks on data types
@@ -331,11 +331,11 @@ public:
             break;
             break;
         case 2:
         case 2:
             buf.resize(buf.size() + 2);
             buf.resize(buf.size() + 2);
-            isc::util::writeUint16(static_cast<uint16_t>(value), &buf[buf.size() - 2]);
+            isc::util::writeUint16(static_cast<uint16_t>(value), &buf[buf.size() - 2], 2);
             break;
             break;
         case 4:
         case 4:
             buf.resize(buf.size() + 4);
             buf.resize(buf.size() + 4);
-            isc::util::writeUint32(static_cast<uint32_t>(value), &buf[buf.size() - 4]);
+            isc::util::writeUint32(static_cast<uint32_t>(value), &buf[buf.size() - 4], 4);
             break;
             break;
         default:
         default:
             // The cases above cover whole range of possible data lengths because
             // The cases above cover whole range of possible data lengths because

+ 4 - 2
src/lib/dhcp/option_int.h

@@ -142,10 +142,12 @@ public:
             value_ = *begin;
             value_ = *begin;
             break;
             break;
         case 2:
         case 2:
-            value_ = isc::util::readUint16(&(*begin));
+            value_ = isc::util::readUint16(&(*begin),
+                                           std::distance(begin, end));
             break;
             break;
         case 4:
         case 4:
-            value_ = isc::util::readUint32(&(*begin));
+            value_ = isc::util::readUint32(&(*begin),
+                                           std::distance(begin, end));
             break;
             break;
         default:
         default:
             isc_throw(dhcp::InvalidDataType, "non-integer type");
             isc_throw(dhcp::InvalidDataType, "non-integer type");

+ 4 - 2
src/lib/dhcp/option_int_array.h

@@ -201,10 +201,12 @@ public:
                 values_.push_back(*begin);
                 values_.push_back(*begin);
                 break;
                 break;
             case 2:
             case 2:
-                values_.push_back(isc::util::readUint16(&(*begin)));
+                values_.push_back(isc::util::readUint16(&(*begin),
+                                      std::distance(begin, end)));
                 break;
                 break;
             case 4:
             case 4:
-                values_.push_back(isc::util::readUint32(&(*begin)));
+                values_.push_back(isc::util::readUint32(&(*begin),
+                                      std::distance(begin, end)));
                 break;
                 break;
             default:
             default:
                 isc_throw(dhcp::InvalidDataType, "non-integer type");
                 isc_throw(dhcp::InvalidDataType, "non-integer type");

+ 1 - 1
src/lib/dhcp/option_vendor.cc

@@ -54,7 +54,7 @@ void OptionVendor::unpack(OptionBufferConstIter begin,
                   << ", length=" << distance(begin, end));
                   << ", length=" << distance(begin, end));
     }
     }
 
 
-    vendor_id_ = isc::util::readUint32(&(*begin));
+    vendor_id_ = isc::util::readUint32(&(*begin), distance(begin, end));
 
 
     OptionBuffer vendor_buffer(begin +4, end);
     OptionBuffer vendor_buffer(begin +4, end);
 
 

+ 2 - 1
src/lib/resolve/tests/recursive_query_unittest_2.cc

@@ -462,7 +462,8 @@ public:
         tcp_cumulative_ += length;
         tcp_cumulative_ += length;
         bool complete = false;
         bool complete = false;
         if (tcp_cumulative_ > 2) {
         if (tcp_cumulative_ > 2) {
-            uint16_t dns_length = readUint16(tcp_receive_buffer_);
+            uint16_t dns_length = readUint16(tcp_receive_buffer_,
+                                             sizeof (tcp_receive_buffer_));
             complete = ((dns_length + 2) == tcp_cumulative_);
             complete = ((dns_length + 2) == tcp_cumulative_);
         }
         }
 
 

+ 2 - 1
src/lib/resolve/tests/recursive_query_unittest_3.cc

@@ -336,7 +336,8 @@ public:
         tcp_cumulative_ += length;
         tcp_cumulative_ += length;
         bool complete = false;
         bool complete = false;
         if (tcp_cumulative_ > 2) {
         if (tcp_cumulative_ > 2) {
-            uint16_t dns_length = readUint16(tcp_receive_buffer_);
+            uint16_t dns_length = readUint16(tcp_receive_buffer_,
+                                             sizeof (tcp_receive_buffer_));
             complete = ((dns_length + 2) == tcp_cumulative_);
             complete = ((dns_length + 2) == tcp_cumulative_);
         }
         }