[nginx] HTTP/2: avoid memcpy() with NULL source and zero length.

Maxim Dounin mdounin at mdounin.ru
Tue Aug 31 13:52:22 UTC 2021


details:   https://hg.nginx.org/nginx/rev/29795b697e14
branches:  
changeset: 7916:29795b697e14
user:      Maxim Dounin <mdounin at mdounin.ru>
date:      Tue Aug 31 16:44:13 2021 +0300
description:
HTTP/2: avoid memcpy() with NULL source and zero length.

Prodded by Clang Static Analyzer.

diffstat:

 src/http/v2/ngx_http_v2.c |  4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diffs (14 lines):

diff -r 09d15a2dbc6b -r 29795b697e14 src/http/v2/ngx_http_v2.c
--- a/src/http/v2/ngx_http_v2.c	Mon Aug 30 14:45:21 2021 +0300
+++ b/src/http/v2/ngx_http_v2.c	Tue Aug 31 16:44:13 2021 +0300
@@ -4241,7 +4241,9 @@ ngx_http_v2_process_request_body(ngx_htt
                 n = size;
             }
 
-            rb->buf->last = ngx_cpymem(rb->buf->last, pos, n);
+            if (n > 0) {
+                rb->buf->last = ngx_cpymem(rb->buf->last, pos, n);
+            }
 
             ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0,
                            "http2 request body recv %uz", n);


More information about the nginx-devel mailing list