[njs] Fixed macro for aligned size of njs_frame_t struct.

Dmitry Volyntsev xeioex at nginx.com
Tue Sep 11 12:36:08 UTC 2018


details:   http://hg.nginx.org/njs/rev/c2cddf3b97b7
branches:  
changeset: 602:c2cddf3b97b7
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Tue Sep 11 15:35:27 2018 +0300
description:
Fixed macro for aligned size of njs_frame_t struct.

NJS_FRAME_SIZE did not take into account the variable length of
closures array.  This can result in overlapping addresses for
native_frame->arguments and frame->closures[n],

diffstat:

 njs/njs_function.c |  8 ++++----
 njs/njs_function.h |  5 +++--
 2 files changed, 7 insertions(+), 6 deletions(-)

diffs (41 lines):

diff -r bbec3cdb747b -r c2cddf3b97b7 njs/njs_function.c
--- a/njs/njs_function.c	Tue Sep 11 15:34:50 2018 +0300
+++ b/njs/njs_function.c	Tue Sep 11 15:35:27 2018 +0300
@@ -166,10 +166,9 @@ njs_function_frame(njs_vm_t *vm, njs_fun
 
     closures = lambda->nesting + lambda->block_closures;
 
-    size = NJS_FRAME_SIZE
+    size = njs_frame_size(closures)
            + (function->args_offset + max_args) * sizeof(njs_value_t)
-           + lambda->local_size
-           + closures * sizeof(njs_closure_t *);
+           + lambda->local_size;
 
     native_frame = njs_function_frame_alloc(vm, size);
     if (nxt_slow_path(native_frame == NULL)) {
@@ -182,7 +181,8 @@ njs_function_frame(njs_vm_t *vm, njs_fun
 
     /* Function arguments. */
 
-    value = (njs_value_t *) ((u_char *) native_frame + NJS_FRAME_SIZE);
+    value = (njs_value_t *) ((u_char *) native_frame +
+                             njs_frame_size(closures));
     native_frame->arguments = value;
 
     bound = function->bound;
diff -r bbec3cdb747b -r c2cddf3b97b7 njs/njs_function.h
--- a/njs/njs_function.h	Tue Sep 11 15:34:50 2018 +0300
+++ b/njs/njs_function.h	Tue Sep 11 15:35:27 2018 +0300
@@ -45,8 +45,9 @@ struct njs_function_lambda_s {
     nxt_align_size(sizeof(njs_native_frame_t), sizeof(njs_value_t))
 
 /* The frame size must be aligned to njs_value_t. */
-#define NJS_FRAME_SIZE                                                        \
-    nxt_align_size(sizeof(njs_frame_t), sizeof(njs_value_t))
+#define njs_frame_size(closures)                                              \
+    nxt_align_size(sizeof(njs_frame_t) + closures * sizeof(njs_closure_t *),  \
+                   sizeof(njs_value_t))
 
 /* The retval field is not used in the global frame. */
 #define NJS_GLOBAL_FRAME_SIZE                                                 \


More information about the nginx-devel mailing list