summaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/datum.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2019-11-04 08:30:00 +0100
committerPeter Eisentraut <peter@eisentraut.org>2019-11-04 09:08:15 +0100
commit8557a6f10ca6f01f4b2f2f25e197292f3f46bb5c (patch)
tree6c6ee9092623cc14fac391eafdfbb4edd5b6cf48 /src/backend/utils/adt/datum.c
parentdb27b60f07a039e236738fe90bd4215cafd35cf2 (diff)
Catch invalid typlens in a couple of places
Rearrange the logic in record_image_cmp() and datum_image_eq() to error out on unexpected typlens (either not supported there or completely invalid due to corruption). Barring corruption, this is not possible today but it seems more future-proof and robust to fix this. Reported-by: Peter Geoghegan <pg@bowt.ie>
Diffstat (limited to 'src/backend/utils/adt/datum.c')
-rw-r--r--src/backend/utils/adt/datum.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/backend/utils/adt/datum.c b/src/backend/utils/adt/datum.c
index 1568658bc9c..73703efe05a 100644
--- a/src/backend/utils/adt/datum.c
+++ b/src/backend/utils/adt/datum.c
@@ -265,7 +265,17 @@ datum_image_eq(Datum value1, Datum value2, bool typByVal, int typLen)
{
bool result = true;
- if (typLen == -1)
+ if (typByVal)
+ {
+ result = (value1 == value2);
+ }
+ else if (typLen > 0)
+ {
+ result = (memcmp(DatumGetPointer(value1),
+ DatumGetPointer(value2),
+ typLen) == 0);
+ }
+ else if (typLen == -1)
{
Size len1,
len2;
@@ -294,16 +304,8 @@ datum_image_eq(Datum value1, Datum value2, bool typByVal, int typLen)
pfree(arg2val);
}
}
- else if (typByVal)
- {
- result = (value1 == value2);
- }
else
- {
- result = (memcmp(DatumGetPointer(value1),
- DatumGetPointer(value2),
- typLen) == 0);
- }
+ elog(ERROR, "unexpected typLen: %d", typLen);
return result;
}