[njs] Fixed hash collision for empty string key.

Dmitry Volyntsev xeioex at nginx.com
Thu Nov 21 20:04:07 UTC 2019


details:   https://hg.nginx.org/njs/rev/37f1f20de909
branches:  
changeset: 1249:37f1f20de909
user:      Artem S. Povalyukhin <artem.povaluhin at gmail.com>
date:      Thu Nov 21 22:31:14 2019 +0300
description:
Fixed hash collision for empty string key.

The issue was introduced in 10a19a2e1d4f.

diffstat:

 src/njs_object.c         |  2 +-
 src/njs_object.h         |  1 +
 src/njs_value.h          |  1 +
 src/test/njs_unit_test.c |  4 ++++
 4 files changed, 7 insertions(+), 1 deletions(-)

diffs (48 lines):

diff -r 10a19a2e1d4f -r 37f1f20de909 src/njs_object.c
--- a/src/njs_object.c	Thu Nov 21 20:56:06 2019 +0300
+++ b/src/njs_object.c	Thu Nov 21 22:31:14 2019 +0300
@@ -171,7 +171,7 @@ njs_object_hash_test(njs_lvlhsh_query_t 
 
     if (njs_slow_path(njs_is_symbol(name))) {
         return ((njs_symbol_key(name) == lhq->key_hash)
-                && lhq->key.length == 0) ? NJS_OK : NJS_DECLINED;
+                && lhq->key.start == NULL) ? NJS_OK : NJS_DECLINED;
     }
 
     /* string. */
diff -r 10a19a2e1d4f -r 37f1f20de909 src/njs_object.h
--- a/src/njs_object.h	Thu Nov 21 20:56:06 2019 +0300
+++ b/src/njs_object.h	Thu Nov 21 22:31:14 2019 +0300
@@ -110,6 +110,7 @@ njs_object_property_key_set(njs_lvlhsh_q
     if (njs_is_symbol(key)) {
 
         lhq->key.length = 0;
+        lhq->key.start = NULL;
         lhq->key_hash = njs_symbol_key(key);
 
     } else {
diff -r 10a19a2e1d4f -r 37f1f20de909 src/njs_value.h
--- a/src/njs_value.h	Thu Nov 21 20:56:06 2019 +0300
+++ b/src/njs_value.h	Thu Nov 21 22:31:14 2019 +0300
@@ -871,6 +871,7 @@ njs_set_object_value(njs_value_t *value,
 #define njs_property_query_init(pq, _query, _own)                             \
     do {                                                                      \
         (pq)->lhq.key.length = 0;                                             \
+        (pq)->lhq.key.start = NULL;                                           \
         (pq)->lhq.value = NULL;                                               \
         (pq)->own_whiteout = NULL;                                            \
         (pq)->query = _query;                                                 \
diff -r 10a19a2e1d4f -r 37f1f20de909 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Thu Nov 21 20:56:06 2019 +0300
+++ b/src/test/njs_unit_test.c	Thu Nov 21 22:31:14 2019 +0300
@@ -10302,6 +10302,10 @@ static njs_unit_test_t  njs_test[] =
               "Object.getOwnPropertyDescriptor(o, Symbol.isConcatSpreadable).value"),
       njs_str("true") },
 
+    { njs_str("var o = {}, n = 5381 /* NJS_DJB_HASH_INIT */;"
+              "while(n--) o[Symbol()] = 'test'; o[''];"),
+      njs_str("undefined") },
+
     /* String */
 
     { njs_str("String()"),


More information about the nginx-devel mailing list