Skip to content

Commit 1b81fd7

Browse files
committed
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...
1 parent a23faee commit 1b81fd7

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/backend/parser/parse_coerce.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.22 1999/08/05 02:33:53 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.23 1999/08/24 00:09:56 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -60,24 +60,24 @@ coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId,
6060
* whereas float-to-int type conversion will round to integer.
6161
*/
6262
Const *con = (Const *) node;
63+
Const *newcon = makeNode(Const);
6364
Type targetType = typeidType(targetTypeId);
64-
char *val;
6565

66-
/* We know the source constant is really of type 'text' */
67-
val = textout((text *) con->constvalue);
66+
newcon->consttype = targetTypeId;
67+
newcon->constlen = typeLen(targetType);
68+
newcon->constbyval = typeByVal(targetType);
69+
newcon->constisnull = con->constisnull;
70+
newcon->constisset = false;
6871

69-
/* now make a new const node */
70-
con = makeNode(Const);
71-
con->consttype = targetTypeId;
72-
con->constlen = typeLen(targetType);
73-
con->constvalue = stringTypeDatum(targetType, val, atttypmod);
74-
con->constisnull = false;
75-
con->constbyval = typeByVal(targetType);
76-
con->constisset = false;
77-
78-
pfree(val);
72+
if (! con->constisnull)
73+
{
74+
/* We know the source constant is really of type 'text' */
75+
char *val = textout((text *) con->constvalue);
76+
newcon->constvalue = stringTypeDatum(targetType, val, atttypmod);
77+
pfree(val);
78+
}
7979

80-
result = (Node *) con;
80+
result = (Node *) newcon;
8181
}
8282
else
8383
{
@@ -105,7 +105,7 @@ coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId,
105105
* such as coercing text 'now' to datetime? Need a way to
106106
* know whether type conversion function is cacheable...
107107
*/
108-
if (IsA(node, Const))
108+
if (IsA(node, Const) && ! ((Const *) node)->constisnull)
109109
{
110110
Const *con = (Const *) node;
111111
Oid convertFuncid;
@@ -122,9 +122,9 @@ coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId,
122122
con = makeNode(Const);
123123
con->consttype = targetTypeId;
124124
con->constlen = typeLen(targetType);
125+
con->constbyval = typeByVal(targetType);
125126
con->constvalue = val;
126127
con->constisnull = false;
127-
con->constbyval = typeByVal(targetType);
128128
con->constisset = false;
129129

130130
result = (Node *) con;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy