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

Commit8468146

Browse files
committed
Fix the inadvertent libpq ABI breakage discovered by Martin Pitt: the
renumbering of encoding IDs done between 8.2 and 8.3 turns out to break 8.2initdb and psql if they are run with an 8.3beta1 libpq.so. For the momentwe can rearrange the order of enum pg_enc to keep the same number foreverything except PG_JOHAB, which isn't a problem since there are no directreferences to it in the 8.2 programs anyway. (This does force initdbunfortunately.)Going forward, we want to fix things so that encoding IDs can be changedwithout an ABI break, and this commit includes the changes needed to allowlibpq's encoding IDs to be treated as fully independent of the backend's.The main issue is that libpq clients should not include pg_wchar.h orotherwise assume they know the specific values of libpq's encoding IDs,since they might encounter version skew between pg_wchar.h and the libpq.sothey are using. To fix, have libpq officially export functions needed forencoding name<=>ID conversion and validity checking; it was doing thisanyway unofficially.It's still the case that we can't renumber backend encoding IDs until thenext bump in libpq's major version number, since doing so will break the8.2-era client programs. However the code is now prepared to avoid thistype of problem in future.Note that initdb is no longer a libpq client: we just pull in the twosource files we need directly. The patch also fixes a few places thatwere being sloppy about checking for an unrecognized encoding name.
1 parent537e92e commit8468146

File tree

21 files changed

+194
-81
lines changed

21 files changed

+194
-81
lines changed

‎src/backend/commands/dbcommands.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.200 2007/10/1218:55:12 tgl Exp $
16+
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.201 2007/10/13 20:18:41 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -178,12 +178,12 @@ createdb(const CreatedbStmt *stmt)
178178
elseif (IsA(dencoding->arg,String))
179179
{
180180
encoding_name=strVal(dencoding->arg);
181-
if (pg_valid_server_encoding(encoding_name)<0)
181+
encoding=pg_valid_server_encoding(encoding_name);
182+
if (encoding<0)
182183
ereport(ERROR,
183184
(errcode(ERRCODE_UNDEFINED_OBJECT),
184185
errmsg("%s is not a valid encoding name",
185186
encoding_name)));
186-
encoding=pg_char_to_encoding(encoding_name);
187187
}
188188
else
189189
elog(ERROR,"unrecognized node type: %d",

‎src/backend/utils/adt/ascii.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Portions Copyright (c) 1999-2007, PostgreSQL Global Development Group
66
*
77
* IDENTIFICATION
8-
* $PostgreSQL: pgsql/src/backend/utils/adt/ascii.c,v 1.30 2007/01/05 22:19:40 momjian Exp $
8+
* $PostgreSQL: pgsql/src/backend/utils/adt/ascii.c,v 1.31 2007/10/13 20:18:41 tgl Exp $
99
*
1010
*-----------------------------------------------------------------------
1111
*/
@@ -117,7 +117,13 @@ Datum
117117
to_ascii_encname(PG_FUNCTION_ARGS)
118118
{
119119
text*data=PG_GETARG_TEXT_P_COPY(0);
120-
intenc=pg_char_to_encoding(NameStr(*PG_GETARG_NAME(1)));
120+
char*encname=NameStr(*PG_GETARG_NAME(1));
121+
intenc=pg_char_to_encoding(encname);
122+
123+
if (enc<0)
124+
ereport(ERROR,
125+
(errcode(ERRCODE_UNDEFINED_OBJECT),
126+
errmsg("%s is not a valid encoding name",encname)));
121127

122128
PG_RETURN_TEXT_P(encode_to_ascii(data,enc));
123129
}
@@ -132,6 +138,11 @@ to_ascii_enc(PG_FUNCTION_ARGS)
132138
text*data=PG_GETARG_TEXT_P_COPY(0);
133139
intenc=PG_GETARG_INT32(1);
134140

141+
if (!PG_VALID_ENCODING(enc))
142+
ereport(ERROR,
143+
(errcode(ERRCODE_UNDEFINED_OBJECT),
144+
errmsg("%d is not a valid encoding code",enc)));
145+
135146
PG_RETURN_TEXT_P(encode_to_ascii(data,enc));
136147
}
137148

‎src/backend/utils/adt/xml.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.47 2007/09/23 21:36:42 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.48 2007/10/13 20:18:41 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -127,6 +127,24 @@ XmlOptionType xmloption;
127127
#defineNAMESPACE_SQLXML "http://standards.iso.org/iso/9075/2003/sqlxml"
128128

129129

130+
#ifdefUSE_LIBXML
131+
132+
staticint
133+
xmlChar_to_encoding(xmlChar*encoding_name)
134+
{
135+
intencoding=pg_char_to_encoding((char*)encoding_name);
136+
137+
if (encoding<0)
138+
ereport(ERROR,
139+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
140+
errmsg("invalid encoding name \"%s\"",
141+
(char*)encoding_name)));
142+
returnencoding;
143+
}
144+
145+
#endif
146+
147+
130148
Datum
131149
xml_in(PG_FUNCTION_ARGS)
132150
{
@@ -263,7 +281,9 @@ xml_recv(PG_FUNCTION_ARGS)
263281
/* Now that we know what we're dealing with, convert to server encoding */
264282
newstr= (char*)pg_do_encoding_conversion((unsignedchar*)str,
265283
nbytes,
266-
encoding ?pg_char_to_encoding((char*)encoding) :PG_UTF8,
284+
encoding ?
285+
xmlChar_to_encoding(encoding) :
286+
PG_UTF8,
267287
GetDatabaseEncoding());
268288

269289
if (newstr!=str)
@@ -1084,9 +1104,9 @@ xml_parse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace, xml
10841104

10851105
utf8string=pg_do_encoding_conversion(string,
10861106
len,
1087-
encoding
1088-
?pg_char_to_encoding((char*)encoding)
1089-
:GetDatabaseEncoding(),
1107+
encoding ?
1108+
xmlChar_to_encoding(encoding) :
1109+
GetDatabaseEncoding(),
10901110
PG_UTF8);
10911111

10921112
xml_init();

‎src/backend/utils/mb/encnames.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Encoding names and routines for work with it. All
33
* in this file is shared bedween FE and BE.
44
*
5-
* $PostgreSQL: pgsql/src/backend/utils/mb/encnames.c,v 1.34 2007/04/1618:50:49 tgl Exp $
5+
* $PostgreSQL: pgsql/src/backend/utils/mb/encnames.c,v 1.35 2007/10/13 20:18:41 tgl Exp $
66
*/
77
#ifdefFRONTEND
88
#include"postgres_fe.h"
@@ -12,10 +12,11 @@
1212
#include"utils/builtins.h"
1313
#endif
1414

15+
#include<ctype.h>
1516
#include<unistd.h>
1617

1718
#include"mb/pg_wchar.h"
18-
#include<ctype.h>
19+
1920

2021
/* ----------
2122
* All encoding names, sorted: *** A L P H A B E T I C ***
@@ -313,6 +314,9 @@ pg_enc2name pg_enc2name_tbl[] =
313314
{
314315
"EUC_TW",PG_EUC_TW
315316
},
317+
{
318+
"EUC_JIS_2004",PG_EUC_JIS_2004
319+
},
316320
{
317321
"UTF8",PG_UTF8
318322
},
@@ -397,9 +401,6 @@ pg_enc2name pg_enc2name_tbl[] =
397401
{
398402
"WIN1257",PG_WIN1257
399403
},
400-
{
401-
"EUC_JIS_2004",PG_EUC_JIS_2004
402-
},
403404
{
404405
"SJIS",PG_SJIS
405406
},
@@ -413,10 +414,10 @@ pg_enc2name pg_enc2name_tbl[] =
413414
"UHC",PG_UHC
414415
},
415416
{
416-
"JOHAB",PG_JOHAB
417+
"GB18030",PG_GB18030
417418
},
418419
{
419-
"GB18030",PG_GB18030
420+
"JOHAB",PG_JOHAB
420421
},
421422
{
422423
"SHIFT_JIS_2004",PG_SHIFT_JIS_2004
@@ -455,6 +456,12 @@ pg_valid_server_encoding(const char *name)
455456
returnenc;
456457
}
457458

459+
int
460+
pg_valid_server_encoding_id(intencoding)
461+
{
462+
returnPG_VALID_BE_ENCODING(encoding);
463+
}
464+
458465
/* ----------
459466
* Remove irrelevant chars from encoding name
460467
* ----------
@@ -533,14 +540,14 @@ pg_char_to_encname_struct(const char *name)
533540
* Returns encoding or -1 for error
534541
*/
535542
int
536-
pg_char_to_encoding(constchar*s)
543+
pg_char_to_encoding(constchar*name)
537544
{
538-
pg_encname*p=NULL;
545+
pg_encname*p;
539546

540-
if (!s)
547+
if (!name)
541548
return-1;
542549

543-
p=pg_char_to_encname_struct(s);
550+
p=pg_char_to_encname_struct(name);
544551
returnp ?p->encoding :-1;
545552
}
546553

‎src/backend/utils/mb/mbutils.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* (currently mule internal code (mic) is used)
55
* Tatsuo Ishii
66
*
7-
* $PostgreSQL: pgsql/src/backend/utils/mb/mbutils.c,v 1.66 2007/09/24 16:38:24 adunstan Exp $
7+
* $PostgreSQL: pgsql/src/backend/utils/mb/mbutils.c,v 1.67 2007/10/13 20:18:41 tgl Exp $
88
*/
99
#include"postgres.h"
1010

@@ -421,6 +421,12 @@ length_in_encoding(PG_FUNCTION_ARGS)
421421
intlen=VARSIZE(string)-VARHDRSZ;
422422
intretval;
423423

424+
if (src_encoding<0)
425+
ereport(ERROR,
426+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
427+
errmsg("invalid encoding name \"%s\"",
428+
src_encoding_name)));
429+
424430
retval=pg_verify_mbstr_len(src_encoding,VARDATA(string),len, false);
425431
PG_RETURN_INT32(retval);
426432

‎src/bin/initdb/Makefile

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
66
# Portions Copyright (c) 1994, Regents of the University of California
77
#
8-
# $PostgreSQL: pgsql/src/bin/initdb/Makefile,v 1.53 2007/09/27 19:53:43 tgl Exp $
8+
# $PostgreSQL: pgsql/src/bin/initdb/Makefile,v 1.54 2007/10/13 20:18:41 tgl Exp $
99
#
1010
#-------------------------------------------------------------------------
1111

@@ -14,14 +14,24 @@ subdir = src/bin/initdb
1414
top_builddir = ../../..
1515
include$(top_builddir)/src/Makefile.global
1616

17-
overrideCPPFLAGS := -I$(libpq_srcdir)$(CPPFLAGS)
17+
overrideCPPFLAGS := -DFRONTEND -I$(libpq_srcdir)$(CPPFLAGS)
1818

19-
OBJS=initdb.o$(WIN32RES)
19+
OBJS=initdb.oencnames.o pqsignal.o$(WIN32RES)
2020

21-
all: submake-libpq submake-libpgport initdb
21+
all: submake-libpgport initdb
2222

23-
initdb:$(OBJS)$(libpq_builddir)/libpq.a
24-
$(CC)$(CFLAGS)$(OBJS)$(libpq_pgport)$(LDFLAGS)$(LIBS) -o$@$(X)
23+
initdb:$(OBJS)
24+
$(CC)$(CFLAGS)$(OBJS)$(LDFLAGS)$(LIBS) -o$@$(X)
25+
26+
# We used to pull in all of libpq to get encnames and pqsignal, but that
27+
# exposes us to risks of version skew if we link to a shared library.
28+
# Do it the hard way, instead, so that we're statically linked.
29+
30+
encnames.c:% :$(top_srcdir)/src/backend/utils/mb/%
31+
rm -f$@&&$(LN_S)$<.
32+
33+
pqsignal.c:% :$(libpq_srcdir)/%
34+
rm -f$@&&$(LN_S)$<.
2535

2636
install: all installdirs
2737
$(INSTALL_PROGRAM) initdb$(X)'$(DESTDIR)$(bindir)/initdb$(X)'
@@ -33,7 +43,7 @@ uninstall:
3343
rm -f'$(DESTDIR)$(bindir)/initdb$(X)'
3444

3545
cleandistcleanmaintainer-clean:
36-
rm -f initdb$(X)$(OBJS)
46+
rm -f initdb$(X)$(OBJS) encnames.c pqsignal.c
3747

3848

3949
# ensure that changes in datadir propagate into object file

‎src/bin/initdb/initdb.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
* Portions Copyright (c) 1994, Regents of the University of California
4343
* Portions taken from FreeBSD.
4444
*
45-
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.144 2007/09/29 00:14:40 tgl Exp $
45+
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.145 2007/10/13 20:18:41 tgl Exp $
4646
*
4747
*-------------------------------------------------------------------------
4848
*/
@@ -2808,7 +2808,7 @@ main(int argc, char *argv[])
28082808
progname);
28092809
exit(1);
28102810
}
2811-
elseif (!PG_VALID_BE_ENCODING(ctype_enc))
2811+
elseif (!pg_valid_server_encoding_id(ctype_enc))
28122812
{
28132813
/* We recognized it, but it's not a legal server encoding */
28142814
fprintf(stderr,
@@ -2968,7 +2968,7 @@ main(int argc, char *argv[])
29682968
{
29692969
char*linkloc;
29702970

2971-
linkloc= (char*)palloc(strlen(pg_data)+8+2);
2971+
linkloc= (char*)pg_malloc(strlen(pg_data)+8+2);
29722972
sprintf(linkloc,"%s/pg_xlog",pg_data);
29732973

29742974
/* check if the specified xlog directory is empty */

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.146 2007/08/21 01:11:20 tgl Exp $
18+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.147 2007/10/13 20:18:41 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -32,7 +32,6 @@
3232
#endif
3333

3434
#include"libpq/libpq-fs.h"
35-
#include"mb/pg_wchar.h"
3635

3736

3837
constchar*progname;
@@ -1639,7 +1638,7 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
16391638
AH->vrev=K_VERS_REV;
16401639

16411640
/* initialize for backwards compatible string processing */
1642-
AH->public.encoding=PG_SQL_ASCII;
1641+
AH->public.encoding=0;/* PG_SQL_ASCII */
16431642
AH->public.std_strings= false;
16441643

16451644
/* sql error handling */

‎src/bin/pg_dump/pg_dump.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*by PostgreSQL
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.472 2007/09/03 00:39:19 tgl Exp $
15+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.473 2007/10/13 20:18:41 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -47,7 +47,6 @@ intoptreset;
4747
#include"catalog/pg_type.h"
4848
#include"commands/sequence.h"
4949
#include"libpq/libpq-fs.h"
50-
#include"mb/pg_wchar.h"
5150

5251
#include"pg_backup_archiver.h"
5352
#include"dumputils.h"

‎src/bin/pg_dump/pg_dumpall.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
88
*
9-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.92 2007/07/08 19:07:38 tgl Exp $
9+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.93 2007/10/13 20:18:41 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -27,7 +27,6 @@ intoptreset;
2727
#endif
2828

2929
#include"dumputils.h"
30-
#include"mb/pg_wchar.h"
3130

3231

3332
/* version string we expect back from pg_dump */

‎src/bin/psql/command.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2007, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.181 2007/08/21 01:11:22 tgl Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.182 2007/10/13 20:18:41 tgl Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"command.h"
@@ -45,7 +45,6 @@
4545
#include"psqlscan.h"
4646
#include"settings.h"
4747
#include"variables.h"
48-
#include"mb/pg_wchar.h"
4948

5049

5150
/* functions for use in this file */
@@ -295,7 +294,7 @@ exec_command(const char *cmd,
295294
}
296295

297296
if (pset.dirname)
298-
pfree(pset.dirname);
297+
free(pset.dirname);
299298
pset.dirname=pg_strdup(dir);
300299
canonicalize_path(pset.dirname);
301300

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp