diff options
author | Noah Misch <noah@leadboat.com> | 2016-08-21 22:05:57 -0400 |
---|---|---|
committer | Noah Misch <noah@leadboat.com> | 2016-08-21 22:05:57 -0400 |
commit | 9132c014290d02435999c81892fa8b0b384497d8 (patch) | |
tree | b319656b5834f805b5127599822d88d272205a82 /src | |
parent | 04164deb7cb8e572302e2b43786fa24de3c40da3 (diff) | |
download | postgresql-9132c014290d02435999c81892fa8b0b384497d8.tar.gz postgresql-9132c014290d02435999c81892fa8b0b384497d8.zip |
Retire escapeConnectionParameter().
It is redundant with appendConnStrVal(), which became an extern function
in commit 41f18f021a0882eccbeca62e2ed4b66c6b96e9c9. This changes the
handling of out-of-memory and of certain inputs for which quoting is
optional, but pg_basebackup has no need for unusual treatment thereof.
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/pg_basebackup/Makefile | 1 | ||||
-rw-r--r-- | src/bin/pg_basebackup/pg_basebackup.c | 69 |
2 files changed, 4 insertions, 66 deletions
diff --git a/src/bin/pg_basebackup/Makefile b/src/bin/pg_basebackup/Makefile index 585467205b6..a23a83eb9b5 100644 --- a/src/bin/pg_basebackup/Makefile +++ b/src/bin/pg_basebackup/Makefile @@ -17,6 +17,7 @@ top_builddir = ../../.. include $(top_builddir)/src/Makefile.global override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS) +LDFLAGS += -L$(top_builddir)/src/fe_utils -lpgfeutils -lpq OBJS=receivelog.o streamutil.o $(WIN32RES) diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c index ed41db8e6e6..351a42068fd 100644 --- a/src/bin/pg_basebackup/pg_basebackup.c +++ b/src/bin/pg_basebackup/pg_basebackup.c @@ -26,6 +26,7 @@ #endif #include "common/string.h" +#include "fe_utils/string_utils.h" #include "getopt_long.h" #include "libpq-fe.h" #include "pqexpbuffer.h" @@ -1393,69 +1394,6 @@ ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum) } /* - * Escape a parameter value so that it can be used as part of a libpq - * connection string, e.g. in: - * - * application_name=<value> - * - * The returned string is malloc'd. Return NULL on out-of-memory. - */ -static char * -escapeConnectionParameter(const char *src) -{ - bool need_quotes = false; - bool need_escaping = false; - const char *p; - char *dstbuf; - char *dst; - - /* - * First check if quoting is needed. Any quote (') or backslash (\) - * characters need to be escaped. Parameters are separated by whitespace, - * so any string containing whitespace characters need to be quoted. An - * empty string is represented by ''. - */ - if (strchr(src, '\'') != NULL || strchr(src, '\\') != NULL) - need_escaping = true; - - for (p = src; *p; p++) - { - if (isspace((unsigned char) *p)) - { - need_quotes = true; - break; - } - } - - if (*src == '\0') - return pg_strdup("''"); - - if (!need_quotes && !need_escaping) - return pg_strdup(src); /* no quoting or escaping needed */ - - /* - * Allocate a buffer large enough for the worst case that all the source - * characters need to be escaped, plus quotes. - */ - dstbuf = pg_malloc(strlen(src) * 2 + 2 + 1); - - dst = dstbuf; - if (need_quotes) - *(dst++) = '\''; - for (; *src; src++) - { - if (*src == '\'' || *src == '\\') - *(dst++) = '\\'; - *(dst++) = *src; - } - if (need_quotes) - *(dst++) = '\''; - *dst = '\0'; - - return dstbuf; -} - -/* * Escape a string so that it can be used as a value in a key-value pair * a configuration file. */ @@ -1523,9 +1461,8 @@ GenerateRecoveryConf(PGconn *conn) * Write "keyword=value" pieces, the value string is escaped and/or * quoted if necessary. */ - escaped = escapeConnectionParameter(option->val); - appendPQExpBuffer(&conninfo_buf, "%s=%s", option->keyword, escaped); - free(escaped); + appendPQExpBuffer(&conninfo_buf, "%s=", option->keyword); + appendConnStrVal(&conninfo_buf, option->val); } /* |