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

Commit376784c

Browse files
committed
Repair erroneous use of hashvarlena() for MACADDR, which is not a
varlena type. (I did not force initdb, but you won't see the fixunless you do one.) Also, make sure all index support operators andfunctions are careful not to leak memory for toasted inputs; I hadmissed some hash and rtree support ops on this point before.
1 parentfb47385 commit376784c

File tree

8 files changed

+115
-30
lines changed

8 files changed

+115
-30
lines changed

‎src/backend/access/hash/hashfunc.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/hash/hashfunc.c,v 1.27 2000/06/19 03:54:17 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/hash/hashfunc.c,v 1.28 2000/12/08 23:57:02 tgl Exp $
1212
*
1313
* NOTES
1414
* These functions are stored in pg_amproc.For each operator class
@@ -106,8 +106,14 @@ Datum
106106
hashvarlena(PG_FUNCTION_ARGS)
107107
{
108108
structvarlena*key=PG_GETARG_VARLENA_P(0);
109+
Datumresult;
109110

110-
returnhash_any(VARDATA(key),VARSIZE(key)-VARHDRSZ);
111+
result=hash_any(VARDATA(key),VARSIZE(key)-VARHDRSZ);
112+
113+
/* Avoid leaking memory for toasted inputs */
114+
PG_FREE_IF_COPY(key,0);
115+
116+
returnresult;
111117
}
112118

113119

‎src/backend/access/rtree/rtproc.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtproc.c,v 1.29 2000/07/30 20:43:40 tgl Exp $
18+
* $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtproc.c,v 1.30 2000/12/08 23:57:01 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -183,5 +183,8 @@ rt_poly_size(PG_FUNCTION_ARGS)
183183
*size= (float) (xdim*ydim);
184184
}
185185

186+
/* Avoid leaking memory when handed toasted input. */
187+
PG_FREE_IF_COPY(a,0);
188+
186189
PG_RETURN_VOID();
187190
}

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

Lines changed: 75 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.55 2000/12/03 20:45:35 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.56 2000/12/08 23:57:03 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -3097,8 +3097,15 @@ poly_left(PG_FUNCTION_ARGS)
30973097
{
30983098
POLYGON*polya=PG_GETARG_POLYGON_P(0);
30993099
POLYGON*polyb=PG_GETARG_POLYGON_P(1);
3100+
boolresult;
31003101

3101-
PG_RETURN_BOOL(polya->boundbox.high.x<polyb->boundbox.low.x);
3102+
result=polya->boundbox.high.x<polyb->boundbox.low.x;
3103+
3104+
/* Avoid leaking memory for toasted inputs ... needed for rtree indexes */
3105+
PG_FREE_IF_COPY(polya,0);
3106+
PG_FREE_IF_COPY(polyb,1);
3107+
3108+
PG_RETURN_BOOL(result);
31023109
}
31033110

31043111
/*-------------------------------------------------------
@@ -3111,8 +3118,15 @@ poly_overleft(PG_FUNCTION_ARGS)
31113118
{
31123119
POLYGON*polya=PG_GETARG_POLYGON_P(0);
31133120
POLYGON*polyb=PG_GETARG_POLYGON_P(1);
3121+
boolresult;
3122+
3123+
result=polya->boundbox.low.x <=polyb->boundbox.high.x;
31143124

3115-
PG_RETURN_BOOL(polya->boundbox.low.x <=polyb->boundbox.high.x);
3125+
/* Avoid leaking memory for toasted inputs ... needed for rtree indexes */
3126+
PG_FREE_IF_COPY(polya,0);
3127+
PG_FREE_IF_COPY(polyb,1);
3128+
3129+
PG_RETURN_BOOL(result);
31163130
}
31173131

31183132
/*-------------------------------------------------------
@@ -3125,8 +3139,15 @@ poly_right(PG_FUNCTION_ARGS)
31253139
{
31263140
POLYGON*polya=PG_GETARG_POLYGON_P(0);
31273141
POLYGON*polyb=PG_GETARG_POLYGON_P(1);
3142+
boolresult;
3143+
3144+
result=polya->boundbox.low.x>polyb->boundbox.high.x;
3145+
3146+
/* Avoid leaking memory for toasted inputs ... needed for rtree indexes */
3147+
PG_FREE_IF_COPY(polya,0);
3148+
PG_FREE_IF_COPY(polyb,1);
31283149

3129-
PG_RETURN_BOOL(polya->boundbox.low.x>polyb->boundbox.high.x);
3150+
PG_RETURN_BOOL(result);
31303151
}
31313152

31323153
/*-------------------------------------------------------
@@ -3139,8 +3160,15 @@ poly_overright(PG_FUNCTION_ARGS)
31393160
{
31403161
POLYGON*polya=PG_GETARG_POLYGON_P(0);
31413162
POLYGON*polyb=PG_GETARG_POLYGON_P(1);
3163+
boolresult;
31423164

3143-
PG_RETURN_BOOL(polya->boundbox.high.x>polyb->boundbox.low.x);
3165+
result=polya->boundbox.high.x>polyb->boundbox.low.x;
3166+
3167+
/* Avoid leaking memory for toasted inputs ... needed for rtree indexes */
3168+
PG_FREE_IF_COPY(polya,0);
3169+
PG_FREE_IF_COPY(polyb,1);
3170+
3171+
PG_RETURN_BOOL(result);
31443172
}
31453173

31463174
/*-------------------------------------------------------
@@ -3155,11 +3183,18 @@ poly_same(PG_FUNCTION_ARGS)
31553183
{
31563184
POLYGON*polya=PG_GETARG_POLYGON_P(0);
31573185
POLYGON*polyb=PG_GETARG_POLYGON_P(1);
3186+
boolresult;
31583187

31593188
if (polya->npts!=polyb->npts)
3160-
PG_RETURN_BOOL(false);
3189+
result= false;
3190+
else
3191+
result=plist_same(polya->npts,polya->p,polyb->p);
3192+
3193+
/* Avoid leaking memory for toasted inputs ... needed for rtree indexes */
3194+
PG_FREE_IF_COPY(polya,0);
3195+
PG_FREE_IF_COPY(polyb,1);
31613196

3162-
PG_RETURN_BOOL(plist_same(polya->npts,polya->p,polyb->p));
3197+
PG_RETURN_BOOL(result);
31633198
}
31643199

31653200
/*-----------------------------------------------------------------
@@ -3173,8 +3208,15 @@ poly_overlap(PG_FUNCTION_ARGS)
31733208
{
31743209
POLYGON*polya=PG_GETARG_POLYGON_P(0);
31753210
POLYGON*polyb=PG_GETARG_POLYGON_P(1);
3211+
boolresult;
3212+
3213+
result=box_ov(&polya->boundbox,&polyb->boundbox);
31763214

3177-
PG_RETURN_BOOL(box_ov(&polya->boundbox,&polyb->boundbox));
3215+
/* Avoid leaking memory for toasted inputs ... needed for rtree indexes */
3216+
PG_FREE_IF_COPY(polya,0);
3217+
PG_FREE_IF_COPY(polyb,1);
3218+
3219+
PG_RETURN_BOOL(result);
31783220
}
31793221

31803222

@@ -3186,6 +3228,7 @@ poly_contain(PG_FUNCTION_ARGS)
31863228
{
31873229
POLYGON*polya=PG_GETARG_POLYGON_P(0);
31883230
POLYGON*polyb=PG_GETARG_POLYGON_P(1);
3231+
boolresult;
31893232
inti;
31903233

31913234
/*
@@ -3195,35 +3238,48 @@ poly_contain(PG_FUNCTION_ARGS)
31953238
BoxPGetDatum(&polya->boundbox),
31963239
BoxPGetDatum(&polyb->boundbox))))
31973240
{
3241+
result= true;/* assume true for now */
31983242
for (i=0;i<polyb->npts;i++)
31993243
{
32003244
if (point_inside(&(polyb->p[i]),polya->npts,&(polya->p[0]))==0)
32013245
{
32023246
#ifGEODEBUG
32033247
printf("poly_contain- point (%f,%f) not in polygon\n",polyb->p[i].x,polyb->p[i].y);
32043248
#endif
3205-
PG_RETURN_BOOL(false);
3249+
result= false;
3250+
break;
32063251
}
32073252
}
3208-
for (i=0;i<polya->npts;i++)
3253+
if (result)
32093254
{
3210-
if (point_inside(&(polya->p[i]),polyb->npts,&(polyb->p[0]))==1)
3255+
for (i=0;i<polya->npts;i++)
32113256
{
3257+
if (point_inside(&(polya->p[i]),polyb->npts,&(polyb->p[0]))==1)
3258+
{
32123259
#ifGEODEBUG
3213-
printf("poly_contain- point (%f,%f) in polygon\n",polya->p[i].x,polya->p[i].y);
3260+
printf("poly_contain- point (%f,%f) in polygon\n",polya->p[i].x,polya->p[i].y);
32143261
#endif
3215-
PG_RETURN_BOOL(false);
3262+
result= false;
3263+
break;
3264+
}
32163265
}
32173266
}
3218-
PG_RETURN_BOOL(true);
32193267
}
3220-
3268+
else
3269+
{
32213270
#ifGEODEBUG
3222-
printf("poly_contain- bound box ((%f,%f),(%f,%f)) not inside ((%f,%f),(%f,%f))\n",
3223-
polyb->boundbox.low.x,polyb->boundbox.low.y,polyb->boundbox.high.x,polyb->boundbox.high.y,
3224-
polya->boundbox.low.x,polya->boundbox.low.y,polya->boundbox.high.x,polya->boundbox.high.y);
3271+
printf("poly_contain- bound box ((%f,%f),(%f,%f)) not inside ((%f,%f),(%f,%f))\n",
3272+
polyb->boundbox.low.x,polyb->boundbox.low.y,polyb->boundbox.high.x,polyb->boundbox.high.y,
3273+
polya->boundbox.low.x,polya->boundbox.low.y,polya->boundbox.high.x,polya->boundbox.high.y);
32253274
#endif
3226-
PG_RETURN_BOOL(false);
3275+
result= false;
3276+
}
3277+
3278+
/* Avoid leaking memory for toasted inputs ... needed for rtree indexes */
3279+
PG_FREE_IF_COPY(polya,0);
3280+
PG_FREE_IF_COPY(polyb,1);
3281+
3282+
PG_RETURN_BOOL(result);
32273283
}
32283284

32293285

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/*
22
*PostgreSQL type definitions for MAC addresses.
33
*
4-
*$Header: /cvsroot/pgsql/src/backend/utils/adt/mac.c,v 1.18 2000/08/23 06:04:33 thomas Exp $
4+
*$Header: /cvsroot/pgsql/src/backend/utils/adt/mac.c,v 1.19 2000/12/08 23:57:03 tgl Exp $
55
*/
66

77
#include"postgres.h"
88

9+
#include"access/hash.h"
910
#include"utils/builtins.h"
1011
#include"utils/inet.h"
1112

@@ -236,11 +237,21 @@ macaddr_ne(PG_FUNCTION_ARGS)
236237
PG_RETURN_BOOL(macaddr_cmp_internal(a1,a2)!=0);
237238
}
238239

240+
/*
241+
* Support function for hash indexes on macaddr.
242+
*/
243+
Datum
244+
hashmacaddr(PG_FUNCTION_ARGS)
245+
{
246+
macaddr*key=PG_GETARG_MACADDR_P(0);
247+
248+
returnhash_any((char*)key,sizeof(macaddr));
249+
}
250+
239251
/*
240252
*Truncation function to allow comparing mac manufacturers.
241253
*From suggestion by Alex Pilosov <alex@pilosoft.com>
242254
*/
243-
244255
Datum
245256
macaddr_trunc(PG_FUNCTION_ARGS)
246257
{

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.71 2000/11/26 11:35:23 ishii Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.72 2000/12/08 23:57:03 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -663,11 +663,17 @@ hashbpchar(PG_FUNCTION_ARGS)
663663
BpChar*key=PG_GETARG_BPCHAR_P(0);
664664
char*keydata;
665665
intkeylen;
666+
Datumresult;
666667

667668
keydata=VARDATA(key);
668669
keylen=bcTruelen(key);
669670

670-
returnhash_any(keydata,keylen);
671+
result=hash_any(keydata,keylen);
672+
673+
/* Avoid leaking memory for toasted inputs */
674+
PG_FREE_IF_COPY(key,0);
675+
676+
returnresult;
671677
}
672678

673679

‎src/include/catalog/pg_amproc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
1111
* Portions Copyright (c) 1994, Regents of the University of California
1212
*
13-
* $Id: pg_amproc.h,v 1.25 2000/08/21 04:48:51 tgl Exp $
13+
* $Id: pg_amproc.h,v 1.26 2000/12/08 23:57:02 tgl Exp $
1414
*
1515
* NOTES
1616
* the genbki.sh script reads this file and generates .bki
@@ -114,7 +114,7 @@ DATA(insert OID = 0 (405 431 456 1));
114114
DATA(insertOID=0 (4054354571));
115115
DATA(insertOID=0 (4056524561));
116116
DATA(insertOID=0 (4057549491));
117-
DATA(insertOID=0 (4058104561));
117+
DATA(insertOID=0 (4058103991));
118118
DATA(insertOID=0 (4059354561));
119119
DATA(insertOID=0 (405107610801));
120120
DATA(insertOID=0 (40510774561));

‎src/include/catalog/pg_proc.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_proc.h,v 1.177 2000/12/07 18:38:58 tgl Exp $
10+
* $Id: pg_proc.h,v 1.178 2000/12/08 23:57:02 tgl Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -830,6 +830,8 @@ DATA(insert OID = 456 ( hashvarlena PGUID 12 f t t t 1 f 23 "0" 100 0 0 100
830830
DESCR("hash any varlena type");
831831
DATA(insertOID=457 (hashoidvectorPGUID12fttt1f23"30"10000100hashoidvector- ));
832832
DESCR("hash");
833+
DATA(insertOID=399 (hashmacaddrPGUID12fttt1f23"829"10000100hashmacaddr- ));
834+
DESCR("hash");
833835
DATA(insertOID=458 (text_largerPGUID12fttt2f25"25 25"10000100text_larger- ));
834836
DESCR("larger of two");
835837
DATA(insertOID=459 (text_smallerPGUID12fttt2f25"25 25"10000100text_smaller- ));

‎src/include/utils/builtins.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: builtins.h,v 1.143 2000/11/25 20:33:54 tgl Exp $
10+
* $Id: builtins.h,v 1.144 2000/12/08 23:57:00 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -522,6 +522,7 @@ extern Datum macaddr_ne(PG_FUNCTION_ARGS);
522522
externDatummacaddr_trunc(PG_FUNCTION_ARGS);
523523
externDatummacaddr_text(PG_FUNCTION_ARGS);
524524
externDatumtext_macaddr(PG_FUNCTION_ARGS);
525+
externDatumhashmacaddr(PG_FUNCTION_ARGS);
525526

526527
/* numeric.c */
527528
externDatumnumeric_in(PG_FUNCTION_ARGS);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp