tls: Fix Picotls ctx_read rx_content issue 81/25181/2
authorSimon Zhang <yuwei1.zhang@intel.com>
Sat, 15 Feb 2020 13:50:16 +0000 (21:50 +0800)
committerSimon Zhang <yuwei1.zhang@intel.com>
Sat, 15 Feb 2020 14:42:13 +0000 (14:42 +0000)
Type: fix

Signed-off-by: Simon Zhang <yuwei1.zhang@intel.com>
Change-Id: I19cdd2055ea494fc36628b4a94fc56742c1d1a8a
Signed-off-by: Simon Zhang <yuwei1.zhang@intel.com>
src/plugins/tlspicotls/tls_picotls.c

index 6e18551..054f01a 100644 (file)
@@ -254,7 +254,7 @@ static inline int
 picotls_ctx_read (tls_ctx_t * ctx, session_t * tls_session)
 {
   picotls_ctx_t *ptls_ctx = (picotls_ctx_t *) ctx;
-  int from_tls_len = 0, to_app_len = 0, crypto_len, ret;
+  int from_tls_len = 0, to_app_len = 0, off, crypto_len, ret;
   u32 deq_max, deq_now;
   u32 enq_max, enq_now;
   ptls_buffer_t _buf, *buf = &_buf;
@@ -270,8 +270,9 @@ picotls_ctx_read (tls_ctx_t * ctx, session_t * tls_session)
       if (!deq_now)
        goto done_hs;
 
-      from_tls_len +=
-       svm_fifo_dequeue (tls_rx_fifo, deq_now, TLS_RX_LEN (ptls_ctx));
+      off = svm_fifo_dequeue (tls_rx_fifo, deq_now, TLS_RX_LEN (ptls_ctx));
+      from_tls_len += off;
+      ptls_ctx->rx_len += off;
       if (from_tls_len <= 0)
        {
          tls_add_vpp_q_builtin_rx_evt (tls_session);
@@ -281,10 +282,11 @@ picotls_ctx_read (tls_ctx_t * ctx, session_t * tls_session)
        {
          deq_now = clib_min (svm_fifo_max_read_chunk (tls_rx_fifo),
                              deq_max - from_tls_len);
-         from_tls_len += svm_fifo_dequeue (tls_rx_fifo, deq_now,
-                                           TLS_RX_LEN (ptls_ctx));
+         off = svm_fifo_dequeue (tls_rx_fifo, deq_now,
+                                 TLS_RX_LEN (ptls_ctx));
+         from_tls_len += off;
+         ptls_ctx->rx_len += off;
        }
-      ptls_ctx->rx_len += from_tls_len;
       picotls_do_handshake (ptls_ctx, tls_session, TLS_RX_OFFSET (ptls_ctx),
                            from_tls_len);
       if (picotls_handshake_is_over (ctx))
@@ -308,20 +310,21 @@ picotls_ctx_read (tls_ctx_t * ctx, session_t * tls_session)
 
       deq_now = clib_min (deq_max, svm_fifo_max_read_chunk (tls_rx_fifo));
 
-      from_tls_len =
-       svm_fifo_dequeue (tls_rx_fifo, deq_now, TLS_RX_LEN (ptls_ctx));
+      off = svm_fifo_dequeue (tls_rx_fifo, deq_now, TLS_RX_LEN (ptls_ctx));
+      from_tls_len = off;
+      ptls_ctx->rx_len += off;
 
       if (from_tls_len < deq_max)
        {
          deq_now =
            clib_min (svm_fifo_max_read_chunk (tls_rx_fifo),
                      deq_max - from_tls_len);
-         from_tls_len +=
+         off =
            svm_fifo_dequeue (tls_rx_fifo, deq_now, TLS_RX_LEN (ptls_ctx));
+         from_tls_len += off;
+         ptls_ctx->rx_len += off;
        }
 
-      ptls_ctx->rx_len += from_tls_len;
-
       if (from_tls_len < deq_max)
        tls_add_vpp_q_builtin_rx_evt (tls_session);
     }
@@ -336,7 +339,7 @@ app_fifo:
     }
 
   crypto_len = clib_min (enq_max, TLS_RX_LEFT_LEN (ptls_ctx));
-  int off = 0;
+  off = 0;
 
   do
     {
@@ -345,7 +348,7 @@ app_fifo:
        ptls_receive (ptls_ctx->tls, buf,
                      TLS_RX_OFFSET (ptls_ctx), &consumed);
       off += consumed;
-      ptls_ctx->rx_offset += consumed;
+      ptls_ctx->rx_offset += off;
     }
   while (ret == 0 && off < crypto_len);
 
@@ -361,12 +364,12 @@ app_fifo:
          to_app_len +=
            svm_fifo_enqueue (app_rx_fifo, enq_now, buf->base + to_app_len);
        }
-    }
+      if (ptls_ctx->rx_len != 0 && !TLS_RX_IS_LEFT (ptls_ctx))
+       {
+         ptls_ctx->rx_len = 0;
+         ptls_ctx->rx_offset = 0;
+       }
 
-  if (ptls_ctx->rx_len != 0 && !TLS_RX_IS_LEFT (ptls_ctx))
-    {
-      ptls_ctx->rx_len = 0;
-      ptls_ctx->rx_offset = 0;
     }
 
 final: