Welcome! Log In Create A New Profile

Advanced

[njs] Fixed parsing of environ variables when duplicate keys are present.

Dmitry Volyntsev
October 01, 2022 12:14AM
details: https://hg.nginx.org/njs/rev/d6a15aa909cd
branches:
changeset: 1972:d6a15aa909cd
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Fri Sep 30 17:35:52 2022 -0700
description:
Fixed parsing of environ variables when duplicate keys are present.

This closes #581 issue on Github.

diffstat:

src/njs_builtin.c | 22 +++++++++++++++++++---
1 files changed, 19 insertions(+), 3 deletions(-)

diffs (39 lines):

diff -r b61a7a4f286e -r d6a15aa909cd src/njs_builtin.c
--- a/src/njs_builtin.c Thu Sep 29 16:32:52 2022 -0700
+++ b/src/njs_builtin.c Fri Sep 30 17:35:52 2022 -0700
@@ -1795,7 +1795,7 @@ njs_env_hash_init(njs_vm_t *vm, njs_lvlh
char **ep;
u_char *val, *entry;
njs_int_t ret;
- njs_object_prop_t *prop;
+ njs_object_prop_t *prop, *prev;
njs_lvlhsh_query_t lhq;

lhq.replace = 0;
@@ -1836,8 +1836,24 @@ njs_env_hash_init(njs_vm_t *vm, njs_lvlh

ret = njs_lvlhsh_insert(hash, &lhq);
if (njs_slow_path(ret != NJS_OK)) {
- njs_internal_error(vm, "lvlhsh insert failed");
- return NJS_ERROR;
+ if (ret == NJS_ERROR) {
+ njs_internal_error(vm, "lvlhsh insert failed");
+ return NJS_ERROR;
+ }
+
+ /* ret == NJS_DECLINED: entry already exists */
+
+ /*
+ * Always using the first element among the duplicates
+ * and ignoring the rest.
+ */
+
+ prev = lhq.value;
+
+ if (!njs_values_same(&prop->value, &prev->value)) {
+ njs_vm_warn(vm, "environment variable \"%V\" has more than one"
+ " value\n", &lhq.key);
+ }
}
}

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

[njs] Fixed parsing of environ variables when duplicate keys are present.

Dmitry Volyntsev 325 October 01, 2022 12:14AM



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

Online Users

Guests: 306
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready