Bug 1018061: Have mozilla::pkix::der::Input::Read use EnsureLength instead of its own checks, r=mmc
authorBrian Smith <brian@briansmith.org>
Thu, 29 May 2014 23:36:30 -0700
changeset 205451 8a49fdbf8041eef998abd839fb01b6ba423d7a41
parent 205450 917d8912c712c5a0b153967a36c08e849ac2ec1a
child 205452 c470f879b8c8b6534aad748ec930000dbd74a258
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmmc
bugs1018061
milestone32.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1018061: Have mozilla::pkix::der::Input::Read use EnsureLength instead of its own checks, r=mmc
security/pkix/lib/pkixder.h
--- a/security/pkix/lib/pkixder.h
+++ b/security/pkix/lib/pkixder.h
@@ -111,43 +111,43 @@ public:
     this->end = data + len;
 
     return Success;
   }
 
   Result Expect(const uint8_t* expected, uint16_t expectedLen)
   {
     if (EnsureLength(expectedLen) != Success) {
-      return Fail(SEC_ERROR_BAD_DER);
+      return Failure;
     }
     if (memcmp(input, expected, expectedLen)) {
       return Fail(SEC_ERROR_BAD_DER);
     }
     input += expectedLen;
     return Success;
   }
 
   bool Peek(uint8_t expectedByte) const
   {
     return input < end && *input == expectedByte;
   }
 
   Result Read(uint8_t& out)
   {
-    if (input == end) {
-      return Fail(SEC_ERROR_BAD_DER);
+    if (EnsureLength(1) != Success) {
+      return Failure;
     }
     out = *input++;
     return Success;
   }
 
   Result Read(uint16_t& out)
   {
-    if (input == end || input + 1 == end) {
-      return Fail(SEC_ERROR_BAD_DER);
+    if (EnsureLength(2) != Success) {
+      return Failure;
     }
     out = *input++;
     out <<= 8u;
     out |= *input++;
     return Success;
   }
 
   template <uint16_t N>
@@ -186,38 +186,38 @@ public:
     }
     input += totalLen;
     return true;
   }
 
   Result Skip(uint16_t len)
   {
     if (EnsureLength(len) != Success) {
-      return Fail(SEC_ERROR_BAD_DER);
+      return Failure;
     }
     input += len;
     return Success;
   }
 
   Result Skip(uint16_t len, Input& skippedInput)
   {
     if (EnsureLength(len) != Success) {
-      return Fail(SEC_ERROR_BAD_DER);
+      return Failure;
     }
     if (skippedInput.Init(input, len) != Success) {
       return Failure;
     }
     input += len;
     return Success;
   }
 
   Result Skip(uint16_t len, SECItem& skippedItem)
   {
     if (EnsureLength(len) != Success) {
-      return Fail(SEC_ERROR_BAD_DER);
+      return Failure;
     }
     skippedItem.type = siBuffer;
     skippedItem.data = const_cast<uint8_t*>(input);
     skippedItem.len = len;
     input += len;
     return Success;
   }