From c0aeb98aa903334f06758d39c772cb22440d8a4e Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Wed, 28 Oct 2020 15:17:49 -0700 Subject: [PATCH] Make ENV.replace handle multiple environ entries with the same key While it is expected that all environment keys are unique, that is not enforced. It is possible by manipulating environ directly you can call a process with an environment with duplicate keys. If ENV.replace was passed a hash with a key where environ had a duplicate for that key, ENV.replace would end up deleting the key from environ. The fix in this case is to not assume that the environment key list has unique keys, and continue processing the entire key list in keylist_delete. Fixes [Bug #17254] --- hash.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hash.c b/hash.c index a8d6978f45..e0f8773b64 100644 --- a/hash.c +++ b/hash.c @@ -6448,13 +6448,16 @@ keylist_delete(VALUE keys, VALUE key) long keylen, elen; const char *keyptr, *eptr; RSTRING_GETMEM(key, keyptr, keylen); + /* Don't stop at first key, as it is possible to have + multiple environment values with the same key. + */ for (long i=0; i