Skip to content

Commit 866ffc2

Browse files
committed
array_in() and array_recv() need to be more paranoid about validating
their OID parameter. It was possible to crash the backend with select array_in('{123}',0,0); because that would bypass the needed step of initializing the workspace. These seem to be the only two places with a problem, though (record_in and record_recv don't have the issue, and the other array functions aren't depending on user-supplied input). Back-patch as far as 7.4; 7.3 does not have the bug.
1 parent e6a3012 commit 866ffc2

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/backend/utils/adt/arrayfuncs.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.121 2005/07/10 21:13:58 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.122 2005/08/15 19:40:20 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -160,7 +160,7 @@ array_in(PG_FUNCTION_ARGS)
160160
fcinfo->flinfo->fn_extra = MemoryContextAlloc(fcinfo->flinfo->fn_mcxt,
161161
sizeof(ArrayMetaState));
162162
my_extra = (ArrayMetaState *) fcinfo->flinfo->fn_extra;
163-
my_extra->element_type = InvalidOid;
163+
my_extra->element_type = ~element_type;
164164
}
165165

166166
if (my_extra->element_type != element_type)
@@ -1173,15 +1173,6 @@ array_recv(PG_FUNCTION_ARGS)
11731173
}
11741174
nitems = ArrayGetNItems(ndim, dim);
11751175

1176-
if (nitems == 0)
1177-
{
1178-
/* Return empty array */
1179-
retval = (ArrayType *) palloc0(sizeof(ArrayType));
1180-
retval->size = sizeof(ArrayType);
1181-
retval->elemtype = element_type;
1182-
PG_RETURN_ARRAYTYPE_P(retval);
1183-
}
1184-
11851176
/*
11861177
* We arrange to look up info about element type, including its
11871178
* receive conversion proc, only once per series of calls, assuming
@@ -1193,7 +1184,7 @@ array_recv(PG_FUNCTION_ARGS)
11931184
fcinfo->flinfo->fn_extra = MemoryContextAlloc(fcinfo->flinfo->fn_mcxt,
11941185
sizeof(ArrayMetaState));
11951186
my_extra = (ArrayMetaState *) fcinfo->flinfo->fn_extra;
1196-
my_extra->element_type = InvalidOid;
1187+
my_extra->element_type = ~element_type;
11971188
}
11981189

11991190
if (my_extra->element_type != element_type)
@@ -1212,6 +1203,16 @@ array_recv(PG_FUNCTION_ARGS)
12121203
fcinfo->flinfo->fn_mcxt);
12131204
my_extra->element_type = element_type;
12141205
}
1206+
1207+
if (nitems == 0)
1208+
{
1209+
/* Return empty array ... but not till we've validated element_type */
1210+
retval = (ArrayType *) palloc0(sizeof(ArrayType));
1211+
retval->size = sizeof(ArrayType);
1212+
retval->elemtype = element_type;
1213+
PG_RETURN_ARRAYTYPE_P(retval);
1214+
}
1215+
12151216
typlen = my_extra->typlen;
12161217
typbyval = my_extra->typbyval;
12171218
typalign = my_extra->typalign;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy