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

Commit c846f7c

Browse files
committed
Fix several datatype input functions that were allowing unused bytes in their
results to contain uninitialized, unpredictable values. While this was okay as far as the datatypes themselves were concerned, it's a problem for the parser because occurrences of the "same" literal might not be recognized as equal by datumIsEqual (and hence not by equal()). It seems sufficient to fix this in the input functions since the only critical use of equal() is in the parser's comparisons of ORDER BY and DISTINCT expressions. Per a trouble report from Marc Cousin. Patch all the way back. Interestingly, array_in did not have the bug before 8.2, which may explain why the issue went unnoticed for so long.
1 parent 00b1827 commit c846f7c

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

contrib/ltree/ltree_io.c

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* in/out function for ltree and lquery
33
* Teodor Sigaev <teodor@stack.net>
4-
* $PostgreSQL: pgsql/contrib/ltree/ltree_io.c,v 1.14 2007/02/28 22:44:38 tgl Exp $
4+
* $PostgreSQL: pgsql/contrib/ltree/ltree_io.c,v 1.15 2008/04/11 22:52:05 tgl Exp $
55
*/
66

77
#include "ltree.h"
@@ -118,7 +118,7 @@ ltree_in(PG_FUNCTION_ARGS)
118118
errmsg("syntax error"),
119119
errdetail("Unexpected end of line.")));
120120

121-
result = (ltree *) palloc(LTREE_HDRSIZE + totallen);
121+
result = (ltree *) palloc0(LTREE_HDRSIZE + totallen);
122122
SET_VARSIZE(result, LTREE_HDRSIZE + totallen);
123123
result->numlevel = lptr - list;
124124
curlevel = LTREE_FIRST(result);
@@ -208,25 +208,22 @@ lquery_in(PG_FUNCTION_ARGS)
208208
}
209209

210210
num++;
211-
curqlevel = tmpql = (lquery_level *) palloc(ITEMSIZE * num);
212-
memset((void *) tmpql, 0, ITEMSIZE * num);
211+
curqlevel = tmpql = (lquery_level *) palloc0(ITEMSIZE * num);
213212
ptr = buf;
214213
while (*ptr)
215214
{
216215
if (state == LQPRS_WAITLEVEL)
217216
{
218217
if (ISALNUM(*ptr))
219218
{
220-
GETVAR(curqlevel) = lptr = (nodeitem *) palloc(sizeof(nodeitem) * (numOR + 1));
221-
memset((void *) GETVAR(curqlevel), 0, sizeof(nodeitem) * (numOR + 1));
219+
GETVAR(curqlevel) = lptr = (nodeitem *) palloc0(sizeof(nodeitem) * (numOR + 1));
222220
lptr->start = ptr;
223221
state = LQPRS_WAITDELIM;
224222
curqlevel->numvar = 1;
225223
}
226224
else if (*ptr == '!')
227225
{
228-
GETVAR(curqlevel) = lptr = (nodeitem *) palloc(sizeof(nodeitem) * (numOR + 1));
229-
memset((void *) GETVAR(curqlevel), 0, sizeof(nodeitem) * (numOR + 1));
226+
GETVAR(curqlevel) = lptr = (nodeitem *) palloc0(sizeof(nodeitem) * (numOR + 1));
230227
lptr->start = ptr + 1;
231228
state = LQPRS_WAITDELIM;
232229
curqlevel->numvar = 1;
@@ -448,7 +445,7 @@ lquery_in(PG_FUNCTION_ARGS)
448445
curqlevel = NEXTLEV(curqlevel);
449446
}
450447

451-
result = (lquery *) palloc(totallen);
448+
result = (lquery *) palloc0(totallen);
452449
SET_VARSIZE(result, totallen);
453450
result->numlevel = num;
454451
result->firstgood = 0;

src/backend/utils/adt/arrayfuncs.c

+2-2
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.142 2008/03/25 22:42:43 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.143 2008/04/11 22:52:05 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -319,7 +319,7 @@ array_in(PG_FUNCTION_ARGS)
319319
dataoffset = 0; /* marker for no null bitmap */
320320
nbytes += ARR_OVERHEAD_NONULLS(ndim);
321321
}
322-
retval = (ArrayType *) palloc(nbytes);
322+
retval = (ArrayType *) palloc0(nbytes);
323323
SET_VARSIZE(retval, nbytes);
324324
retval->ndim = ndim;
325325
retval->dataoffset = dataoffset;

src/backend/utils/adt/geo_ops.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/geo_ops.c,v 1.99 2008/01/01 19:45:52 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/geo_ops.c,v 1.100 2008/04/11 22:52:05 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1425,6 +1425,8 @@ path_in(PG_FUNCTION_ARGS)
14251425
errmsg("invalid input syntax for type path: \"%s\"", str)));
14261426

14271427
path->closed = (!isopen);
1428+
/* prevent instability in unused pad bytes */
1429+
path->dummy = 0;
14281430

14291431
PG_RETURN_PATH_P(path);
14301432
}

src/backend/utils/adt/tsquery.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/tsquery.c,v 1.16 2008/03/25 22:42:44 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/tsquery.c,v 1.17 2008/04/11 22:52:05 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -223,7 +223,7 @@ pushOperator(TSQueryParserState state, int8 oper)
223223

224224
Assert(oper == OP_NOT || oper == OP_AND || oper == OP_OR);
225225

226-
tmp = (QueryOperator *) palloc(sizeof(QueryOperator));
226+
tmp = (QueryOperator *) palloc0(sizeof(QueryOperator));
227227
tmp->type = QI_OPR;
228228
tmp->oper = oper;
229229
/* left is filled in later with findoprnd */
@@ -247,7 +247,7 @@ pushValue_internal(TSQueryParserState state, pg_crc32 valcrc, int distance, int
247247
errmsg("operand is too long in tsquery: \"%s\"",
248248
state->buffer)));
249249

250-
tmp = (QueryOperand *) palloc(sizeof(QueryOperand));
250+
tmp = (QueryOperand *) palloc0(sizeof(QueryOperand));
251251
tmp->type = QI_VAL;
252252
tmp->weight = weight;
253253
tmp->valcrc = (int32) valcrc;
@@ -304,7 +304,7 @@ pushStop(TSQueryParserState state)
304304
{
305305
QueryOperand *tmp;
306306

307-
tmp = (QueryOperand *) palloc(sizeof(QueryOperand));
307+
tmp = (QueryOperand *) palloc0(sizeof(QueryOperand));
308308
tmp->type = QI_VALSTOP;
309309

310310
state->polstr = lcons(tmp, state->polstr);

0 commit comments

Comments
 (0)