Welcome! Log In Create A New Profile

Advanced

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

Dmitry Volyntsev
April 26, 2022 07:14PM
details: https://hg.nginx.org/njs/rev/f150bd2d40bb
branches:
changeset: 1842:f150bd2d40bb
user: Dmitry Volyntsev <xeioex@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;

_______________________________________________
nginx-devel mailing list -- nginx-devel@nginx.org
To unsubscribe send an email to nginx-devel-leave@nginx.org
Subject Author Views Posted

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

Dmitry Volyntsev 373 April 26, 2022 07:14PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 106
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready