Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d1cee54

Browse files
committed
Escape single quotes and backslashes used in locales placed in
postgresql.conf. Zhong Xubin
1 parent 2b8fab8 commit d1cee54

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/bin/initdb/initdb.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* Portions Copyright (c) 1994, Regents of the University of California
4040
* Portions taken from FreeBSD.
4141
*
42-
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.56 2004/10/06 09:13:10 momjian Exp $
42+
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.57 2004/10/07 16:53:25 momjian Exp $
4343
*
4444
*-------------------------------------------------------------------------
4545
*/
@@ -181,6 +181,7 @@ static void vacuum_db(void);
181181
static void make_template0(void);
182182
static void trapsig(int signum);
183183
static void check_ok(void);
184+
static void escape_locale(char **locale);
184185
static bool chklocale(const char *locale);
185186
static void setlocales(void);
186187
static void usage(const char *progname);
@@ -1099,16 +1100,20 @@ setup_config(void)
10991100
snprintf(repltok, sizeof(repltok), "shared_buffers = %d", n_buffers);
11001101
conflines = replace_token(conflines, "#shared_buffers = 1000", repltok);
11011102

1103+
1104+
escape_locale(&lc_messages);
11021105
snprintf(repltok, sizeof(repltok), "lc_messages = '%s'", lc_messages);
11031106
conflines = replace_token(conflines, "#lc_messages = 'C'", repltok);
11041107

1108+
escape_locale(&lc_monetary);
11051109
snprintf(repltok, sizeof(repltok), "lc_monetary = '%s'", lc_monetary);
11061110
conflines = replace_token(conflines, "#lc_monetary = 'C'", repltok);
11071111

1112+
escape_locale(&lc_numeric);
11081113
snprintf(repltok, sizeof(repltok), "lc_numeric = '%s'", lc_numeric);
1109-
11101114
conflines = replace_token(conflines, "#lc_numeric = 'C'", repltok);
11111115

1116+
escape_locale(&lc_time);
11121117
snprintf(repltok, sizeof(repltok), "lc_time = '%s'", lc_time);
11131118
conflines = replace_token(conflines, "#lc_time = 'C'", repltok);
11141119

@@ -1896,11 +1901,27 @@ check_ok()
18961901
}
18971902
}
18981903

1904+
/*
1905+
* Escape any single quotes or backslashes in locale
1906+
*/
1907+
static void
1908+
escape_locale(char **locale)
1909+
{
1910+
int len = strlen(*locale),
1911+
i, j;
1912+
char *loc_temp = xmalloc(len * 2);
1913+
1914+
for (i = 0, j = 0; i < len; i++)
1915+
{
1916+
if ((*locale)[i] == '\'' || (*locale)[i] == '\\')
1917+
loc_temp[j++] = '\\';
1918+
loc_temp[j++] = (*locale)[i];
1919+
}
1920+
*locale = loc_temp;
1921+
}
18991922

19001923
/*
19011924
* check if given string is a valid locale specifier
1902-
* based on some code given to me by Peter Eisentraut
1903-
* (but I take responsibility for it :-)
19041925
*/
19051926
static bool
19061927
chklocale(const char *locale)

0 commit comments

Comments
 (0)