haproxy/include/haproxy/mailers-t.h
Aurelien DARRAGON 9d312212df BUG/MINOR: proxy: fix email-alert leak on deinit() (2nd try)
As shown in GH #2608 and ("BUG/MEDIUM: proxy: fix email-alert invalid
free"), simply calling free_email_alert() from free_proxy() is not the
right thing to do.

In this patch, we reuse proxy->email_alert.set memory space to introduce
proxy->email_alert.flags in order to support 2 flags:
PR_EMAIL_ALERT_SET (to mimic proxy->email_alert.set) and
PR_EMAIL_ALERT_RESOLVED (set once init_email_alert() was called on the
proxy to resolve email_alert.mailer pointer).

Thanks to PR_EMAIL_ALERT_RESOLVED flag, free_email_alert() may now
properly handle the freeing of proxy email_alert settings: if the RESOLVED
flag is set, then it means the .email_alert.mailers.name parsing hint was
replaced by the actual mailers pointer, thus no free should be attempted.

No backport needed: as described in ("BUG/MEDIUM: proxy: fix email-alert
invalid free"), this historical leak is not sensitive as it cannot be
triggered during runtime.. thus given that the fix is not backport-
friendly, it's not worth the trouble.
2024-06-17 19:37:29 +02:00

91 lines
3.0 KiB
C

/*
* include/haproxy/mailer-t.h
* This file defines everything related to mailer.
*
* Copyright 2015 Horms Solutions Ltd., Simon Horman <horms@verge.net.au>
*
* Based on include/haproxy/peers-t.h
*
* Copyright 2010 EXCELIANCE, Emeric Brun <ebrun@exceliance.fr>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, version 2.1
* exclusively.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _HAPROXY_MAILERS_T_H
#define _HAPROXY_MAILERS_T_H
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <haproxy/check-t.h>
#include <haproxy/tcpcheck-t.h>
#include <haproxy/thread-t.h>
/* flags for proxy.email_alert.flags */
enum proxy_email_alert_flags {
PR_EMAIL_ALERT_NONE = 0,
PR_EMAIL_ALERT_SET, /* set if email alert settings are present */
PR_EMAIL_ALERT_RESOLVED, /* set if email alert settings were resolved */
};
struct mailer {
char *id;
struct mailers *mailers;
struct {
const char *file; /* file where the section appears */
int line; /* line where the section appears */
} conf; /* config information */
struct sockaddr_storage addr; /* SMTP server address */
struct protocol *proto; /* SMTP server address's protocol */
struct xprt_ops *xprt; /* SMTP server socket operations at transport layer */
void *sock_init_arg; /* socket operations's opaque init argument if needed */
struct mailer *next; /* next mailer in the list */
};
struct mailers {
char *id; /* mailers section name */
struct mailer *mailer_list; /* mailers in this mailers section */
struct {
const char *file; /* file where the section appears */
int line; /* line where the section appears */
} conf; /* config information */
struct mailers *next; /* next mailers section */
int count; /* total number of mailers in this mailers section */
int users; /* number of users of this mailers section */
struct { /* time to: */
int mail; /* try connecting to mailserver and sending a email */
} timeout;
};
struct email_alert {
struct list list;
struct tcpcheck_rules rules;
struct server *srv;
};
struct email_alertq {
struct list email_alerts;
struct check check; /* Email alerts are implemented using existing check
* code even though they are not checks. This structure
* is as a parameter to the check code.
* Each check corresponds to a mailer */
__decl_thread(HA_SPINLOCK_T lock);
};
#endif /* _HAPROXY_MAILERS_T_H */