mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-10 00:57:02 +02:00
CLEANUP: backend: make alloc_{bind,dst}_address() idempotent
These functions dynamically allocate a source or destination address but start by clearing the previous one. There's a non-null risk of leaking addresses there in case of misuse. Better have them do nothing if the address was already allocated.
This commit is contained in:
parent
291ee25696
commit
b3f0d42a1d
@ -866,7 +866,8 @@ int assign_server(struct stream *s)
|
|||||||
* The address is taken from the currently assigned server, or from the
|
* The address is taken from the currently assigned server, or from the
|
||||||
* dispatch or transparent address.
|
* dispatch or transparent address.
|
||||||
*
|
*
|
||||||
* Returns SRV_STATUS_OK on success.
|
* Returns SRV_STATUS_OK on success. Does nothing if the address was
|
||||||
|
* already set.
|
||||||
* On error, no address is allocated and SRV_STATUS_INTERNAL is returned.
|
* On error, no address is allocated and SRV_STATUS_INTERNAL is returned.
|
||||||
*/
|
*/
|
||||||
static int alloc_dst_address(struct sockaddr_storage **ss,
|
static int alloc_dst_address(struct sockaddr_storage **ss,
|
||||||
@ -874,7 +875,9 @@ static int alloc_dst_address(struct sockaddr_storage **ss,
|
|||||||
{
|
{
|
||||||
const struct sockaddr_storage *dst;
|
const struct sockaddr_storage *dst;
|
||||||
|
|
||||||
*ss = NULL;
|
if (*ss)
|
||||||
|
return SRV_STATUS_OK;
|
||||||
|
|
||||||
if ((s->flags & SF_DIRECT) || (s->be->lbprm.algo & BE_LB_KIND)) {
|
if ((s->flags & SF_DIRECT) || (s->be->lbprm.algo & BE_LB_KIND)) {
|
||||||
/* A server is necessarily known for this stream */
|
/* A server is necessarily known for this stream */
|
||||||
if (!(s->flags & SF_ASSIGNED))
|
if (!(s->flags & SF_ASSIGNED))
|
||||||
@ -1070,7 +1073,8 @@ int assign_server_and_queue(struct stream *s)
|
|||||||
* with transparent mode.
|
* with transparent mode.
|
||||||
*
|
*
|
||||||
* Returns SRV_STATUS_OK if no transparent mode or the address was successfully
|
* Returns SRV_STATUS_OK if no transparent mode or the address was successfully
|
||||||
* allocated. Otherwise returns SRV_STATUS_INTERNAL.
|
* allocated. Otherwise returns SRV_STATUS_INTERNAL. Does nothing if the
|
||||||
|
* address was already allocated.
|
||||||
*/
|
*/
|
||||||
static int alloc_bind_address(struct sockaddr_storage **ss,
|
static int alloc_bind_address(struct sockaddr_storage **ss,
|
||||||
struct server *srv, struct stream *s)
|
struct server *srv, struct stream *s)
|
||||||
@ -1083,7 +1087,8 @@ static int alloc_bind_address(struct sockaddr_storage **ss,
|
|||||||
size_t vlen;
|
size_t vlen;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
*ss = NULL;
|
if (*ss)
|
||||||
|
return SRV_STATUS_OK;
|
||||||
|
|
||||||
#if defined(CONFIG_HAP_TRANSPARENT)
|
#if defined(CONFIG_HAP_TRANSPARENT)
|
||||||
if (srv && srv->conn_src.opts & CO_SRC_BIND)
|
if (srv && srv->conn_src.opts & CO_SRC_BIND)
|
||||||
@ -1335,7 +1340,7 @@ static int connect_server(struct stream *s)
|
|||||||
#ifdef USE_OPENSSL
|
#ifdef USE_OPENSSL
|
||||||
struct sample *sni_smp = NULL;
|
struct sample *sni_smp = NULL;
|
||||||
#endif
|
#endif
|
||||||
struct sockaddr_storage *bind_addr;
|
struct sockaddr_storage *bind_addr = NULL;
|
||||||
int proxy_line_ret;
|
int proxy_line_ret;
|
||||||
int64_t hash = 0;
|
int64_t hash = 0;
|
||||||
struct conn_hash_params hash_params;
|
struct conn_hash_params hash_params;
|
||||||
|
Loading…
Reference in New Issue
Block a user