Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd1cee54

Browse files
committed
Escape single quotes and backslashes used in locales placed in
postgresql.conf.Zhong Xubin
1 parent2b8fab8 commitd1cee54

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
staticvoidmake_template0(void);
182182
staticvoidtrapsig(intsignum);
183183
staticvoidcheck_ok(void);
184+
staticvoidescape_locale(char**locale);
184185
staticboolchklocale(constchar*locale);
185186
staticvoidsetlocales(void);
186187
staticvoidusage(constchar*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+
staticvoid
1908+
escape_locale(char**locale)
1909+
{
1910+
intlen=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
staticbool
19061927
chklocale(constchar*locale)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp