mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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]
This commit is contained in:
parent
07c03bc309
commit
c0aeb98aa9
Notes:
git
2020-10-30 00:09:26 +09:00
1 changed files with 4 additions and 1 deletions
5
hash.c
5
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<RARRAY_LEN(keys); i++) {
|
||||
VALUE e = RARRAY_AREF(keys, i);
|
||||
RSTRING_GETMEM(e, eptr, elen);
|
||||
if (elen != keylen) continue;
|
||||
if (!ENVNMATCH(keyptr, eptr, elen)) continue;
|
||||
rb_ary_delete_at(keys, i);
|
||||
return;
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue