From 7be39bb0be87a2fe6ea64c9d48130b78412968a8 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Fri, 4 Sep 2009 11:20:23 +0000 Subject: Tigthen binary receive functions so that they reject values that the text input functions don't accept either. While the backend can handle such values fine, they can cause trouble in clients and in pg_dump/restore. This is followup to the original issue on time datatype reported by Andrew McNamara a while ago. Like that one, none of these seem worth back-patching. --- src/backend/utils/adt/date.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/backend/utils/adt/date.c') diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c index 85450e12cdb..2b82c20efe7 100644 --- a/src/backend/utils/adt/date.c +++ b/src/backend/utils/adt/date.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.147 2009/07/29 22:19:18 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.148 2009/09/04 11:20:22 heikki Exp $ * *------------------------------------------------------------------------- */ @@ -203,8 +203,17 @@ Datum date_recv(PG_FUNCTION_ARGS) { StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); + DateADT result; - PG_RETURN_DATEADT((DateADT) pq_getmsgint(buf, sizeof(DateADT))); + result = (DateADT) pq_getmsgint(buf, sizeof(DateADT)); + + /* Limit to the same range that date_in() accepts. */ + if (result < 0 || result > JULIAN_MAX) + ereport(ERROR, + (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), + errmsg("date out of range"))); + + PG_RETURN_DATEADT(result); } /* -- cgit v1.2.3