Enhance PACKET readability
authorMatt Caswell <matt@openssl.org>
Mon, 3 Aug 2015 16:20:47 +0000 (17:20 +0100)
committerMatt Caswell <matt@openssl.org>
Thu, 13 Aug 2015 19:34:51 +0000 (20:34 +0100)
Enhance the PACKET code readability, and fix a stale comment. Thanks
to Ben Kaduk (bkaduk@akamai.com) for pointing this out.

Reviewed-by: Emilia Käsper <emilia@openssl.org>
ssl/packet_locl.h
ssl/s3_srvr.c
ssl/t1_lib.c
test/packettest.c

index 80d0b93fd95bcdf8262d74fa40e3c13ceff9b453..a5e4d00911d01e6b380cae4944d8085e89b1d87e 100644 (file)
@@ -80,8 +80,7 @@ typedef struct {
 } PACKET;
 
 /*
- * Returns 1 if there are exactly |len| bytes left to be read from |pkt|
- * and 0 otherwise
+ * Returns the number of bytes remaining to be read in the PACKET
  */
 __owur static inline size_t PACKET_remaining(PACKET *pkt)
 {
index c723ea0f2d01776419cffa3ace279d7226621e1a..a015a495c7926f4ea1855a4b44f55fbfc7e0ce2d 100644 (file)
@@ -1059,7 +1059,7 @@ int ssl3_get_client_hello(SSL *s)
         memset(s->s3->client_random, 0, SSL3_RANDOM_SIZE);
         if (!PACKET_peek_copy_bytes(&pkt, s->s3->client_random, i)
                 || !PACKET_forward(&pkt, cl)
-                || !PACKET_remaining(&pkt) == 0) {
+                || PACKET_remaining(&pkt) != 0) {
             SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_RECORD_LENGTH_MISMATCH);
             al = SSL_AD_DECODE_ERROR;
             goto f_err;
index ece2b72ac609176bcfe8bd76b7b49fb5aa57919f..e37411ccbf847d8d47ac5caf5ce7521ee3bf307b 100644 (file)
@@ -2036,7 +2036,7 @@ static int ssl_scan_clienthello_tlsext(SSL *s, PACKET *pkt, int *al)
                     }
             }
             /* We shouldn't have any bytes left */
-            if (PACKET_remaining(&ssubpkt))
+            if (PACKET_remaining(&ssubpkt) != 0)
                 goto err;
 
         }
@@ -2140,7 +2140,7 @@ static int ssl_scan_clienthello_tlsext(SSL *s, PACKET *pkt, int *al)
                     || (dsize & 1) != 0
                     || (dsize == 0)
                     || !PACKET_get_bytes(&subpkt, &data, dsize)
-                    || PACKET_remaining(&subpkt)
+                    || PACKET_remaining(&subpkt) != 0
                     || !tls1_save_sigalgs(s, data, dsize)) {
                 goto err;
             }
index d6d0c082f5ace42ff327f84da9877c07c9b19fd3..c3ac53bcb0712cf692d3fb90a521c7b1071349fb 100644 (file)
@@ -67,7 +67,7 @@ static int test_PACKET_remaining(PACKET *pkt)
             || !PACKET_forward(pkt, BUF_LEN - 1)
             ||  PACKET_remaining(pkt) != 1
             || !PACKET_forward(pkt, 1)
-            ||  PACKET_remaining(pkt)) {
+            ||  PACKET_remaining(pkt) != 0) {
         fprintf(stderr, "test_PACKET_remaining() failed\n");
         return 0;
     }