mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
Escape double-quotes in strings passed to an event notification script
The string in question will be generated internally by repmgr as a simple one-line string with no control characters etc., so all that needs to be escaped at the moment are any double quotes.
This commit is contained in:
@@ -40,7 +40,7 @@ REPMGR_CLIENT_OBJS = repmgr-client.o \
|
||||
repmgr-action-primary.o repmgr-action-standby.o repmgr-action-witness.o \
|
||||
repmgr-action-bdr.o repmgr-action-cluster.o repmgr-action-node.o \
|
||||
configfile.o log.o strutil.o controldata.o dirutil.o compat.o dbutils.o
|
||||
REPMGRD_OBJS = repmgrd.o repmgrd-physical.o repmgrd-bdr.o configfile.o log.o dbutils.o strutil.o controldata.o
|
||||
REPMGRD_OBJS = repmgrd.o repmgrd-physical.o repmgrd-bdr.o configfile.o log.o dbutils.o strutil.o controldata.o compat.o
|
||||
DATE=$(shell date "+%Y-%m-%d")
|
||||
|
||||
repmgr_version.h: repmgr_version.h.in
|
||||
|
||||
10
dbutils.c
10
dbutils.c
@@ -27,7 +27,6 @@
|
||||
#include "repmgr.h"
|
||||
#include "dbutils.h"
|
||||
#include "controldata.h"
|
||||
|
||||
#include "dirutil.h"
|
||||
|
||||
/* mainly for use by repmgrd */
|
||||
@@ -3086,6 +3085,7 @@ _create_event(PGconn *conn, t_configuration_options *options, int node_id, char
|
||||
char *end_ptr = NULL;
|
||||
int r = 0;
|
||||
|
||||
log_verbose(LOG_DEBUG, "_create_event(): command is '%s'", options->event_notification_command);
|
||||
/*
|
||||
* If configuration option 'event_notifications' was provided, check
|
||||
* if this event is one of the ones listed; if not listed, don't
|
||||
@@ -3164,8 +3164,14 @@ _create_event(PGconn *conn, t_configuration_options *options, int node_id, char
|
||||
src_ptr++;
|
||||
if (details != NULL)
|
||||
{
|
||||
strlcpy(dst_ptr, details, end_ptr - dst_ptr);
|
||||
PQExpBufferData details_escaped;
|
||||
initPQExpBuffer(&details_escaped);
|
||||
|
||||
escape_double_quotes(details, &details_escaped);
|
||||
|
||||
strlcpy(dst_ptr, details_escaped.data, end_ptr - dst_ptr);
|
||||
dst_ptr += strlen(dst_ptr);
|
||||
termPQExpBuffer(&details_escaped);
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
|
||||
@@ -472,8 +472,8 @@ do_bdr_failover(NodeInfoList *nodes, t_node_info *monitored_node)
|
||||
* event "bdr_failover"
|
||||
*/
|
||||
|
||||
create_event_notification_extended(
|
||||
next_node_conn,
|
||||
|
||||
create_event_notification_extended(next_node_conn,
|
||||
&config_file_options,
|
||||
monitored_node->node_id,
|
||||
"bdr_failover",
|
||||
|
||||
25
strutil.c
25
strutil.c
@@ -369,6 +369,31 @@ escape_string(PGconn *conn, const char *string)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* simple function to escape double quotes only
|
||||
*/
|
||||
|
||||
void
|
||||
escape_double_quotes(char *string, PQExpBufferData *out)
|
||||
{
|
||||
char *ptr;
|
||||
|
||||
for (ptr = string; *ptr; ptr++)
|
||||
{
|
||||
if (*ptr == '"')
|
||||
{
|
||||
if ( (ptr == string) || (ptr > string && *(ptr - 1) != '\\'))
|
||||
{
|
||||
appendPQExpBufferChar(out, '\\');
|
||||
}
|
||||
}
|
||||
appendPQExpBufferChar(out, *ptr);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
string_skip_prefix(const char *prefix, char *string)
|
||||
{
|
||||
|
||||
@@ -142,6 +142,8 @@ extern char *escape_recovery_conf_value(const char *src);
|
||||
|
||||
extern char *escape_string(PGconn *conn, const char *string);
|
||||
|
||||
extern void escape_double_quotes(char *string, PQExpBufferData *out);
|
||||
|
||||
extern void
|
||||
append_where_clause(PQExpBufferData *where_clause, const char *clause,...)
|
||||
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
|
||||
|
||||
Reference in New Issue
Block a user