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

Commit8557a6f

Browse files
committed
Catch invalid typlens in a couple of places
Rearrange the logic in record_image_cmp() and datum_image_eq() toerror out on unexpected typlens (either not supported there orcompletely invalid due to corruption). Barring corruption, this isnot possible today but it seems more future-proof and robust to fixthis.Reported-by: Peter Geoghegan <pg@bowt.ie>
1 parentdb27b60 commit8557a6f

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,17 @@ datum_image_eq(Datum value1, Datum value2, bool typByVal, int typLen)
265265
{
266266
boolresult= true;
267267

268-
if (typLen==-1)
268+
if (typByVal)
269+
{
270+
result= (value1==value2);
271+
}
272+
elseif (typLen>0)
273+
{
274+
result= (memcmp(DatumGetPointer(value1),
275+
DatumGetPointer(value2),
276+
typLen)==0);
277+
}
278+
elseif (typLen==-1)
269279
{
270280
Sizelen1,
271281
len2;
@@ -294,16 +304,8 @@ datum_image_eq(Datum value1, Datum value2, bool typByVal, int typLen)
294304
pfree(arg2val);
295305
}
296306
}
297-
elseif (typByVal)
298-
{
299-
result= (value1==value2);
300-
}
301307
else
302-
{
303-
result= (memcmp(DatumGetPointer(value1),
304-
DatumGetPointer(value2),
305-
typLen)==0);
306-
}
308+
elog(ERROR,"unexpected typLen: %d",typLen);
307309

308310
returnresult;
309311
}

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,18 @@ record_image_cmp(FunctionCallInfo fcinfo)
14431443
}
14441444

14451445
/* Compare the pair of elements */
1446-
if (att1->attlen==-1)
1446+
if (att1->attbyval)
1447+
{
1448+
if (values1[i1]!=values2[i2])
1449+
cmpresult= (values1[i1]<values2[i2]) ?-1 :1;
1450+
}
1451+
elseif (att1->attlen>0)
1452+
{
1453+
cmpresult=memcmp(DatumGetPointer(values1[i1]),
1454+
DatumGetPointer(values2[i2]),
1455+
att1->attlen);
1456+
}
1457+
elseif (att1->attlen==-1)
14471458
{
14481459
Sizelen1,
14491460
len2;
@@ -1466,17 +1477,8 @@ record_image_cmp(FunctionCallInfo fcinfo)
14661477
if ((Pointer)arg2val!= (Pointer)values2[i2])
14671478
pfree(arg2val);
14681479
}
1469-
elseif (att1->attbyval)
1470-
{
1471-
if (values1[i1]!=values2[i2])
1472-
cmpresult= (values1[i1]<values2[i2]) ?-1 :1;
1473-
}
14741480
else
1475-
{
1476-
cmpresult=memcmp(DatumGetPointer(values1[i1]),
1477-
DatumGetPointer(values2[i2]),
1478-
att1->attlen);
1479-
}
1481+
elog(ERROR,"unexpected attlen: %d",att1->attlen);
14801482

14811483
if (cmpresult<0)
14821484
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp