[tor-commits] [tor/master] Regenerate pwbox.c with the latest trunnel

nickm at torproject.org nickm at torproject.org
Fri Sep 26 13:34:15 UTC 2014


commit 9fd6fbec280ea07326f0d4a0e9289609fafd7ef1
Author: Nick Mathewson <nickm at torproject.org>
Date:   Fri Sep 26 09:33:24 2014 -0400

    Regenerate pwbox.c with the latest trunnel
    
    This one should no longer generate dead-code warnings with coverity.
    Fingers crossed?  This was CID 1241498
---
 src/trunnel/pwbox.c |   47 +++++++++++++++++++++++------------------------
 1 file changed, 23 insertions(+), 24 deletions(-)

diff --git a/src/trunnel/pwbox.c b/src/trunnel/pwbox.c
index b70e1d8..bfea3ac 100644
--- a/src/trunnel/pwbox.c
+++ b/src/trunnel/pwbox.c
@@ -12,6 +12,22 @@
     (obj)->trunnel_error_code_ = 1; \
   } while (0)
 
+#if defined(__COVERITY__) || defined(__clang_analyzer__)
+/* If we're runnning a static analysis tool, we don't want it to complain
+ * that some of our remaining-bytes checks are dead-code. */
+int pwbox_deadcode_dummy__ = 0;
+#define OR_DEADCODE_DUMMY || pwbox_deadcode_dummy__
+#else
+#define OR_DEADCODE_DUMMY
+#endif
+
+#define CHECK_REMAINING(nbytes, label)                           \
+  do {                                                           \
+    if (remaining < (nbytes) OR_DEADCODE_DUMMY) {                \
+      goto label;                                                \
+    }                                                            \
+  } while (0)
+
 pwbox_encoded_t *
 pwbox_encoded_new(void)
 {
@@ -422,49 +438,38 @@ pwbox_encoded_parse_into(pwbox_encoded_t *obj, const uint8_t *input, const size_
   (void)result;
 
   /* Parse u32 fixedbytes0 IN [PWBOX0_CONST0] */
-  if (remaining < 4)
-    goto truncated;
+  CHECK_REMAINING(4, truncated);
   obj->fixedbytes0 = trunnel_ntohl(trunnel_get_uint32(ptr));
   remaining -= 4; ptr += 4;
   if (! (obj->fixedbytes0 == PWBOX0_CONST0))
     goto fail;
 
   /* Parse u32 fixedbytes1 IN [PWBOX0_CONST1] */
-  if (remaining < 4)
-    goto truncated;
+  CHECK_REMAINING(4, truncated);
   obj->fixedbytes1 = trunnel_ntohl(trunnel_get_uint32(ptr));
   remaining -= 4; ptr += 4;
   if (! (obj->fixedbytes1 == PWBOX0_CONST1))
     goto fail;
 
   /* Parse u8 header_len */
-  if (remaining < 1)
-    goto truncated;
+  CHECK_REMAINING(1, truncated);
   obj->header_len = (trunnel_get_uint8(ptr));
   remaining -= 1; ptr += 1;
 
   /* Parse u8 skey_header[header_len] */
-  if (remaining < obj->header_len)
-    goto truncated;
+  CHECK_REMAINING(obj->header_len, truncated);
   TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->skey_header, obj->header_len, {});
   obj->skey_header.n_ = obj->header_len;
   memcpy(obj->skey_header.elts_, ptr, obj->header_len);
   ptr += obj->header_len; remaining -= obj->header_len;
 
   /* Parse u8 iv[16] */
-  if (remaining < (16))
-    goto truncated;
+  CHECK_REMAINING(16, truncated);
   memcpy(obj->iv, ptr, 16);
-  {
-    unsigned idx;
-    for (idx = 0; idx < 16; ++idx)
-      obj->iv[idx] = (obj->iv[idx]);
-  }
   remaining -= 16; ptr += 16;
   {
     size_t remaining_after;
-    if (remaining < 32)
-       goto truncated;
+    CHECK_REMAINING(32, truncated);
     remaining_after = 32;
     remaining = remaining - 32;
 
@@ -479,14 +484,8 @@ pwbox_encoded_parse_into(pwbox_encoded_t *obj, const uint8_t *input, const size_
   }
 
   /* Parse u8 hmac[32] */
-  if (remaining < (32))
-    goto truncated;
+  CHECK_REMAINING(32, truncated);
   memcpy(obj->hmac, ptr, 32);
-  {
-    unsigned idx;
-    for (idx = 0; idx < 32; ++idx)
-      obj->hmac[idx] = (obj->hmac[idx]);
-  }
   remaining -= 32; ptr += 32;
   trunnel_assert(ptr + remaining == input + len_in);
   return len_in - remaining;



More information about the tor-commits mailing list