serf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhuij...@apache.org
Subject svn commit: r1711703 - in /serf/trunk: buckets/hpack_buckets.c protocols/http2_stream.c
Date Sat, 31 Oct 2015 22:51:40 GMT
Author: rhuijben
Date: Sat Oct 31 22:51:40 2015
New Revision: 1711703

URL: http://svn.apache.org/viewvc?rev=1711703&view=rev
Log:
Avoid using data and *data when a read returns 0 bytes. Several
buckets don't set data in this case.

* buckets/hpack_buckets.c
  (hpack_process): Be a bit more careful.

* protocols/http2_stream.c
  (serf_http2__stream_processor): Don't use *data when len is 0.
    Most buckets don't set *data in this case on error paths.
    Solves segfault during testing.

Modified:
    serf/trunk/buckets/hpack_buckets.c
    serf/trunk/protocols/http2_stream.c

Modified: serf/trunk/buckets/hpack_buckets.c
URL: http://svn.apache.org/viewvc/serf/trunk/buckets/hpack_buckets.c?rev=1711703&r1=1711702&r2=1711703&view=diff
==============================================================================
--- serf/trunk/buckets/hpack_buckets.c (original)
+++ serf/trunk/buckets/hpack_buckets.c Sat Oct 31 22:51:40 2015
@@ -1295,8 +1295,9 @@ hpack_process(serf_bucket_t *bucket)
 
                   if (!SERF_BUCKET_READ_ERROR(status))
                     {
-                      memcpy(&ctx->buffer[ctx->buffer_used],
-                             data, len);
+                      if (len > 0)
+                        memcpy(&ctx->buffer[ctx->buffer_used],
+                               data, len);
                       ctx->buffer_used += len;
                     }
                   else
@@ -1374,8 +1375,10 @@ hpack_process(serf_bucket_t *bucket)
 
                   if (!SERF_BUCKET_READ_ERROR(status))
                     {
-                      memcpy(&ctx->buffer[ctx->buffer_used],
-                             data, len);
+                      if (len > 0)
+                        memcpy(&ctx->buffer[ctx->buffer_used],
+                               data, len);
+
                       ctx->buffer_used += len;
                     }
                   else

Modified: serf/trunk/protocols/http2_stream.c
URL: http://svn.apache.org/viewvc/serf/trunk/protocols/http2_stream.c?rev=1711703&r1=1711702&r2=1711703&view=diff
==============================================================================
--- serf/trunk/protocols/http2_stream.c (original)
+++ serf/trunk/protocols/http2_stream.c Sat Oct 31 22:51:40 2015
@@ -251,22 +251,26 @@ serf_http2__stream_processor(void *baton
 
       if (!SERF_BUCKET_READ_ERROR(status))
         {
-          char *printable = serf_bstrmemdup(bucket->allocator, data, len);
-          char *c;
+          if (len > 0)
+          {
+            char *printable = serf_bstrmemdup(bucket->allocator, data, len);
+            char *c;
 
-          for (c = printable; *c; c++)
-            {
-              if (((*c < ' ') || (*c > '\x7E')) && !strchr("\r\n", *c)) /*
Poor mans isctrl*/
+            for (c = printable; *c; c++)
+              {
+                /* Poor mans isctrl */
+                if (((*c < ' ') || (*c > '\x7E')) && !strchr("\r\n", *c))
                 {
                   *c = ' ';
                 }
-            }
+              }
 
 #ifdef _DEBUG
-          fputs(printable, stdout);
+            fputs(printable, stdout);
 #endif
 
-          serf_bucket_mem_free(bucket->allocator, printable);
+            serf_bucket_mem_free(bucket->allocator, printable);
+          }
         }
     }
 



Mime
View raw message