[njs] Making FOREACH and NEXT instructions robust to invalid input.

Dmitry Volyntsev xeioex at nginx.com
Tue Apr 26 23:09:02 UTC 2022


details:   https://hg.nginx.org/njs/rev/f150bd2d40bb
branches:  
changeset: 1842:f150bd2d40bb
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Tue Apr 26 16:07:06 2022 -0700
description:
Making FOREACH and NEXT instructions robust to invalid input.

diffstat:

 src/njs_value.h  |  3 +--
 src/njs_vmcode.c |  5 +++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diffs (42 lines):

diff -r 744122b4dccf -r f150bd2d40bb src/njs_value.h
--- a/src/njs_value.h	Tue Apr 26 16:07:02 2022 -0700
+++ b/src/njs_value.h	Tue Apr 26 16:07:06 2022 -0700
@@ -70,7 +70,7 @@ typedef enum {
     NJS_DATA_TAG_TEXT_ENCODER,
     NJS_DATA_TAG_TEXT_DECODER,
     NJS_DATA_TAG_ARRAY_ITERATOR,
-    NJS_DATA_TAG_FS_STAT,
+    NJS_DATA_TAG_FOREACH_NEXT,
     NJS_DATA_TAG_MAX
 } njs_data_tag_t;
 
@@ -135,7 +135,6 @@ union njs_value_s {
             njs_promise_t             *promise;
             njs_prop_handler_t        prop_handler;
             njs_value_t               *value;
-            njs_property_next_t       *next;
             void                      *data;
         } u;
     } data;
diff -r 744122b4dccf -r f150bd2d40bb src/njs_vmcode.c
--- a/src/njs_vmcode.c	Tue Apr 26 16:07:02 2022 -0700
+++ b/src/njs_vmcode.c	Tue Apr 26 16:07:06 2022 -0700
@@ -819,7 +819,8 @@ next:
                 pnext = (njs_vmcode_prop_next_t *) pc;
                 retval = njs_scope_value(vm, pnext->retval);
 
-                next = value2->data.u.next;
+                njs_assert(njs_is_data(value2, NJS_DATA_TAG_FOREACH_NEXT));
+                next = njs_data(value2);
 
                 if (next->index < next->array->length) {
                     *retval = next->array->start[next->index++];
@@ -1468,7 +1469,7 @@ njs_vmcode_property_foreach(njs_vm_t *vm
         return NJS_ERROR;
     }
 
-    vm->retval.data.u.next = next;
+    njs_set_data(&vm->retval, next, NJS_DATA_TAG_FOREACH_NEXT);
 
     code = (njs_vmcode_prop_foreach_t *) pc;
 



More information about the nginx-devel mailing list