Skip to content

Commit b1dfa9f

Browse files
committed
feature: use the actual ngx_connection_t * in ssl_client_hello_by
Do we really need to create a fake connection here? Sure, the request struct wasn't even created yet but the conneciton does exist. I personally need it because I need to allocate memory that will live for as long as the connection exists, not until the Lua chunk returns.
1 parent edd1b6a commit b1dfa9f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/ngx_http_lua_ssl_client_helloby.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,7 @@ ngx_http_lua_ffi_ssl_get_client_hello_ext_present(ngx_http_request_t *r,
670670
int got_extensions;
671671
size_t ext_len;
672672
int *ext_out;
673-
/* OPENSSL will allocate memory for us and make the ext_out point to it */
674-
673+
ngx_connection_t *c;
675674

676675
if (r->connection == NULL || r->connection->ssl == NULL) {
677676
*err = "bad request";
@@ -684,6 +683,13 @@ ngx_http_lua_ffi_ssl_get_client_hello_ext_present(ngx_http_request_t *r,
684683
return NGX_ERROR;
685684
}
686685

686+
c = ngx_ssl_get_connection(ssl_conn);
687+
if (c == NULL) {
688+
*err = "bad ssl conn";
689+
return NGX_ERROR;
690+
}
691+
692+
687693
#ifdef SSL_ERROR_WANT_CLIENT_HELLO_CB
688694
got_extensions = SSL_client_hello_get1_extensions_present(ssl_conn,
689695
&ext_out, &ext_len);
@@ -692,7 +698,7 @@ ngx_http_lua_ffi_ssl_get_client_hello_ext_present(ngx_http_request_t *r,
692698
return NGX_DECLINED;
693699
}
694700

695-
*extensions = ngx_palloc(r->connection->pool, sizeof(int) * ext_len);
701+
*extensions = ngx_palloc(c->pool, sizeof(int) * ext_len);
696702
if (*extensions != NULL) {
697703
ngx_memcpy(*extensions, ext_out, sizeof(int) * ext_len);
698704
*extensions_len = ext_len;

0 commit comments

Comments
 (0)