aboutsummaryrefslogtreecommitdiff
path: root/nginx/ngx_http_js_module.c
diff options
context:
space:
mode:
authorDmitry Volyntsev <xeioex@nginx.com>2025-01-28 19:11:48 -0800
committerDmitry Volyntsev <xeioexception@gmail.com>2025-01-31 17:56:40 -0800
commit2d97e80486d7d2554e58cdaca4f2389b836600c8 (patch)
treee5b9b51d316d670570ae35e605a48ba89d0a5fd6 /nginx/ngx_http_js_module.c
parent75ca26f8347123c3163439a3652c1218bcb3bfa7 (diff)
downloadnjs-2d97e80486d7d2554e58cdaca4f2389b836600c8.tar.gz
njs-2d97e80486d7d2554e58cdaca4f2389b836600c8.zip
HTTP: reading r.requestText or r.requestBuffer from a temp file.
Previously, an exception was thrown when accessing r.requestText or r.requestBuffer if a client request body size exceeded client_body_buffer_size.
Diffstat (limited to 'nginx/ngx_http_js_module.c')
-rw-r--r--nginx/ngx_http_js_module.c60
1 files changed, 51 insertions, 9 deletions
diff --git a/nginx/ngx_http_js_module.c b/nginx/ngx_http_js_module.c
index 04d06fb2..66cb97c0 100644
--- a/nginx/ngx_http_js_module.c
+++ b/nginx/ngx_http_js_module.c
@@ -2916,6 +2916,7 @@ ngx_http_js_ext_get_request_body(njs_vm_t *vm, njs_object_prop_t *prop,
{
u_char *p, *body;
size_t len;
+ ssize_t n;
uint32_t buffer_type;
ngx_buf_t *buf;
njs_int_t ret;
@@ -2948,14 +2949,35 @@ ngx_http_js_ext_get_request_body(njs_vm_t *vm, njs_object_prop_t *prop,
return NJS_DECLINED;
}
- if (r->request_body->temp_file) {
- njs_vm_error(vm, "request body is in a file");
- return NJS_ERROR;
- }
-
cl = r->request_body->bufs;
buf = cl->buf;
+ if (r->request_body->temp_file) {
+ ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
+ "http js reading request body from a temporary file");
+
+ if (buf == NULL || !buf->in_file) {
+ njs_vm_internal_error(vm, "cannot find request body");
+ return NJS_ERROR;
+ }
+
+ len = buf->file_last - buf->file_pos;
+
+ body = ngx_pnalloc(r->pool, len);
+ if (body == NULL) {
+ njs_vm_memory_error(vm);
+ return NJS_ERROR;
+ }
+
+ n = ngx_read_file(buf->file, body, len, buf->file_pos);
+ if (n != (ssize_t) len) {
+ njs_vm_internal_error(vm, "failed to read request body");
+ return NJS_ERROR;
+ }
+
+ goto done;
+ }
+
if (cl->next == NULL) {
len = buf->last - buf->pos;
body = buf->pos;
@@ -5259,6 +5281,7 @@ ngx_http_qjs_ext_request_body(JSContext *cx, JSValueConst this_val, int type)
{
u_char *p, *data;
size_t len;
+ ssize_t n;
JSValue body;
uint32_t buffer_type;
ngx_buf_t *buf;
@@ -5287,13 +5310,32 @@ ngx_http_qjs_ext_request_body(JSContext *cx, JSValueConst this_val, int type)
return JS_UNDEFINED;
}
- if (r->request_body->temp_file) {
- return JS_ThrowTypeError(cx, "request body is in a file");
- }
-
cl = r->request_body->bufs;
buf = cl->buf;
+ if (r->request_body->temp_file) {
+ ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
+ "http js reading request body from a temporary file");
+
+ if (buf == NULL || !buf->in_file) {
+ return JS_ThrowInternalError(cx, "cannot find body file");
+ }
+
+ len = buf->file_last - buf->file_pos;
+
+ data = ngx_pnalloc(r->pool, len);
+ if (data == NULL) {
+ return JS_ThrowOutOfMemory(cx);
+ }
+
+ n = ngx_read_file(buf->file, data, len, buf->file_pos);
+ if (n != (ssize_t) len) {
+ return JS_ThrowInternalError(cx, "failed to read request body");
+ }
+
+ goto done;
+ }
+
if (cl->next == NULL) {
len = buf->last - buf->pos;
data = buf->pos;