Skip to content

Commit 836d5c9

Browse files
committed
fix(*) not mutating tables when doing pairs to avoid missing of
iterration
1 parent ec2ef27 commit 836d5c9

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

lib/resty/openssl.lua

+8-1
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@ _M.bignum = _M.bn
3333
function _M.luaossl_compat()
3434
for mod, tbl in pairs(_M) do
3535
if type(tbl) == 'table' then
36+
37+
-- avoid using a same table as the iterrator will change
38+
local new_tbl = {}
3639
-- luaossl always error() out
3740
for k, f in pairs(tbl) do
3841
if type(f) == 'function' then
3942
local of = f
40-
tbl[k] = function(...)
43+
new_tbl[k] = function(...)
4144
local ret = { of(...) }
4245
if ret and #ret > 1 and ret[#ret] then
4346
error(mod .. "." .. k .. "(): " .. ret[#ret])
@@ -47,6 +50,10 @@ function _M.luaossl_compat()
4750
end
4851
end
4952

53+
for k, f in pairs(new_tbl) do
54+
tbl[k] = f
55+
end
56+
5057
setmetatable(tbl, {
5158
__index = function(t, k)
5259
local tok

lib/resty/openssl/include/x509/altname.lua

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ local GEN_URI = 6
88
local GEN_IPADD = 7
99
-- local GEN_RID = 8
1010

11-
local types = {
11+
local default_types = {
1212
RFC822Name = GEN_EMAIL,
1313
RFC822 = GEN_EMAIL,
1414
Email = GEN_EMAIL,
@@ -29,8 +29,10 @@ local literals = {
2929
[GEN_IPADD] = "IP",
3030
}
3131

32-
for t, gid in pairs(types) do
32+
local types = {}
33+
for t, gid in pairs(default_types) do
3334
types[t:lower()] = gid
35+
types[t] = gid
3436
end
3537

3638
return {

lib/resty/openssl/pkey.lua

+6-2
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ local function generate_key(config)
324324
return ctx_ptr[0]
325325
end
326326

327-
local load_key_try_funcs = {
327+
local _load_key_try_funcs = {
328328
PEM = {
329329
-- Note: make sure we always try load priv key first
330330
pr = {
@@ -351,7 +351,10 @@ local load_key_try_funcs = {
351351
-- populate * funcs
352352
local all_funcs = {}
353353
local typ_funcs = {}
354-
for fmt, ffs in pairs(load_key_try_funcs) do
354+
local load_key_try_funcs = {}
355+
for fmt, ffs in pairs(_load_key_try_funcs) do
356+
load_key_try_funcs[fmt] = ffs
357+
355358
local funcs = {}
356359
for typ, fs in pairs(ffs) do
357360
for f, arg in pairs(fs) do
@@ -370,6 +373,7 @@ load_key_try_funcs["*"]["*"] = all_funcs
370373
for typ, fs in pairs(typ_funcs) do
371374
load_key_try_funcs[typ] = fs
372375
end
376+
_load_key_try_funcs = nil
373377

374378
local function tostring(self, is_priv, fmt)
375379
if fmt == "JWK" then

0 commit comments

Comments
 (0)