[njs] Fixed memory overlapping.

Vadim Zhestikov v.zhestikov at f5.com
Tue Nov 21 14:55:03 UTC 2023


details:   https://hg.nginx.org/njs/rev/8e024f36e38e
branches:  
changeset: 2235:8e024f36e38e
user:      Vadim Zhestikov <v.zhestikov at f5.com>
date:      Tue Nov 21 06:49:30 2023 -0800
description:
Fixed memory overlapping.

diffstat:

 src/njs_iterator.c       |  22 ++--------------------
 src/test/njs_unit_test.c |   3 +++
 2 files changed, 5 insertions(+), 20 deletions(-)

diffs (66 lines):

diff -r e4105b65d105 -r 8e024f36e38e src/njs_iterator.c
--- a/src/njs_iterator.c	Wed Nov 15 15:08:18 2023 -0800
+++ b/src/njs_iterator.c	Tue Nov 21 06:49:30 2023 -0800
@@ -301,7 +301,6 @@ njs_object_iterate(njs_vm_t *vm, njs_ite
     njs_value_t         *value, *entry, prop, character;
     const u_char        *p, *end, *pos;
     njs_string_prop_t   string_prop;
-    njs_object_value_t  *object;
 
     value = njs_value_arg(&args->value);
     from = args->from;
@@ -348,15 +347,7 @@ njs_object_iterate(njs_vm_t *vm, njs_ite
 
     if (njs_is_string(value) || njs_is_object_string(value)) {
 
-        if (njs_is_string(value)) {
-            object = njs_object_value_alloc(vm, NJS_OBJ_TYPE_STRING, 0, value);
-            if (njs_slow_path(object == NULL)) {
-                return NJS_ERROR;
-            }
-
-            njs_set_object_value(njs_value_arg(&args->value), object);
-        }
-        else {
+        if (!njs_is_string(value)) {
             value = njs_object_value(value);
         }
 
@@ -461,7 +452,6 @@ njs_object_iterate_reverse(njs_vm_t *vm,
     njs_value_t         *entry, *value, prop, character;
     const u_char        *p, *end, *pos;
     njs_string_prop_t   string_prop;
-    njs_object_value_t  *object;
 
     value = njs_value_arg(&args->value);
     from = args->from;
@@ -510,15 +500,7 @@ njs_object_iterate_reverse(njs_vm_t *vm,
 
     if (njs_is_string(value) || njs_is_object_string(value)) {
 
-        if (njs_is_string(value)) {
-            object = njs_object_value_alloc(vm, NJS_OBJ_TYPE_STRING, 0, value);
-            if (njs_slow_path(object == NULL)) {
-                return NJS_ERROR;
-            }
-
-            njs_set_object_value(njs_value_arg(&args->value), object);
-        }
-        else {
+        if (!njs_is_string(value)) {
             value = njs_object_value(value);
         }
 
diff -r e4105b65d105 -r 8e024f36e38e src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Wed Nov 15 15:08:18 2023 -0800
+++ b/src/test/njs_unit_test.c	Tue Nov 21 06:49:30 2023 -0800
@@ -12136,6 +12136,9 @@ static njs_unit_test_t  njs_test[] =
     { njs_str("let e = AggregateError('abc'); e.errors"),
       njs_str("a,b,c") },
 
+    { njs_str("let e = AggregateError('1234567'); e.errors"),
+      njs_str("1,2,3,4,5,6,7") },
+
     { njs_str("let e = AggregateError([1, 2, 3], 'm'); e"),
       njs_str("AggregateError: m") },
 


More information about the nginx-devel mailing list