Skip to content

Commit ca1db4d

Browse files
committed
sslsocket: fix "attempt to redefine 'SSL_*'" error
Different libraries can use FFI OpenSSL bindings. E.g. cartridge already uses it: https://github.com/tarantool/cartridge/blob/master/cartridge/sslsocket.lua Right now there is no any significant difference in cdef. But in future it can be different (e.g. after implementation of #207). Since we use "struct SSL_METHOD {} SSL_METHOD" definition it can cause errors like 'attempt to redefine 'SSL_METHOD'" that lead to the case then pcall silently handle an error but some symbols won't be defined. This patch fixes such case. That's only relevant for struct definitions. Functions and typedefs can be redefined.
1 parent 32f0473 commit ca1db4d

File tree

1 file changed

+33
-36
lines changed

1 file changed

+33
-36
lines changed

http/sslsocket.lua

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,55 +9,52 @@ local buffer = require('buffer')
99
local clock = require('clock')
1010
local errno = require('errno')
1111

12-
pcall(
13-
function()
14-
ffi.cdef[[
15-
typedef struct SSL_METHOD {} SSL_METHOD;
16-
typedef struct SSL_CTX {} SSL_CTX;
17-
typedef struct SSL {} SSL;
12+
pcall(ffi.cdef, 'typedef struct SSL_METHOD {} SSL_METHOD;')
13+
pcall(ffi.cdef, 'typedef struct SSL_CTX {} SSL_CTX;')
14+
pcall(ffi.cdef, 'typedef struct SSL {} SSL;')
1815

19-
const SSL_METHOD *TLS_server_method(void);
20-
const SSL_METHOD *TLS_client_method(void);
16+
pcall(ffi.cdef, [[
17+
const SSL_METHOD *TLS_server_method(void);
18+
const SSL_METHOD *TLS_client_method(void);
2119
22-
SSL_CTX *SSL_CTX_new(const SSL_METHOD *method);
23-
void SSL_CTX_free(SSL_CTX *);
20+
SSL_CTX *SSL_CTX_new(const SSL_METHOD *method);
21+
void SSL_CTX_free(SSL_CTX *);
2422
25-
int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type);
26-
int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type);
27-
void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u);
28-
typedef int (*pem_passwd_cb)(char *buf, int size, int rwflag, void *userdata);
23+
int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type);
24+
int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type);
25+
void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u);
26+
typedef int (*pem_passwd_cb)(char *buf, int size, int rwflag, void *userdata);
2927
30-
void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_passwd_cb cb);
28+
void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_passwd_cb cb);
3129
32-
int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
33-
const char *CApath);
34-
int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str);
35-
void SSL_CTX_set_verify(SSL_CTX *ctx, int mode,
36-
int (*verify_callback)(int, void *));
30+
int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
31+
const char *CApath);
32+
int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str);
33+
void SSL_CTX_set_verify(SSL_CTX *ctx, int mode,
34+
int (*verify_callback)(int, void *));
3735
38-
SSL *SSL_new(SSL_CTX *ctx);
39-
void SSL_free(SSL *ssl);
36+
SSL *SSL_new(SSL_CTX *ctx);
37+
void SSL_free(SSL *ssl);
4038
41-
int SSL_set_fd(SSL *s, int fd);
39+
int SSL_set_fd(SSL *s, int fd);
4240
43-
void SSL_set_connect_state(SSL *s);
44-
void SSL_set_accept_state(SSL *s);
41+
void SSL_set_connect_state(SSL *s);
42+
void SSL_set_accept_state(SSL *s);
4543
46-
int SSL_write(SSL *ssl, const void *buf, int num);
47-
int SSL_read(SSL *ssl, void *buf, int num);
44+
int SSL_write(SSL *ssl, const void *buf, int num);
45+
int SSL_read(SSL *ssl, void *buf, int num);
4846
49-
int SSL_pending(const SSL *ssl);
47+
int SSL_pending(const SSL *ssl);
5048
51-
void ERR_clear_error(void);
52-
char *ERR_error_string(unsigned long e, char *buf);
53-
unsigned long ERR_peek_last_error(void);
49+
void ERR_clear_error(void);
50+
char *ERR_error_string(unsigned long e, char *buf);
51+
unsigned long ERR_peek_last_error(void);
5452
55-
int SSL_get_error(const SSL *s, int ret_code);
53+
int SSL_get_error(const SSL *s, int ret_code);
5654
57-
void *memmem(const void *haystack, size_t haystacklen,
58-
const void *needle, size_t needlelen);
59-
]]
60-
end)
55+
void *memmem(const void *haystack, size_t haystacklen,
56+
const void *needle, size_t needlelen);
57+
]])
6158

6259
local function slice_wait(timeout, starttime)
6360
if timeout == nil then

0 commit comments

Comments
 (0)