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

Commitb1eb992

Browse files
committed
Fix a *second* buffer overrun bug in to_ascii(). Grumble.
1 parent6eb27d1 commitb1eb992

File tree

1 file changed

+35
-48
lines changed

1 file changed

+35
-48
lines changed

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

Lines changed: 35 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
/*-----------------------------------------------------------------------
1+
/*-----------------------------------------------------------------------
22
* ascii.c
3+
* The PostgreSQL routine for string to ascii conversion.
34
*
4-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ascii.c,v 1.14 2003/04/02 21:07:59 tgl Exp $
5-
*
6-
* Portions Copyright (c) 1999-2000, PostgreSQL Global Development Group
7-
*
5+
* Portions Copyright (c) 1999-2002, PostgreSQL Global Development Group
86
*
9-
* TO_ASCII()
7+
* IDENTIFICATION
8+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ascii.c,v 1.15 2003/07/14 16:41:38 tgl Exp $
109
*
11-
* The PostgreSQL routine for string to ascii conversion.
12-
*
13-
* -----------------------------------------------------------------------
10+
*-----------------------------------------------------------------------
1411
*/
15-
1612
#include"postgres.h"
13+
1714
#include"utils/builtins.h"
1815
#include"mb/pg_wchar.h"
1916
#include"utils/ascii.h"
2017

18+
staticvoidpg_to_ascii(unsignedchar*src,unsignedchar*src_end,
19+
unsignedchar*dest,intenc);
2120
statictext*encode_to_ascii(text*data,intenc);
2221

22+
2323
/* ----------
2424
* to_ascii
2525
* ----------
2626
*/
27-
char*
28-
pg_to_ascii(unsignedchar*src,unsignedchar*src_end,unsignedchar*desc,intenc)
27+
staticvoid
28+
pg_to_ascii(unsignedchar*src,unsignedchar*src_end,unsignedchar*dest,intenc)
2929
{
3030
unsignedchar*x;
3131
unsignedchar*ascii;
@@ -37,7 +37,6 @@ pg_to_ascii(unsigned char *src, unsigned char *src_end, unsigned char *desc, int
3737
#defineRANGE_128128
3838
#defineRANGE_160160
3939

40-
4140
if (enc==PG_LATIN1)
4241
{
4342
/*
@@ -64,9 +63,9 @@ pg_to_ascii(unsigned char *src, unsigned char *src_end, unsigned char *desc, int
6463
}
6564
else
6665
{
67-
elog(ERROR,"pg_to_ascii():unsupported encoding from %s",
66+
elog(ERROR,"unsupported encodingconversionfrom %s to ASCII",
6867
pg_encoding_to_char(enc));
69-
returnNULL;/* keep compiler quiet */
68+
return;/* keep compiler quiet */
7069
}
7170

7271
/*
@@ -75,27 +74,27 @@ pg_to_ascii(unsigned char *src, unsigned char *src_end, unsigned char *desc, int
7574
for (x=src;x<src_end;x++)
7675
{
7776
if (*x<128)
78-
*desc++=*x;
77+
*dest++=*x;
7978
elseif (*x<range)
80-
*desc++=' ';/* bogus 128 to 'range' */
79+
*dest++=' ';/* bogus 128 to 'range' */
8180
else
82-
*desc++=ascii[*x-range];
81+
*dest++=ascii[*x-range];
8382
}
84-
85-
returndesc;
8683
}
8784

8885
/* ----------
8986
* encode text
87+
*
88+
* The text datum is overwritten in-place, therefore this coding method
89+
* cannot support conversions that change the string length!
9090
* ----------
9191
*/
9292
statictext*
9393
encode_to_ascii(text*data,intenc)
9494
{
95-
pg_to_ascii(
96-
(unsignedchar*)VARDATA(data),/* src */
97-
VARDATA(data)+VARSIZE(data),/* src end */
98-
(unsignedchar*)VARDATA(data),/* desc */
95+
pg_to_ascii((unsignedchar*)VARDATA(data),/* src */
96+
(unsignedchar*) (data)+VARSIZE(data),/* src end */
97+
(unsignedchar*)VARDATA(data),/* dest */
9998
enc);/* encoding */
10099

101100
returndata;
@@ -108,14 +107,10 @@ encode_to_ascii(text *data, int enc)
108107
Datum
109108
to_ascii_encname(PG_FUNCTION_ARGS)
110109
{
111-
PG_RETURN_TEXT_P
112-
(
113-
encode_to_ascii
114-
(
115-
PG_GETARG_TEXT_P_COPY(0),
116-
pg_char_to_encoding(NameStr(*PG_GETARG_NAME(1)))
117-
)
118-
);
110+
text*data=PG_GETARG_TEXT_P_COPY(0);
111+
intenc=pg_char_to_encoding(NameStr(*PG_GETARG_NAME(1)));
112+
113+
PG_RETURN_TEXT_P(encode_to_ascii(data,enc));
119114
}
120115

121116
/* ----------
@@ -125,14 +120,10 @@ to_ascii_encname(PG_FUNCTION_ARGS)
125120
Datum
126121
to_ascii_enc(PG_FUNCTION_ARGS)
127122
{
128-
PG_RETURN_TEXT_P
129-
(
130-
encode_to_ascii
131-
(
132-
PG_GETARG_TEXT_P_COPY(0),
133-
PG_GETARG_INT32(1)
134-
)
135-
);
123+
text*data=PG_GETARG_TEXT_P_COPY(0);
124+
intenc=PG_GETARG_INT32(1);
125+
126+
PG_RETURN_TEXT_P(encode_to_ascii(data,enc));
136127
}
137128

138129
/* ----------
@@ -142,12 +133,8 @@ to_ascii_enc(PG_FUNCTION_ARGS)
142133
Datum
143134
to_ascii_default(PG_FUNCTION_ARGS)
144135
{
145-
PG_RETURN_TEXT_P
146-
(
147-
encode_to_ascii
148-
(
149-
PG_GETARG_TEXT_P_COPY(0),
150-
GetDatabaseEncoding()
151-
)
152-
);
136+
text*data=PG_GETARG_TEXT_P_COPY(0);
137+
intenc=GetDatabaseEncoding();
138+
139+
PG_RETURN_TEXT_P(encode_to_ascii(data,enc));
153140
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp