From ffbc446e3b338c784c345b9340f2eccf6359ddab Mon Sep 17 00:00:00 2001 From: "Artem S. Povalyukhin" Date: Thu, 21 Nov 2019 22:31:14 +0300 Subject: [PATCH] Fixed hash collision for empty string key. The issue was introduced in 10a19a2e1d4f. --- 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 deletion(-) diff --git a/src/njs_object.c b/src/njs_object.c index 34ef9d17..088aef68 100644 --- a/src/njs_object.c +++ b/src/njs_object.c @@ -171,7 +171,7 @@ njs_object_hash_test(njs_lvlhsh_query_t *lhq, void *data) 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 --git a/src/njs_object.h b/src/njs_object.h index 32e42936..b64f9947 100644 --- a/src/njs_object.h +++ b/src/njs_object.h @@ -110,6 +110,7 @@ njs_object_property_key_set(njs_lvlhsh_query_t *lhq, const njs_value_t *key, if (njs_is_symbol(key)) { lhq->key.length = 0; + lhq->key.start = NULL; lhq->key_hash = njs_symbol_key(key); } else { diff --git a/src/njs_value.h b/src/njs_value.h index 7865a013..6d0ebfa1 100644 --- a/src/njs_value.h +++ b/src/njs_value.h @@ -871,6 +871,7 @@ njs_set_object_value(njs_value_t *value, njs_object_value_t *object_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 --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index d5826b75..37697386 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -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()"), -- 2.47.3