[njs] HTTP: fixed handling of 0 length request body.

Dmitry Volyntsev xeioex at nginx.com
Mon May 20 23:46:18 UTC 2024


details:   https://hg.nginx.org/njs/rev/286dbef3c0b2
branches:  
changeset: 2331:286dbef3c0b2
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Mon May 20 16:44:10 2024 -0700
description:
HTTP: fixed handling of 0 length request body.

Previously, when r.requestBuffer was passed as a body argument to
ngx.fetch() or r.subrequest() then exception was thrown "Error: invalid
Request body" when the request body had 0 length.

diffstat:

 src/njs_vm.c |  6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diffs (16 lines):

diff -r 8851a78723dc -r 286dbef3c0b2 src/njs_vm.c
--- a/src/njs_vm.c	Fri May 17 21:54:50 2024 -0700
+++ b/src/njs_vm.c	Mon May 20 16:44:10 2024 -0700
@@ -1602,6 +1602,12 @@ njs_vm_value_to_bytes(njs_vm_t *vm, njs_
         }
 
         if (njs_slow_path(njs_is_detached_buffer(buffer))) {
+            if (length == 0) {
+                dst->length = 0;
+                dst->start = NULL;
+                return NJS_OK;
+            }
+
             njs_type_error(vm, "detached buffer");
             return NJS_ERROR;
         }


More information about the nginx-devel mailing list