repmgr: in standby switchover, quote file paths in remotely executed commands

Per suggestion from GitHub user sebasmannem (#229)
This commit is contained in:
Ian Barwick
2016-09-20 17:05:20 +09:00
parent 3e51a85e07
commit 03911488aa
4 changed files with 177 additions and 84 deletions

View File

@@ -87,3 +87,34 @@ maxlen_snprintf(char *str, const char *format,...)
return retval;
}
/*
* Adapted from: src/fe_utils/string_utils.c
*
* Function not publicly available before PostgreSQL 9.6.
*/
void
appendShellString(PQExpBuffer buf, const char *str)
{
const char *p;
appendPQExpBufferChar(buf, '\'');
for (p = str; *p; p++)
{
if (*p == '\n' || *p == '\r')
{
fprintf(stderr,
_("shell command argument contains a newline or carriage return: \"%s\"\n"),
str);
exit(ERR_BAD_CONFIG);
}
if (*p == '\'')
appendPQExpBufferStr(buf, "'\"'\"'");
else
appendPQExpBufferChar(buf, *p);
}
appendPQExpBufferChar(buf, '\'');
}