]> granicus.if.org Git - curl/commitdiff
http2: Fix address sanitizer memcpy warning
authorJay Satiro <raysatiro@yahoo.com>
Wed, 16 Nov 2016 07:16:10 +0000 (02:16 -0500)
committerJay Satiro <raysatiro@yahoo.com>
Wed, 16 Nov 2016 07:16:10 +0000 (02:16 -0500)
- In Curl_http2_switched don't call memcpy when src is NULL.

Curl_http2_switched can be called like:

Curl_http2_switched(conn, NULL, 0);

.. and prior to this change memcpy was then called like:

memcpy(dest, NULL, 0)

.. causing address sanitizer to warn:

http2.c:2057:3: runtime error: null pointer passed as argument 2, which
is declared to never be null

lib/http2.c

index 1484e1515e02d52711a0aa01ec96a2d262c8bc32..6720984b0182afada1604e2fa39c7eff6278c4b5 100644 (file)
@@ -2054,7 +2054,8 @@ CURLcode Curl_http2_switched(struct connectdata *conn,
                     " after upgrade: len=%zu\n",
         nread);
 
-  memcpy(httpc->inbuf, mem, nread);
+  if(nread)
+    memcpy(httpc->inbuf, mem, nread);
   httpc->inbuflen = nread;
 
   nproc = nghttp2_session_mem_recv(httpc->h2, (const uint8_t *)httpc->inbuf,