Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9132c01

Browse files
committed
Retire escapeConnectionParameter().
It is redundant with appendConnStrVal(), which became an extern function in commit 41f18f0. 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.
1 parent 04164de commit 9132c01

File tree

2 files changed

+4
-66
lines changed

2 files changed

+4
-66
lines changed

src/bin/pg_basebackup/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ top_builddir = ../../..
1717
include $(top_builddir)/src/Makefile.global
1818

1919
override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS)
20+
LDFLAGS += -L$(top_builddir)/src/fe_utils -lpgfeutils -lpq
2021

2122
OBJS=receivelog.o streamutil.o $(WIN32RES)
2223

src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 3 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#endif
2727

2828
#include "common/string.h"
29+
#include "fe_utils/string_utils.h"
2930
#include "getopt_long.h"
3031
#include "libpq-fe.h"
3132
#include "pqexpbuffer.h"
@@ -1392,69 +1393,6 @@ ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum)
13921393
WriteRecoveryConf();
13931394
}
13941395

1395-
/*
1396-
* Escape a parameter value so that it can be used as part of a libpq
1397-
* connection string, e.g. in:
1398-
*
1399-
* application_name=<value>
1400-
*
1401-
* The returned string is malloc'd. Return NULL on out-of-memory.
1402-
*/
1403-
static char *
1404-
escapeConnectionParameter(const char *src)
1405-
{
1406-
bool need_quotes = false;
1407-
bool need_escaping = false;
1408-
const char *p;
1409-
char *dstbuf;
1410-
char *dst;
1411-
1412-
/*
1413-
* First check if quoting is needed. Any quote (') or backslash (\)
1414-
* characters need to be escaped. Parameters are separated by whitespace,
1415-
* so any string containing whitespace characters need to be quoted. An
1416-
* empty string is represented by ''.
1417-
*/
1418-
if (strchr(src, '\'') != NULL || strchr(src, '\\') != NULL)
1419-
need_escaping = true;
1420-
1421-
for (p = src; *p; p++)
1422-
{
1423-
if (isspace((unsigned char) *p))
1424-
{
1425-
need_quotes = true;
1426-
break;
1427-
}
1428-
}
1429-
1430-
if (*src == '\0')
1431-
return pg_strdup("''");
1432-
1433-
if (!need_quotes && !need_escaping)
1434-
return pg_strdup(src); /* no quoting or escaping needed */
1435-
1436-
/*
1437-
* Allocate a buffer large enough for the worst case that all the source
1438-
* characters need to be escaped, plus quotes.
1439-
*/
1440-
dstbuf = pg_malloc(strlen(src) * 2 + 2 + 1);
1441-
1442-
dst = dstbuf;
1443-
if (need_quotes)
1444-
*(dst++) = '\'';
1445-
for (; *src; src++)
1446-
{
1447-
if (*src == '\'' || *src == '\\')
1448-
*(dst++) = '\\';
1449-
*(dst++) = *src;
1450-
}
1451-
if (need_quotes)
1452-
*(dst++) = '\'';
1453-
*dst = '\0';
1454-
1455-
return dstbuf;
1456-
}
1457-
14581396
/*
14591397
* Escape a string so that it can be used as a value in a key-value pair
14601398
* a configuration file.
@@ -1523,9 +1461,8 @@ GenerateRecoveryConf(PGconn *conn)
15231461
* Write "keyword=value" pieces, the value string is escaped and/or
15241462
* quoted if necessary.
15251463
*/
1526-
escaped = escapeConnectionParameter(option->val);
1527-
appendPQExpBuffer(&conninfo_buf, "%s=%s", option->keyword, escaped);
1528-
free(escaped);
1464+
appendPQExpBuffer(&conninfo_buf, "%s=", option->keyword);
1465+
appendConnStrVal(&conninfo_buf, option->val);
15291466
}
15301467

15311468
/*

0 commit comments

Comments
 (0)