Commit 1b81fd77 authored by Tom Lane's avatar Tom Lane

coerce_type() failed to guard against trying to convert a NULL

constant to a different type.  Not sure that this could happen in ordinary
parser usage, but it can in some new code I'm working on...
parent a23faeee
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.22 1999/08/05 02:33:53 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.23 1999/08/24 00:09:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -60,24 +60,24 @@ coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId, ...@@ -60,24 +60,24 @@ coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId,
* whereas float-to-int type conversion will round to integer. * whereas float-to-int type conversion will round to integer.
*/ */
Const *con = (Const *) node; Const *con = (Const *) node;
Const *newcon = makeNode(Const);
Type targetType = typeidType(targetTypeId); Type targetType = typeidType(targetTypeId);
char *val;
/* We know the source constant is really of type 'text' */ newcon->consttype = targetTypeId;
val = textout((text *) con->constvalue); newcon->constlen = typeLen(targetType);
newcon->constbyval = typeByVal(targetType);
newcon->constisnull = con->constisnull;
newcon->constisset = false;
/* now make a new const node */ if (! con->constisnull)
con = makeNode(Const); {
con->consttype = targetTypeId; /* We know the source constant is really of type 'text' */
con->constlen = typeLen(targetType); char *val = textout((text *) con->constvalue);
con->constvalue = stringTypeDatum(targetType, val, atttypmod); newcon->constvalue = stringTypeDatum(targetType, val, atttypmod);
con->constisnull = false; pfree(val);
con->constbyval = typeByVal(targetType); }
con->constisset = false;
pfree(val);
result = (Node *) con; result = (Node *) newcon;
} }
else else
{ {
...@@ -105,7 +105,7 @@ coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId, ...@@ -105,7 +105,7 @@ coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId,
* such as coercing text 'now' to datetime? Need a way to * such as coercing text 'now' to datetime? Need a way to
* know whether type conversion function is cacheable... * know whether type conversion function is cacheable...
*/ */
if (IsA(node, Const)) if (IsA(node, Const) && ! ((Const *) node)->constisnull)
{ {
Const *con = (Const *) node; Const *con = (Const *) node;
Oid convertFuncid; Oid convertFuncid;
...@@ -122,9 +122,9 @@ coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId, ...@@ -122,9 +122,9 @@ coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId,
con = makeNode(Const); con = makeNode(Const);
con->consttype = targetTypeId; con->consttype = targetTypeId;
con->constlen = typeLen(targetType); con->constlen = typeLen(targetType);
con->constbyval = typeByVal(targetType);
con->constvalue = val; con->constvalue = val;
con->constisnull = false; con->constisnull = false;
con->constbyval = typeByVal(targetType);
con->constisset = false; con->constisset = false;
result = (Node *) con; result = (Node *) con;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment