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

Commit859b8dd

Browse files
committed
Add a defense to prevent core dumps if 8.2 version of rank_cd() is used with
the 8.1 SQL function definition for it. Per report from Rajesh Kumar Mallah,such a DBA error doesn't seem at all improbable, and the cost of checking forit is not very high compared to the cost of running this function. (It wouldhave been better to change the C name of the function so it wouldn't be calledby the old SQL definition, but it's too late for that now in the 8.2 branch.)
1 parent3a7f545 commit859b8dd

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

‎contrib/tsearch2/rank.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,12 +728,28 @@ calc_rank_cd(float4 *arrdata, tsvector * txt, QUERYTYPE * query, int method)
728728
Datum
729729
rank_cd(PG_FUNCTION_ARGS)
730730
{
731-
ArrayType*win= (ArrayType*)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
731+
ArrayType*win;
732732
tsvector*txt= (tsvector*)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
733733
QUERYTYPE*query= (QUERYTYPE*)PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(2));
734734
intmethod=DEF_NORM_METHOD;
735735
float4res;
736736

737+
/*
738+
* Pre-8.2, rank_cd took just a plain int as its first argument.
739+
* It was a mistake to keep the same C function name while changing the
740+
* signature, but it's too late to fix that. Instead, do a runtime test
741+
* to make sure the expected datatype has been passed. This is needed
742+
* to prevent core dumps if tsearch2 function definitions from an old
743+
* database are loaded into an 8.2 server.
744+
*/
745+
if (get_fn_expr_argtype(fcinfo->flinfo,0)!=FLOAT4ARRAYOID)
746+
ereport(ERROR,
747+
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
748+
errmsg("rank_cd() now takes real[] as its first argument, not integer")));
749+
750+
/* now safe to dereference the first arg */
751+
win= (ArrayType*)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
752+
737753
if (ARR_NDIM(win)!=1)
738754
ereport(ERROR,
739755
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),

‎src/include/catalog/pg_type.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/include/catalog/pg_type.h,v 1.173 2006/12/21 16:05:15 petere Exp $
11+
* $PostgreSQL: pgsql/src/include/catalog/pg_type.h,v 1.174 2006/12/28 01:09:01 tgl Exp $
1212
*
1313
* NOTES
1414
* the genbki.sh script reads this file and generates .bki
@@ -422,6 +422,7 @@ DATA(insert OID = 1018 ( _lseg PGNSP PGUID -1 f b t \054 0 601 array_in array
422422
DATA(insertOID=1019 (_pathPGNSPPGUID-1fbt \0540602array_inarray_outarray_recvarray_send-dxf0-10_null__null_ ));
423423
DATA(insertOID=1020 (_boxPGNSPPGUID-1fbt \0730603array_inarray_outarray_recvarray_send-dxf0-10_null__null_ ));
424424
DATA(insertOID=1021 (_float4PGNSPPGUID-1fbt \0540700array_inarray_outarray_recvarray_send-ixf0-10_null__null_ ));
425+
#defineFLOAT4ARRAYOID 1021
425426
DATA(insertOID=1022 (_float8PGNSPPGUID-1fbt \0540701array_inarray_outarray_recvarray_send-dxf0-10_null__null_ ));
426427
DATA(insertOID=1023 (_abstimePGNSPPGUID-1fbt \0540702array_inarray_outarray_recvarray_send-ixf0-10_null__null_ ));
427428
DATA(insertOID=1024 (_reltimePGNSPPGUID-1fbt \0540703array_inarray_outarray_recvarray_send-ixf0-10_null__null_ ));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp