Skip to content

Commit aa6ad47

Browse files
catbro666fffonion
authored andcommitted
fix(*) fix typos and add error check for new_of/dup_of (#2)
* format_error and format_all_error are not correctly referenced * add error check for new_of/dup_of * fix istype/stack_of
1 parent fb264ce commit aa6ad47

File tree

7 files changed

+36
-10
lines changed

7 files changed

+36
-10
lines changed

lib/resty/openssl/pkcs12.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ local function decode(p12, passphrase)
4141
local px509 = ptr_ptr_of_x509()
4242
local pstack = ptr_ptr_of_stack()
4343
local stack = stack_of_x509_new()
44+
if stack == nil then
45+
return nil, "pkcs12.decode: OPENSSL_sk_new_null() failed"
46+
end
47+
4448
-- assign a valid OPENSSL_STACK so gc is taken care of
4549
pstack[0] = stack
4650

@@ -165,4 +169,4 @@ return {
165169
loads = decode,
166170
encode = encode,
167171
dumps = encode,
168-
}
172+
}

lib/resty/openssl/x509/altname.lua

+4-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ function _M.dup(ctx)
115115
return nil, "x509.altname.dup: expect a GENERAL_NAMES* ctx at #1"
116116
end
117117

118-
local dup_ctx = dup(ctx)
118+
local dup_ctx, err = dup(ctx)
119+
if dup_ctx == nil then
120+
return nil, err
121+
end
119122

120123
return setmetatable({
121124
cast = ffi_cast("GENERAL_NAMES*", dup_ctx),

lib/resty/openssl/x509/chain.lua

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ local add = stack_lib.add_of(STACK)
1717
local mt = stack_lib.mt_of(STACK, x509_lib.dup, _M)
1818

1919
function _M.new()
20-
local raw = new()
20+
local raw, err = new()
21+
if raw == nil then
22+
return nil, err
23+
end
2124

2225
local self = setmetatable({
2326
stack_of = STACK,

lib/resty/openssl/x509/extension/dist_points.lua

+8-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function _M.new()
2727
end
2828

2929
local self = setmetatable({
30+
stack_of = STACK,
3031
ctx = ctx,
3132
_is_shallow_copy = false,
3233
}, mt)
@@ -35,16 +36,21 @@ function _M.new()
3536
end
3637

3738
function _M.istype(l)
38-
return l and l.cast and ffi.istype(stack_ptr_ct, l.cast)
39+
return l and l.ctx and ffi.istype(stack_ptr_ct, l.ctx)
40+
and l.stack_of and l.stack_of == STACK
3941
end
4042

4143
function _M.dup(ctx)
4244
if ctx == nil or not ffi.istype(stack_ptr_ct, ctx) then
4345
return nil, "expect a stack ctx at #1"
4446
end
45-
local dup_ctx = dup(ctx)
47+
local dup_ctx, err = dup(ctx)
48+
if dup_ctx == nil then
49+
return nil, err
50+
end
4651

4752
return setmetatable({
53+
stack_of = STACK,
4854
ctx = dup_ctx,
4955
-- don't let lua gc the original stack to keep its elements
5056
_dupped_from = ctx,

lib/resty/openssl/x509/extension/info_access.lua

+4-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ function _M.dup(ctx)
5959
if ctx == nil or not ffi.istype(authority_info_access_ptr_ct, ctx) then
6060
return nil, "expect a AUTHORITY_INFO_ACCESS* ctx at #1"
6161
end
62-
local dup_ctx = dup(ctx)
62+
local dup_ctx, err = dup(ctx)
63+
if dup_ctx == nil then
64+
return nil, err
65+
end
6366

6467
return setmetatable({
6568
ctx = dup_ctx,

lib/resty/openssl/x509/extensions.lua

+9-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ local dup = stack_lib.dup_of(STACK)
1717
local mt = stack_lib.mt_of(STACK, extension_lib.dup, _M)
1818

1919
function _M.new()
20-
local raw = new()
20+
local raw, err = new()
21+
if raw == nil then
22+
return nil, err
23+
end
2124

2225
local self = setmetatable({
2326
stack_of = STACK,
@@ -37,9 +40,13 @@ function _M.dup(ctx)
3740
return nil, "x509.extensions.dup: expect a stack ctx at #1, got " .. type(ctx)
3841
end
3942

40-
local dup_ctx = dup(ctx)
43+
local dup_ctx, err = dup(ctx)
44+
if dup_ctx == nil then
45+
return nil, err
46+
end
4147

4248
return setmetatable({
49+
stack_of = STACK,
4350
ctx = dup_ctx,
4451
-- don't let lua gc the original stack to keep its elements
4552
_dupped_from = ctx,

lib/resty/openssl/x509/store.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ local x509_lib = require "resty.openssl.x509"
99
local chain_lib = require "resty.openssl.x509.chain"
1010
local crl_lib = require "resty.openssl.x509.crl"
1111
local ctx_lib = require "resty.openssl.ctx"
12-
local format_error = require("resty.openssl.err").format_all_error
13-
local format_all_error = require("resty.openssl.err").format_error
12+
local format_all_error = require("resty.openssl.err").format_all_error
13+
local format_error = require("resty.openssl.err").format_error
1414
local OPENSSL_3X = require("resty.openssl.version").OPENSSL_3X
1515

1616
local _M = {}

0 commit comments

Comments
 (0)